chatgpt-api/packages/llamaindex/src/llamaindex.ts

26 wiersze
617 B
TypeScript
Czysty Zwykły widok Historia

import {
type AIFunctionLike,
AIFunctionSet,
asZodOrJsonSchema
} from '@agentic/core'
2024-06-05 00:58:50 +00:00
import { FunctionTool } from 'llamaindex'
/**
* Converts a set of Agentic stdlib AI functions to an array of LlamaIndex-
* compatible tools.
*/
export function createLlamaIndexTools(
...aiFunctionLikeTools: AIFunctionLike[]
) {
const fns = new AIFunctionSet(aiFunctionLikeTools)
return fns.map((fn) =>
FunctionTool.from(fn.execute, {
2024-06-05 00:58:50 +00:00
name: fn.spec.name,
description: fn.spec.description,
// TODO: Investigate types here
parameters: asZodOrJsonSchema(fn.inputSchema) as any
2024-06-05 00:58:50 +00:00
})
)
}