forked from team-openpm/workgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenpm-multitask.ts
63 lines (56 loc) · 1.61 KB
/
openpm-multitask.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { z } from 'zod'
import { Api, invokable } from '../src/apis'
import { Calculator } from '../src/apis/calculator'
import { FactApi } from '../src/apis/fact'
import { OpenpmApi } from '../src/apis/openpm'
import { OpenAiAgent } from '../src/chat-agents/open-ai'
import { haltProgram } from '../src/runners/control'
import { WorkGptRunner } from '../src/runners/workgpt'
import { TextBrowser } from '../src/apis/text-browser'
export class WorkGptControl extends Api {
@invokable({
usage: 'Finishes the program. Call with the result.',
schema: z.object({
dates: z.array(
z.object({
date: z.string().describe('Date, in YYYY-MM-DD format'),
weather: z.string().describe('Weather for the date'),
})
),
}),
})
onFinish(result: any) {
haltProgram(result)
}
}
async function main() {
const agent = new OpenAiAgent({
verbose: true,
temperature: 0,
model: 'gpt-4-0613',
})
const apis = await Promise.all([
OpenpmApi.fromPackageId('serpapi-search', {
authKey: process.env.SERPAPI_API_KEY!,
}),
new TextBrowser(),
new Calculator(),
new FactApi(),
new WorkGptControl(),
])
const runner = new WorkGptRunner({
agent,
apis,
})
const result = await runner.runWithDirective(
`
Run these commands in order. Think carefully step by step.
1. What is the five day forecast for San Francisco?
2. Format this forecast into a list of dates and weather. The current date is ${new Date()
.toISOString()
.slice(0, 10)}.
`
)
console.log('Result', JSON.stringify(result, null, 2))
}
main()