/
githubmirror
/
workgpt
Обзор
Документация
Войти
/
githubmirror
/
workgpt
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/apis/api.test.ts
68 строк
2 KB
Alex MacCaw
Add new openai functions (#1)
15 июн 2023, 08:07
Не верифицирован
15 июн 2023, 08:07
01ae0c2
Код
Авторство
О чём код?
import { z } from 'zod' import { Api } from './base' import { invokable } from './helpers/decorators' describe('ApiBase', () => { class MyApi extends Api { @invokable({ usage: 'myapi doSomething', schema: z.object({ inputA: z.string().describe('inputA'), inputB: z.string().describe('inputB'), }), }) doSomething({ inputA, inputB }: { inputA: string; inputB: string }) { return inputB + inputA } } const myApi = new MyApi() it('has functions', async () => { expect(myApi.functions).toMatchInlineSnapshot(` [ { "description": "myapi doSomething", "name": "MyApi_doSomething", "parameters": { "additionalProperties": false, "properties": { "inputA": { "description": "inputA", "type": "string", }, "inputB": { "description": "inputB", "type": "string", }, }, "required": [ "inputA", "inputB", ], "type": "object", }, }, ] `) }) it('has invokables', async () => { expect(myApi.invokables.map((i) => i.name)).toMatchInlineSnapshot(` [ "MyApi_doSomething", ] `) }) it('invokes', async () => { const invokable = myApi.invokables[0] expect(invokable).toBeTruthy() expect(invokable.name).toEqual('MyApi_doSomething') expect(await invokable.callback({ inputA: 'foo', inputB: 'bar' })).toEqual( 'barfoo' ) }) })