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: add dashscope(alibabacloud) as new provider to gateway #663

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const SAMBANOVA: string = 'sambanova';
export const LEMONFOX_AI: string = 'lemonfox-ai';
export const UPSTAGE: string = 'upstage';
export const LAMBDA: string = 'lambda';
export const DASHSCOPE: string = 'dashscope';

export const VALID_PROVIDERS = [
ANTHROPIC,
Expand Down Expand Up @@ -118,6 +119,7 @@ export const VALID_PROVIDERS = [
LEMONFOX_AI,
UPSTAGE,
LAMBDA,
DASHSCOPE,
];

export const CONTENT_TYPES = {
Expand Down
19 changes: 19 additions & 0 deletions src/providers/dashscope/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ProviderAPIConfig } from '../types';

export const dashscopeAPIConfig: ProviderAPIConfig = {
getBaseURL: () => 'https://dashscope.aliyuncs.com/compatible-mode/v1',
headers({ providerOptions }) {
const { apiKey } = providerOptions;
return { Authorization: `Bearer ${apiKey}` };
},
getEndpoint({ fn }) {
switch (fn) {
case 'chatComplete':
return `/chat/completions`;
case 'embed':
return `/embeddings`;
default:
return '';
}
},
};
18 changes: 18 additions & 0 deletions src/providers/dashscope/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DASHSCOPE } from '../../globals';
import {
chatCompleteParams,
embedParams,
responseTransformers,
} from '../open-ai-base';
import { ProviderConfigs } from '../types';
import { dashscopeAPIConfig } from './api';

export const DashScopeConfig: ProviderConfigs = {
chatComplete: chatCompleteParams([], { model: 'qwen-turbo' }),
embed: embedParams([], { model: 'text-embedding-v1' }),
api: dashscopeAPIConfig,
responseTransforms: responseTransformers(DASHSCOPE, {
chatComplete: true,
embed: true,
}),
};
2 changes: 2 additions & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import LemonfoxAIConfig from './lemonfox-ai';
import { UpstageConfig } from './upstage';
import { LAMBDA } from '../globals';
import { LambdaProviderConfig } from './lambda';
import { DashScopeConfig } from './dashscope';

const Providers: { [key: string]: ProviderConfigs } = {
openai: OpenAIConfig,
Expand Down Expand Up @@ -92,6 +93,7 @@ const Providers: { [key: string]: ProviderConfigs } = {
'lemonfox-ai': LemonfoxAIConfig,
upstage: UpstageConfig,
[LAMBDA]: LambdaProviderConfig,
dashscope: DashScopeConfig,
};

export default Providers;