Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image urls for screenshot and images tools #352

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser/src/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function screenshot (
const obotServerUrl = process.env?.OBOT_SERVER_URL
const threadId = getGPTScriptEnv(headers, 'OBOT_THREAD_ID')
if (obotServerUrl !== undefined && threadId !== undefined) {
downloadUrl = `${obotServerUrl}/api/threads/${threadId}/file/${screenshotName}`
downloadUrl = `${obotServerUrl}/api/threads/${threadId}/files/${screenshotName}`
}

return {
Expand Down
6 changes: 3 additions & 3 deletions images/src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function analyzeImages(
const supportedMimeTypes = ['image/jpeg', 'image/png', 'image/webp'];
const threadId = process.env.OBOT_THREAD_ID
const obotServerUrl = process.env.OBOT_SERVER_URL
const imageGenBaseUrl = (threadId && obotServerUrl) ? `${obotServerUrl}/api/threads/${threadId}/file/` : null
const imageGenBaseUrl = (threadId && obotServerUrl) ? `${obotServerUrl}/api/threads/${threadId}/files/` : null

async function resolveImageURL (image: string): Promise<string> {
// If the image is a URL, return it as is
Expand Down Expand Up @@ -99,9 +99,9 @@ async function readImageFile(path: string): Promise<Buffer> {

// The Generate Images tool returns file paths with a special prefix
// so that they can be rendered in the Obot UI.
// e.g. /api/threads/<thread-id>/file/generated_image_<hash>.webp
// e.g. /api/threads/<thread-id>/files/generated_image_<hash>.webp
// It must be stripped before reading the file from the workspace
path = path.replace(/^\/?api\/threads\/[a-z0-9]+\/file\//, '')
path = path.replace(/^\/?api\/threads\/[a-z0-9]+\/files\//, '')

const client = new GPTScript()
return Buffer.from(await client.readFileInWorkspace(`files/${path}`))
Expand Down
2 changes: 1 addition & 1 deletion images/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type ImageQuality = 'standard' | 'hd';

const threadId = process.env.OBOT_THREAD_ID
const obotServerUrl = process.env.OBOT_SERVER_URL
const downloadBaseUrl = (threadId && obotServerUrl) ? `${obotServerUrl}/api/threads/${threadId}/file` : null
const downloadBaseUrl = (threadId && obotServerUrl) ? `${obotServerUrl}/api/threads/${threadId}/files` : null

export async function generateImages(
prompt: string = '',
Expand Down