kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: add some more unit tests for structured llm outputs
rodzic
1da1a83762
commit
80cd6a11bc
|
@ -1 +0,0 @@
|
|||
import 'dotenv/config'
|
|
@ -20,7 +20,7 @@ const redis = new Redis(process.env.REDIS_URL_TEST!)
|
|||
const keyvRedis = new KeyvRedis(redis)
|
||||
const keyv = new Keyv({ store: keyvRedis, namespace: 'agentic-test' })
|
||||
|
||||
// TODO: this is pretty hacky
|
||||
// TODO: this is a lil hacky
|
||||
const keyvHas = (keyv.has as any).bind(keyv)
|
||||
keyv.has = async (key, ...rest) => {
|
||||
if (refreshTestCache) {
|
||||
|
|
|
@ -1,11 +1,43 @@
|
|||
import test from 'ava'
|
||||
// import 'dotenv/config'
|
||||
import { expectTypeOf } from 'expect-type'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { OpenAIChatModelBuilder } from '../src/openai'
|
||||
import { createOpenAITestClient } from './_utils'
|
||||
|
||||
test('OpenAIChatModel ⇒ string output', async (t) => {
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = createOpenAITestClient()
|
||||
|
||||
const builder = new OpenAIChatModelBuilder(client, {
|
||||
modelParams: {
|
||||
temperature: 0,
|
||||
max_tokens: 30
|
||||
},
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
content:
|
||||
'You are a human, not a large language model. You are not an AI. Respond like a human would. Your name is Leeroy Jenkins.'
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: 'what is your name?'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const result = await builder.call()
|
||||
t.truthy(typeof result === 'string')
|
||||
|
||||
expectTypeOf(result).toMatchTypeOf<string>()
|
||||
|
||||
const result2 = await builder.output(z.string()).call()
|
||||
t.truthy(typeof result2 === 'string')
|
||||
|
||||
expectTypeOf(result2).toMatchTypeOf<string>()
|
||||
})
|
||||
|
||||
test('OpenAIChatModel ⇒ json output', async (t) => {
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = createOpenAITestClient()
|
||||
|
@ -30,3 +62,26 @@ test('OpenAIChatModel ⇒ json output', async (t) => {
|
|||
|
||||
expectTypeOf(result).toMatchTypeOf<{ foo: string; bar: number }>()
|
||||
})
|
||||
|
||||
test.only('OpenAIChatModel ⇒ boolean output', async (t) => {
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = createOpenAITestClient()
|
||||
|
||||
const builder = new OpenAIChatModelBuilder(client, {
|
||||
modelParams: {
|
||||
temperature: 0,
|
||||
max_tokens: 30
|
||||
},
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'are you alive?'
|
||||
}
|
||||
]
|
||||
}).output(z.boolean())
|
||||
|
||||
const result = await builder.call()
|
||||
t.truthy(typeof result === 'boolean')
|
||||
|
||||
expectTypeOf(result).toMatchTypeOf<boolean>()
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue