Skip to content

Commit 84a57ca

Browse files
committed
ai-tinkerers
1 parent f979ec2 commit 84a57ca

File tree

11 files changed

+388
-17
lines changed

11 files changed

+388
-17
lines changed

.ai-fun.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"add values provided":{"code":"function f(params) {\n const { a, b } = params;\n return a + b;\n}","npmModules":[]},"log the values provided using pino":{"code":"function f(params) {\n const pino = require('pino')();\n const { a, b } = params;\n pino.info({ a, b }, 'Logging values provided');\n return null;\n}","npmModules":["pino"]},"read the contents of a file":{"code":"function f(params) {\n const fs = require('fs');\n \n try {\n const content = fs.readFileSync(params, 'utf8');\n return content;\n } catch (error) {\n return `Error reading file: ${error.message}`;\n }\n}","npmModules":["fs"]},"use fetch to grab the website and return its contents":{"code":"function f(params) {\n return fetch(params)\n .then(response => {\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n return response.text();\n })\n .catch(error => {\n console.error('Error:', error);\n return `Error fetching content: ${error.message}`;\n });\n}","npmModules":["node-fetch"]}}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ More examples found under [examples/](examples/)
4646

4747
## Caching
4848

49-
Function caching is enabled by default for cost-saving measures. By default, the functions are stored in a file named `.ai-function-executor.json`.
49+
Function caching is enabled by default for cost-saving measures. By default, the functions are stored in a file named `.ai-fun.json`.
5050

5151
Options you can provide to `AIFunctionBuilder`:
5252

examples/file.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Servus, AI Tinkerers Vienna

examples/file2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Follow me on Twitter: @mishushakov

examples/files.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { z } from 'zod'
2+
import AIFunctionBuilder from '../src'
3+
import NodeExec from '../src/backends/node'
4+
import { anthropic } from '@ai-sdk/anthropic'
5+
6+
// Provide a LLM model
7+
const llm = anthropic.chat('claude-3-5-sonnet-20240620')
8+
9+
// Create a new AI Function Executor
10+
const backend = new NodeExec()
11+
const ai = new AIFunctionBuilder(llm, backend)
12+
13+
// Define the input parameters and output parameters of the function
14+
const parameters = z.string()
15+
const output = z.string()
16+
17+
// Generate the function
18+
const f = await ai.function('read the contents of a file', parameters, output)
19+
20+
// Call the function and log the result
21+
const result = await f('./examples/file2.txt')
22+
console.log(result)

examples/modules.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ const backend = new NodeExec({
1515
// Create a new AI Function Executor
1616
const ai = new AIFunctionBuilder(llm, backend, {
1717
debug: true,
18-
esModules: true,
1918
cache: true,
20-
cacheFile: '.ai-function-executor.json',
19+
cacheFile: '.ai-fun.json',
2120
})
2221

2322
// Define the input parameters of the function

examples/website.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const ai = new AIFunctionBuilder(llm, backend, {
1717
debug: true,
1818
esModules: false,
1919
cache: true,
20-
cacheFile: '.ai-function-executor.json',
20+
cacheFile: '.ai-fun.json',
2121
})
2222

2323
// Define the input parameters of the function
@@ -26,7 +26,7 @@ const output = z.string()
2626

2727
// Generate the function
2828
const f = await ai.function(
29-
'use axios to fetch the website and return its contents',
29+
'use fetch to grab the website and return its contents',
3030
parameters,
3131
output
3232
)

0 commit comments

Comments
 (0)