chatgpt-api/legacy/packages/ai-sdk/src/ai-sdk.ts

29 wiersze
722 B
TypeScript
Czysty Zwykły widok Historia

import {
type AIFunctionLike,
AIFunctionSet,
asAgenticSchema,
isZodSchema
} from '@agentic/core'
import { jsonSchema, tool } from 'ai'
2024-06-02 02:04:13 +00:00
2024-06-02 07:30:50 +00:00
/**
* Converts a set of Agentic stdlib AI functions to an object compatible with
* the Vercel AI SDK's `tools` parameter.
*/
export function createAISDKTools(...aiFunctionLikeTools: AIFunctionLike[]) {
const fns = new AIFunctionSet(aiFunctionLikeTools)
2024-06-02 02:04:13 +00:00
return Object.fromEntries(
fns.map((fn) => [
2024-06-02 02:04:13 +00:00
fn.spec.name,
tool({
description: fn.spec.description,
parameters: isZodSchema(fn.inputSchema)
? fn.inputSchema
: jsonSchema(asAgenticSchema(fn.inputSchema).jsonSchema),
execute: fn.execute
2024-06-02 02:04:13 +00:00
})
])
)
}