kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
old-agentic-v1^2
rodzic
203db5fa7f
commit
8b3ebb4515
33
src/llm.ts
33
src/llm.ts
|
@ -209,22 +209,31 @@ export class OpenAIChatModelBuilder<
|
|||
: z.object(this._options.output)
|
||||
|
||||
const { node } = zodToTs(outputSchema)
|
||||
const tsTypeString = printNode(node, {
|
||||
removeComments: true,
|
||||
// TODO: this doesn't seem to actually work, so we're doing it manually below
|
||||
omitTrailingSemicolon: true,
|
||||
noEmitHelpers: true
|
||||
})
|
||||
.replace(/^ /gm, ' ')
|
||||
.replace(/;$/gm, '')
|
||||
|
||||
messages.push({
|
||||
role: 'system',
|
||||
content: dedent`Output JSON only in the following format:
|
||||
if (node.kind === 152) {
|
||||
// ignore raw strings
|
||||
messages.push({
|
||||
role: 'system',
|
||||
content: dedent`Output a string`
|
||||
})
|
||||
} else {
|
||||
const tsTypeString = printNode(node, {
|
||||
removeComments: false,
|
||||
// TODO: this doesn't seem to actually work, so we're doing it manually below
|
||||
omitTrailingSemicolon: true,
|
||||
noEmitHelpers: true
|
||||
})
|
||||
.replace(/^ /gm, ' ')
|
||||
.replace(/;$/gm, '')
|
||||
|
||||
messages.push({
|
||||
role: 'system',
|
||||
content: dedent`Output JSON only in the following format:
|
||||
\`\`\`ts
|
||||
${tsTypeString}
|
||||
\`\`\``
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: filter/compress messages based on token counts
|
||||
|
|
|
@ -18,8 +18,9 @@ async function main() {
|
|||
// .call()
|
||||
// console.log(ex0)
|
||||
|
||||
const ex1 = await $.gpt4(`give me fake data conforming to this schema`)
|
||||
const ex1 = await $.gpt4(`give me fake data`)
|
||||
.output(z.object({ foo: z.string(), bar: z.number() }))
|
||||
// .output(z.string())
|
||||
// .retry({ attempts: 3 })
|
||||
.call()
|
||||
console.log(ex1)
|
||||
|
|
Ładowanie…
Reference in New Issue