const schema = defSchema("CITY_SCHEMA", { type: "array", description: "A list of cities with population and elevation information.", items: { type: "object", description: "A city with population and elevation information.", properties: { name: { type: "string", description: "The name of the city." }, population: { type: "number", description: "The population of the city." }, url: { type: "string", description: "The URL of the city's Wikipedia page." } }, required: ["name", "population", "url"] } })
$`Generate data using JSON compliant with ${schema}.`
根据 TypeChat 的 “All You Need Is Types” 方法,架构会在插入 LLM 提示前转换成 TypeScript 类型。例如,上面的
CITY_SCHEMA
类型如下:
// A list of cities with population and elevation information.
type CITY_SCHEMA = Array<{ // The name of the city. name: string, // The population of the city. population: number, // The URL of the city's Wikipedia page. url: string, }>
const schema = defSchema("CITY_SCHEMA", { type: "array", description: "A list of cities with population and elevation information.", items: { type: "object", description: "A city with population and elevation information.", properties: { name: { type: "string", description: "The name of the city." }, population: { type: "number", description: "The population of the city." }, url: { type: "string", description: "The URL of the city's Wikipedia page." } }, required: ["name", "population", "url"] } }) $`Generate data using JSON compliant with ${schema}.`
defTool( "weather", "query a weather web api", { location: "string" }, async (args) => await fetch(`https://weather.api.api/?location=${args.location}`) )
注册 JavaScript 函数作为工具并结合
prompt
成为代理。
defAgent( "git", "Query a repository using Git to accomplish tasks.", `Your are a helpful LLM agent that can use the git tools to query the current repository. Answer the question in QUERY. - The current repository is the same as github repository.`, { model, system: ["system.github_info"], tools: ["git"] } ) then use it as a tool