Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: qwen #4942

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge code
lloydzhou committed Jul 9, 2024
commit 23872086fa625efdd0c2fcfe205c3f2d8a72b714
6 changes: 6 additions & 0 deletions app/api/auth.ts
Original file line number Diff line number Diff line change
@@ -73,6 +73,12 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
case ModelProvider.Claude:
systemApiKey = serverConfig.anthropicApiKey;
break;
case ModelProvider.Doubao:
systemApiKey = serverConfig.bytedanceApiKey;
break;
case ModelProvider.Ernie:
systemApiKey = serverConfig.baiduApiKey;
break;
case ModelProvider.Qwen:
systemApiKey = serverConfig.alibabaApiKey;
break;
12 changes: 12 additions & 0 deletions app/client/api.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import { ChatMessage, ModelType, useAccessStore, useChatStore } from "../store";
import { ChatGPTApi } from "./platforms/openai";
import { GeminiProApi } from "./platforms/google";
import { ClaudeApi } from "./platforms/anthropic";
import { ErnieApi } from "./platforms/baidu";
import { DoubaoApi } from "./platforms/bytedance";
import { QwenApi } from "./platforms/alibaba";

export const ROLES = ["system", "user", "assistant"] as const;
@@ -106,6 +108,12 @@ export class ClientApi {
case ModelProvider.Claude:
this.llm = new ClaudeApi();
break;
case ModelProvider.Ernie:
this.llm = new ErnieApi();
break;
case ModelProvider.Doubao:
this.llm = new DoubaoApi();
break;
case ModelProvider.Qwen:
this.llm = new QwenApi();
break;
@@ -245,6 +253,10 @@ export function getClientApi(provider: ServiceProvider): ClientApi {
return new ClientApi(ModelProvider.GeminiPro);
case ServiceProvider.Anthropic:
return new ClientApi(ModelProvider.Claude);
case ServiceProvider.Baidu:
return new ClientApi(ModelProvider.Ernie);
case ServiceProvider.ByteDance:
return new ClientApi(ModelProvider.Doubao);
case ServiceProvider.Alibaba:
return new ClientApi(ModelProvider.Qwen);
default:
27 changes: 26 additions & 1 deletion app/config/server.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,20 @@ declare global {
// google tag manager
GTM_ID?: string;

// anthropic only
ANTHROPIC_URL?: string;
ANTHROPIC_API_KEY?: string;
ANTHROPIC_API_VERSION?: string;

// baidu only
BAIDU_URL?: string;
BAIDU_API_KEY?: string;
BAIDU_SECRET_KEY?: string;

// bytedance only
BYTEDANCE_URL?: string;
BYTEDANCE_API_KEY?: string;

// alibaba only
ALIBABA_URL?: string;
ALIBABA_API_KEY?: string;
@@ -96,8 +110,10 @@ export const getServerSideConfig = () => {
const isAzure = !!process.env.AZURE_URL;
const isGoogle = !!process.env.GOOGLE_API_KEY;
const isAnthropic = !!process.env.ANTHROPIC_API_KEY;
const isAlibaba = !!process.env.ALIBABA_API_KEY;

const isBaidu = !!process.env.BAIDU_API_KEY;
const isBytedance = !!process.env.BYTEDANCE_API_KEY;
const isAlibaba = !!process.env.ALIBABA_API_KEY;
// const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? "";
// const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());
// const randomIndex = Math.floor(Math.random() * apiKeys.length);
@@ -129,6 +145,15 @@ export const getServerSideConfig = () => {
anthropicApiVersion: process.env.ANTHROPIC_API_VERSION,
anthropicUrl: process.env.ANTHROPIC_URL,

isBaidu,
baiduUrl: process.env.BAIDU_URL,
baiduApiKey: getApiKey(process.env.BAIDU_API_KEY),
baiduSecretKey: process.env.BAIDU_SECRET_KEY,

isBytedance,
bytedanceApiKey: getApiKey(process.env.BYTEDANCE_API_KEY),
bytedanceUrl: process.env.BYTEDANCE_URL,

isAlibaba,
alibabaUrl: process.env.ALIBABA_URL,
alibabaApiKey: getApiKey(process.env.ALIBABA_API_KEY),
70 changes: 70 additions & 0 deletions app/constant.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,11 @@ export const ANTHROPIC_BASE_URL = "https://api.anthropic.com";

export const GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/";

export const BAIDU_BASE_URL = "https://aip.baidubce.com";
export const BAIDU_OATUH_URL = `${BAIDU_BASE_URL}/oauth/2.0/token`;

export const BYTEDANCE_BASE_URL = "https://ark.cn-beijing.volces.com";

export const ALIBABA_BASE_URL =
"https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation";

@@ -31,6 +36,8 @@ export enum ApiPath {
Azure = "/api/azure",
OpenAI = "/api/openai",
Anthropic = "/api/anthropic",
Baidu = "/api/baidu",
ByteDance = "/api/bytedance",
Alibaba = "/api/alibaba",
}

@@ -75,13 +82,17 @@ export enum ServiceProvider {
Azure = "Azure",
Google = "Google",
Anthropic = "Anthropic",
Baidu = "Baidu",
ByteDance = "ByteDance",
Alibaba = "Alibaba",
}

export enum ModelProvider {
GPT = "GPT",
GeminiPro = "GeminiPro",
Claude = "Claude",
Ernie = "Ernie",
Doubao = "Doubao",
Qwen = "Qwen",
}

@@ -110,6 +121,28 @@ export const Google = {
ChatPath: (modelName: string) => `v1beta/models/${modelName}:generateContent`,
};

export const Baidu = {
ExampleEndpoint: BAIDU_BASE_URL,
ChatPath: (modelName: string) => {
let endpoint = modelName;
if (modelName === "ernie-4.0-8k") {
endpoint = "completions_pro";
}
if (modelName === "ernie-4.0-8k-preview-0518") {
endpoint = "completions_adv_pro";
}
if (modelName === "ernie-3.5-8k") {
endpoint = "completions";
}
return `rpc/2.0/ai_custom/v1/wenxinworkshop/chat/${endpoint}`;
},
};

export const ByteDance = {
ExampleEndpoint: "https://ark.cn-beijing.volces.com/api/",
ChatPath: "api/v3/chat/completions",
};

export const Alibaba = {
ChatPath: "chat/completions",
};
@@ -183,6 +216,25 @@ const anthropicModels = [
"claude-3-5-sonnet-20240620",
];

const baiduModels = [
"ernie-4.0-turbo-8k",
"ernie-4.0-8k",
"ernie-4.0-8k-preview",
"ernie-4.0-8k-preview-0518",
"ernie-4.0-8k-latest",
"ernie-3.5-8k",
"ernie-3.5-8k-0205",
];

const bytedanceModels = [
"Doubao-lite-4k",
"Doubao-lite-32k",
"Doubao-lite-128k",
"Doubao-pro-4k",
"Doubao-pro-32k",
"Doubao-pro-128k",
];

const alibabaModes = [
"qwen-turbo",
"qwen-plus",
@@ -230,6 +282,24 @@ export const DEFAULT_MODELS = [
providerType: "anthropic",
},
})),
...baiduModels.map((name) => ({
name,
available: true,
provider: {
id: "baidu",
providerName: "Baidu",
providerType: "baidu",
},
})),
...bytedanceModels.map((name) => ({
name,
available: true,
provider: {
id: "bytedance",
providerName: "ByteDance",
providerType: "bytedance",
},
})),
...alibabaModes.map((name) => ({
name,
available: true,
19 changes: 19 additions & 0 deletions app/store/access.ts
Original file line number Diff line number Diff line change
@@ -47,6 +47,15 @@ const DEFAULT_ACCESS_STATE = {
anthropicApiVersion: "2023-06-01",
anthropicUrl: "",

// baidu
baiduUrl: "",
baiduApiKey: "",
baiduSecretKey: "",

// bytedance
bytedanceApiKey: "",
bytedanceUrl: "",

// alibaba
alibabaUrl: "",
alibabaApiKey: "",
@@ -87,6 +96,14 @@ export const useAccessStore = createPersistStore(
return ensure(get(), ["anthropicApiKey"]);
},

isValidBaidu() {
return ensure(get(), ["baiduApiKey", "baiduSecretKey"]);
},

isValidByteDance() {
return ensure(get(), ["bytedanceApiKey"]);
},

isValidAlibaba() {
return ensure(get(), ["alibabaApiKey"]);
},
@@ -100,6 +117,8 @@ export const useAccessStore = createPersistStore(
this.isValidAzure() ||
this.isValidGoogle() ||
this.isValidAnthropic() ||
this.isValidBaidu() ||
this.isValidByteDance() ||
this.isValidAlibaba() ||
!this.enabledAccessControl() ||
(this.enabledAccessControl() && ensure(get(), ["accessCode"]))
You are viewing a condensed version of this merge commit. You can view the full changes here.