Skip to content

Commit

Permalink
Update OpenAiService.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
steveruizok committed Feb 20, 2025
1 parent d02cc53 commit 17cf83c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions example/worker/do/openai/OpenAiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@ export class OpenAiService {

async generate(prompt: TLAiSerializedPrompt): Promise<TLAiResult> {
const events = await generateEvents(this.openai, prompt)

if (this.env.LOG_LEVEL === 'debug') {
console.log(events)
}

return {
changes: events.map((event) => getTldrawAiChangesForSimpleEvents(prompt, event)).flat(),
}
if (this.env.LOG_LEVEL === 'debug') console.log(events)
const changes = events.map((event) => getTldrawAiChangesForSimpleEvents(prompt, event)).flat()
return { changes }
}

async *stream(prompt: TLAiSerializedPrompt): AsyncGenerator<TLAiChange> {
for await (const simpleEvent of streamEvents(this.openai, prompt)) {
for (const event of getTldrawAiChangesForSimpleEvents(prompt, simpleEvent)) {
if (this.env.LOG_LEVEL === 'debug') {
console.log(event)
}
yield event
if (this.env.LOG_LEVEL === 'debug') console.log(simpleEvent)
for (const change of getTldrawAiChangesForSimpleEvents(prompt, simpleEvent)) {
yield change
}
}
}
Expand Down

0 comments on commit 17cf83c

Please sign in to comment.