feat: add百炼
This commit is contained in:
10
src/provider/chat-adapter/dashscope.ts
Normal file
10
src/provider/chat-adapter/dashscope.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
|
||||
|
||||
export type BailianOptions = Partial<BaseChatOptions>;
|
||||
export class BailianChat extends BaseChat {
|
||||
static BASE_URL = 'https://bailian.aliyuncs.com/compatible-mode/v1/';
|
||||
constructor(options: BailianOptions) {
|
||||
const baseURL = options.baseURL || BailianChat.BASE_URL;
|
||||
super({ ...(options as BaseChatOptions), baseURL: baseURL });
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { Custom } from './chat-adapter/custom.ts';
|
||||
import { Volces } from './chat-adapter/volces.ts';
|
||||
import { DeepSeek } from './chat-adapter/deepseek.ts';
|
||||
import { ModelScope } from './chat-adapter/model-scope.ts';
|
||||
import { BailianChat } from './chat-adapter/dashscope.ts';
|
||||
|
||||
import { ChatMessage } from './core/type.ts';
|
||||
|
||||
export const OllamaProvider = Ollama;
|
||||
@@ -15,6 +17,7 @@ export const CustomProvider = Custom;
|
||||
export const VolcesProvider = Volces;
|
||||
export const DeepSeekProvider = DeepSeek;
|
||||
export const ModelScopeProvider = ModelScope;
|
||||
export const BailianProvider = BailianChat;
|
||||
|
||||
export const ChatProviderMap = {
|
||||
Ollama: OllamaProvider,
|
||||
@@ -24,6 +27,7 @@ export const ChatProviderMap = {
|
||||
DeepSeek: DeepSeekProvider,
|
||||
ModelScope: ModelScopeProvider,
|
||||
BaseChat: BaseChat,
|
||||
Bailian: BailianProvider,
|
||||
};
|
||||
|
||||
type ProviderManagerConfig = {
|
||||
|
||||
@@ -14,7 +14,7 @@ export type BaseChatOptions<T = Record<string, any>> = {
|
||||
/**
|
||||
* 默认baseURL
|
||||
*/
|
||||
baseURL: string;
|
||||
baseURL?: string;
|
||||
/**
|
||||
* 默认模型
|
||||
*/
|
||||
@@ -32,7 +32,14 @@ export type BaseChatOptions<T = Record<string, any>> = {
|
||||
*/
|
||||
stream?: boolean;
|
||||
} & T;
|
||||
|
||||
export const getIsBrowser = () => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
return IS_BROWSER;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
||||
/**
|
||||
* 默认baseURL
|
||||
@@ -63,7 +70,9 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
||||
this.baseURL = options.baseURL;
|
||||
this.model = options.model;
|
||||
this.apiKey = options.apiKey;
|
||||
this.isBrowser = options.isBrowser ?? false;
|
||||
// @ts-ignore
|
||||
const DEFAULT_IS_BROWSER = getIsBrowser();
|
||||
this.isBrowser = options.isBrowser ?? DEFAULT_IS_BROWSER;
|
||||
this.openai = new OpenAI({
|
||||
apiKey: this.apiKey,
|
||||
baseURL: this.baseURL,
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import OpenAI from 'openai';
|
||||
|
||||
export type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
||||
export type ChatMessageOptions = Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams>;
|
||||
export type ChatMessageOptions = Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams> & {
|
||||
/**
|
||||
* 是否能够思考
|
||||
* 如果会话是千文,服务器的接口,默认为 true
|
||||
*/
|
||||
enable_thinking?: boolean;
|
||||
};
|
||||
export type ChatMessageComplete = OpenAI.Chat.Completions.ChatCompletion;
|
||||
export type ChatMessageStream = OpenAI.Chat.Completions.ChatCompletion;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { KnowledgeBase, KnowledgeOptions } from './knowledge-base.ts';
|
||||
|
||||
export class SiliconFlowKnowledge extends KnowledgeBase {
|
||||
static BASE_URL = 'https://api.siliconflow.com/v1';
|
||||
static BASE_URL = 'https://api.siliconflow.cn/v1';
|
||||
constructor(options: KnowledgeOptions) {
|
||||
super({ ...options, baseURL: options?.baseURL ?? SiliconFlowKnowledge.BASE_URL });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user