-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathvercel_ai.ts
More file actions
37 lines (32 loc) · 1.03 KB
/
Copy pathvercel_ai.ts
File metadata and controls
37 lines (32 loc) · 1.03 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
// Vercel AI SDK + OrcaRouter Lite
//
// npm install ai @ai-sdk/openai
//
// The @ai-sdk/openai provider lets you point at any OpenAI-compatible base URL.
// Lite serves the OpenAI Chat Completions protocol, so this works as a drop-in.
import { createOpenAI } from "@ai-sdk/openai";
import { generateText, streamText } from "ai";
export const orca = createOpenAI({
baseURL: "http://localhost:8000/v1",
apiKey: process.env.ORCA_API_KEY!, // sk-orca-...
});
// model="auto" → cheapest capable model per request
export async function ask(prompt: string) {
const { text } = await generateText({
model: orca("auto"),
prompt,
});
return text;
}
// Streaming
export async function ask_stream(prompt: string) {
const { textStream } = await streamText({
model: orca("auto"),
prompt,
});
for await (const chunk of textStream) process.stdout.write(chunk);
}
// Pin a specific model
export const haiku = orca("claude-3-5-haiku-latest");
export const sonnet = orca("claude-3-5-sonnet-latest");
export const gpt4o = orca("gpt-4o");