-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebsite.ts
35 lines (29 loc) · 838 Bytes
/
website.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { z } from 'zod'
import AIFunctionBuilder from '../src'
import NodeExec from '../src/backends/node'
import { anthropic } from '@ai-sdk/anthropic'
// Provide a LLM model
const llm = anthropic.chat('claude-3-5-sonnet-20240620')
const backend = new NodeExec({
debug: true,
packageFile: 'package.json',
installPackages: true,
})
// Create a new AI Function Executor
const ai = new AIFunctionBuilder(llm, backend, {
debug: true,
esModules: false,
cache: true,
cacheFile: '.ai-fun.json',
})
// Define the input parameters of the function
const parameters = z.string()
const output = z.string()
// Generate the function
const f = await ai.function(
'use fetch to grab the website and return its contents',
parameters,
output
)
// Call the function to log the result
console.log(await f('https://kubernetes.io'))