forked from daydreamsai/daydreams
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-chat.tsx
More file actions
71 lines (66 loc) · 1.83 KB
/
Copy pathexample-chat.tsx
File metadata and controls
71 lines (66 loc) · 1.83 KB
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
64
65
66
67
68
69
70
71
/**
* Basic example demonstrating a simple chat interface using Dreams
* with a command line interface and Groq's LLM.
*/
import { createAnthropic } from "@ai-sdk/anthropic";
import {
createDreams,
context,
LogLevel,
validateEnv,
} from "@daydreamsai/core";
import * as z from "zod/v4";
const env = validateEnv(
z.object({
ANTHROPIC_API_KEY: z.string().min(1, "ANTHROPIC_API_KEY is required"),
OPENAI_API_KEY: z.string().min(1, "OPENAI_API_KEY is required"),
})
);
const anthropic = createAnthropic({
apiKey: env.ANTHROPIC_API_KEY!,
});
const thread = context({
type: "thread",
schema: { threadId: z.string(), user: z.string() },
key: ({ threadId }) => threadId,
render({ args }) {
const date = new Date();
return `\
User: ${args.user}
Current ISO time is: ${date.toISOString()}, timestamp: ${date.getTime()}`;
},
inputs: {
message: {
schema: z.string(),
},
},
outputs: {
message: {
required: true,
schema: z.string(),
},
"screen:widget:weather": {
description: "use this to display the latest weather report",
instructions:
"always show some weather report if you havent set one yet, try to keep it updated every 5 mins, if no location the user has set use: Lisbon",
schema: z.string(),
attributes: { lastUpdated: z.number() },
},
},
});
const agent = await createDreams({
debugger: async (contextId, keys, data) => {
const [type, id] = keys;
await Bun.write(`./logs/chat/${contextId}/${id}-${type}.md`, data);
},
model: anthropic("claude-3-5-haiku-latest"),
contexts: [thread],
}).start();
const res = await agent.send({
context: thread,
args: { threadId: "test", user: "dreamer" },
input: {
type: "message",
data: "fetch the weather for lisbon, porto, and faro and make me a report in markdown format!",
},
});