chatgpt-api/src/sdks/ai-sdk.ts

24 wiersze
594 B
TypeScript
Czysty Zwykły widok Historia

2024-06-02 02:04:13 +00:00
import { tool } from 'ai'
import type { AIFunctionLike } from '../types'
import { AIFunctionSet } from '../ai-function-set'
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: fn.inputSchema,
execute: fn.impl
})
])
)
}