old-agentic-v1^2
Travis Fischer 2023-05-25 17:51:45 -07:00
rodzic 203db5fa7f
commit 8b3ebb4515
2 zmienionych plików z 23 dodań i 13 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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)