-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.ts
More file actions
40 lines (33 loc) · 1.07 KB
/
agent.ts
File metadata and controls
40 lines (33 loc) · 1.07 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
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.SOXAI_API_KEY!,
baseURL: "https://api.soxai.io/v1",
});
type Model = "gpt-4o-mini" | "claude-sonnet-4-6" | "deepseek-chat";
async function agentStep(
prompt: string,
model: Model = "gpt-4o-mini"
): Promise<string> {
const response = await client.chat.completions.create({
model,
messages: [{ role: "user", content: prompt }],
});
return response.choices[0].message.content ?? "";
}
// Agent workflow: classify → reason → summarize
const question = "Should I use REST or GraphQL for my new API?";
const intent = await agentStep(
`Classify in one word (question/task/chat): ${question}`,
"gpt-4o-mini" // cheap & fast
);
console.log(`Intent: ${intent}`);
const analysis = await agentStep(
`Analyze this thoroughly with pros and cons: ${question}`,
"claude-sonnet-4-6" // best reasoning
);
console.log(`\nAnalysis:\n${analysis}`);
const summary = await agentStep(
`Summarize in 2 sentences: ${analysis}`,
"deepseek-chat" // good value
);
console.log(`\nTL;DR: ${summary}`);