Skip to content

Commit a5ed1a8

Browse files
committed
feat: add support for 'intern' provider in chat API and integrate OpenAI-compatible model
1 parent 4c3d3fd commit a5ed1a8

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

app/api/chat/route.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createOpenAI } from "@ai-sdk/openai";
22
import { createGoogleGenerativeAI } from "@ai-sdk/google";
3+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
34
import { streamText, UIMessage, convertToModelMessages } from "ai";
45

56
// Allow streaming responses up to 30 seconds
@@ -22,12 +23,12 @@ export async function POST(req: Request) {
2223
content?: string;
2324
slug?: string;
2425
};
25-
provider?: "openai" | "gemini";
26+
provider?: "openai" | "gemini" | "intern";
2627
apiKey?: string;
2728
} = await req.json();
2829

29-
// Check if API key is provided
30-
if (!apiKey || apiKey.trim() === "") {
30+
// Check if API key is provided (not required for intern provider)
31+
if (provider !== "intern" && (!apiKey || apiKey.trim() === "")) {
3132
return Response.json(
3233
{
3334
error:
@@ -68,6 +69,13 @@ export async function POST(req: Request) {
6869
apiKey: apiKey,
6970
});
7071
model = customGoogle("models/gemini-2.0-flash");
72+
} else if (provider === "intern") {
73+
const intern = createOpenAICompatible({
74+
name: "intern",
75+
baseURL: "https://chat.intern-ai.org.cn/api/v1/",
76+
apiKey: process.env.INTERN_KEY,
77+
});
78+
model = intern("intern-s1");
7179
} else {
7280
// Default to OpenAI
7381
const customOpenAI = createOpenAI({

0 commit comments

Comments
 (0)