mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
♻️ refactor: rename the createOpenAICompatibleRuntime (#8049)
* refactor model runtime createOpenAICompatibleRuntime * upgrade version and fix tests * fix tests * fix tests
This commit is contained in:
parent
6160b9eeeb
commit
ee660d64a6
67 changed files with 225 additions and 215 deletions
86
package.json
86
package.json
|
|
@ -123,15 +123,15 @@
|
|||
"@ant-design/pro-components": "^2.8.7",
|
||||
"@anthropic-ai/sdk": "^0.51.0",
|
||||
"@auth/core": "^0.38.0",
|
||||
"@aws-sdk/client-bedrock-runtime": "^3.812.0",
|
||||
"@aws-sdk/client-s3": "^3.812.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.812.0",
|
||||
"@aws-sdk/client-bedrock-runtime": "^3.821.0",
|
||||
"@aws-sdk/client-s3": "^3.821.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.821.0",
|
||||
"@azure-rest/ai-inference": "1.0.0-beta.5",
|
||||
"@azure/core-auth": "^1.9.0",
|
||||
"@cfworker/json-schema": "^4.1.1",
|
||||
"@clerk/localizations": "^3.16.0",
|
||||
"@clerk/nextjs": "^6.19.4",
|
||||
"@clerk/themes": "^2.2.45",
|
||||
"@clerk/localizations": "^3.16.3",
|
||||
"@clerk/nextjs": "^6.20.2",
|
||||
"@clerk/themes": "^2.2.48",
|
||||
"@codesandbox/sandpack-react": "^2.20.0",
|
||||
"@cyntler/react-doc-viewer": "^1.17.0",
|
||||
"@electric-sql/pglite": "0.2.17",
|
||||
|
|
@ -140,7 +140,7 @@
|
|||
"@huggingface/inference": "^2.8.1",
|
||||
"@icons-pack/react-simple-icons": "9.6.0",
|
||||
"@khmyznikov/pwa-install": "0.3.9",
|
||||
"@langchain/community": "^0.3.43",
|
||||
"@langchain/community": "^0.3.45",
|
||||
"@lobechat/electron-client-ipc": "workspace:*",
|
||||
"@lobechat/electron-server-ipc": "workspace:*",
|
||||
"@lobechat/file-loaders": "workspace:*",
|
||||
|
|
@ -148,21 +148,21 @@
|
|||
"@lobehub/charts": "^2.0.0",
|
||||
"@lobehub/chat-plugin-sdk": "^1.32.4",
|
||||
"@lobehub/chat-plugins-gateway": "^1.9.0",
|
||||
"@lobehub/icons": "^2.0.0",
|
||||
"@lobehub/icons": "^2.2.0",
|
||||
"@lobehub/tts": "^2.0.1",
|
||||
"@lobehub/ui": "^2.1.7",
|
||||
"@modelcontextprotocol/sdk": "^1.11.4",
|
||||
"@lobehub/ui": "^2.1.15",
|
||||
"@modelcontextprotocol/sdk": "^1.12.1",
|
||||
"@neondatabase/serverless": "^1.0.0",
|
||||
"@next/third-parties": "^15.3.2",
|
||||
"@next/third-parties": "^15.3.3",
|
||||
"@react-spring/web": "^9.7.5",
|
||||
"@sentry/nextjs": "^7.120.3",
|
||||
"@serwist/next": "^9.0.14",
|
||||
"@t3-oss/env-nextjs": "^0.12.0",
|
||||
"@tanstack/react-query": "^5.76.1",
|
||||
"@trpc/client": "^11.1.2",
|
||||
"@trpc/next": "^11.1.2",
|
||||
"@trpc/react-query": "^11.1.2",
|
||||
"@trpc/server": "^11.1.2",
|
||||
"@tanstack/react-query": "^5.79.0",
|
||||
"@trpc/client": "^11.2.0",
|
||||
"@trpc/next": "^11.1.4",
|
||||
"@trpc/react-query": "^11.2.0",
|
||||
"@trpc/server": "^11.2.0",
|
||||
"@vercel/analytics": "^1.5.0",
|
||||
"@vercel/edge-config": "^1.4.0",
|
||||
"@vercel/functions": "^2.1.0",
|
||||
|
|
@ -170,7 +170,7 @@
|
|||
"@xterm/xterm": "^5.5.0",
|
||||
"ahooks": "^3.8.5",
|
||||
"ai": "^3.4.33",
|
||||
"antd": "^5.25.2",
|
||||
"antd": "^5.25.4",
|
||||
"antd-style": "^3.7.1",
|
||||
"brotli-wasm": "^3.0.1",
|
||||
"chroma-js": "^3.1.2",
|
||||
|
|
@ -184,7 +184,7 @@
|
|||
"epub2": "^3.0.2",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"file-type": "^20.5.0",
|
||||
"framer-motion": "^12.12.1",
|
||||
"framer-motion": "^12.15.0",
|
||||
"gpt-tokenizer": "^2.9.0",
|
||||
"html-to-text": "^9.0.5",
|
||||
"i18next": "^24.2.3",
|
||||
|
|
@ -193,19 +193,19 @@
|
|||
"idb-keyval": "^6.2.2",
|
||||
"immer": "^10.1.1",
|
||||
"jose": "^5.10.0",
|
||||
"js-sha256": "^0.11.0",
|
||||
"js-sha256": "^0.11.1",
|
||||
"jsonl-parse-stringify": "^1.0.3",
|
||||
"keyv": "^4.5.4",
|
||||
"langchain": "^0.3.26",
|
||||
"langfuse": "^3.37.2",
|
||||
"langfuse-core": "^3.37.2",
|
||||
"langchain": "^0.3.27",
|
||||
"langfuse": "^3.37.3",
|
||||
"langfuse-core": "^3.37.3",
|
||||
"lodash-es": "^4.17.21",
|
||||
"lucide-react": "^0.509.0",
|
||||
"mammoth": "^1.9.0",
|
||||
"mammoth": "^1.9.1",
|
||||
"mdast-util-to-markdown": "^2.1.2",
|
||||
"modern-screenshot": "^4.6.0",
|
||||
"nanoid": "^5.1.5",
|
||||
"next": "^15.3.2",
|
||||
"next": "^15.3.3",
|
||||
"next-auth": "5.0.0-beta.25",
|
||||
"next-mdx-remote": "^5.0.0",
|
||||
"nextjs-toploader": "^3.8.16",
|
||||
|
|
@ -213,8 +213,8 @@
|
|||
"nuqs": "^2.4.3",
|
||||
"officeparser": "^5.1.1",
|
||||
"oidc-provider": "^8.8.1",
|
||||
"ollama": "^0.5.15",
|
||||
"openai": "^4.100.0",
|
||||
"ollama": "^0.5.16",
|
||||
"openai": "^4.104.0",
|
||||
"openapi-fetch": "^0.9.8",
|
||||
"partial-json": "^0.1.7",
|
||||
"path-browserify-esm": "^1.0.6",
|
||||
|
|
@ -224,22 +224,22 @@
|
|||
"pino": "^9.7.0",
|
||||
"plaiceholder": "^3.0.0",
|
||||
"polished": "^4.3.1",
|
||||
"posthog-js": "^1.245.0",
|
||||
"posthog-js": "^1.249.0",
|
||||
"pwa-install-handler": "^2.6.2",
|
||||
"query-string": "^9.1.2",
|
||||
"query-string": "^9.2.0",
|
||||
"random-words": "^2.0.1",
|
||||
"react": "^19.1.0",
|
||||
"react-confetti": "^6.4.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-fast-marquee": "^1.6.5",
|
||||
"react-hotkeys-hook": "^4.6.2",
|
||||
"react-i18next": "^15.5.1",
|
||||
"react-i18next": "^15.5.2",
|
||||
"react-layout-kit": "^1.9.1",
|
||||
"react-lazy-load": "^4.0.1",
|
||||
"react-pdf": "^9.2.1",
|
||||
"react-rnd": "^10.5.2",
|
||||
"react-scan": "^0.3.4",
|
||||
"react-virtuoso": "^4.12.7",
|
||||
"react-virtuoso": "^4.12.8",
|
||||
"react-wrap-balancer": "^1.1.1",
|
||||
"remark": "^15.0.1",
|
||||
"remark-gfm": "^4.0.1",
|
||||
|
|
@ -252,7 +252,7 @@
|
|||
"shiki": "^3.4.2",
|
||||
"stripe": "^16.12.0",
|
||||
"superjson": "^2.2.2",
|
||||
"svix": "^1.65.0",
|
||||
"svix": "^1.66.0",
|
||||
"swr": "^2.3.3",
|
||||
"systemjs": "^6.15.1",
|
||||
"tokenx": "^0.4.1",
|
||||
|
|
@ -268,7 +268,7 @@
|
|||
"y-webrtc": "^10.3.0",
|
||||
"yaml": "^2.8.0",
|
||||
"yjs": "^13.6.27",
|
||||
"zod": "^3.25.7",
|
||||
"zod": "^3.25.48",
|
||||
"zustand": "5.0.4",
|
||||
"zustand-utils": "^2.1.0"
|
||||
},
|
||||
|
|
@ -276,11 +276,11 @@
|
|||
"@commitlint/cli": "^19.8.1",
|
||||
"@edge-runtime/vm": "^5.0.0",
|
||||
"@huggingface/tasks": "^0.15.9",
|
||||
"@lobehub/i18n-cli": "^1.20.3",
|
||||
"@lobehub/lint": "^1.26.1",
|
||||
"@lobehub/seo-cli": "^1.4.3",
|
||||
"@next/bundle-analyzer": "^15.3.2",
|
||||
"@next/eslint-plugin-next": "^15.3.2",
|
||||
"@lobehub/i18n-cli": "^1.22.0",
|
||||
"@lobehub/lint": "^1.26.2",
|
||||
"@lobehub/seo-cli": "^1.6.0",
|
||||
"@next/bundle-analyzer": "^15.3.3",
|
||||
"@next/eslint-plugin-next": "^15.3.3",
|
||||
"@peculiar/webcrypto": "^1.5.0",
|
||||
"@semantic-release/exec": "^6.0.3",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
|
|
@ -293,13 +293,13 @@
|
|||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/ip": "^1.1.3",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/lodash": "^4.17.16",
|
||||
"@types/lodash": "^4.17.17",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^22.15.19",
|
||||
"@types/node": "^22.15.29",
|
||||
"@types/numeral": "^2.0.5",
|
||||
"@types/oidc-provider": "^8.8.1",
|
||||
"@types/pg": "^8.15.2",
|
||||
"@types/react": "^19.1.4",
|
||||
"@types/pg": "^8.15.4",
|
||||
"@types/react": "^19.1.6",
|
||||
"@types/react-dom": "^19.1.5",
|
||||
"@types/rtl-detect": "^1.0.3",
|
||||
"@types/semver": "^7.7.0",
|
||||
|
|
@ -325,7 +325,7 @@
|
|||
"fs-extra": "^11.3.0",
|
||||
"glob": "^11.0.2",
|
||||
"gray-matter": "^4.0.3",
|
||||
"happy-dom": "^17.4.7",
|
||||
"happy-dom": "^17.5.6",
|
||||
"husky": "^9.1.7",
|
||||
"just-diff": "^6.0.2",
|
||||
"lint-staged": "^15.5.2",
|
||||
|
|
@ -351,7 +351,7 @@
|
|||
"unified": "^11.0.5",
|
||||
"unist-util-visit": "^5.0.0",
|
||||
"vite": "^5.4.19",
|
||||
"vitest": "^3.1.4",
|
||||
"vitest": "^3.2.0",
|
||||
"vitest-canvas-mock": "^0.3.3"
|
||||
},
|
||||
"packageManager": "pnpm@10.10.0",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ describe('useOnPluginReadyForInteraction', () => {
|
|||
|
||||
afterEach(() => {
|
||||
mockOnReady.mockReset();
|
||||
window.removeEventListener('message', expect.any(Function));
|
||||
window.removeEventListener('message', () => {});
|
||||
});
|
||||
|
||||
it('sets readyForRender to true when a PluginChannel.pluginReadyForRender message is received', async () => {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ describe('useOnPluginSettingsUpdate', () => {
|
|||
|
||||
afterEach(() => {
|
||||
mockCallback.mockReset();
|
||||
window.removeEventListener('message', expect.any(Function));
|
||||
window.removeEventListener('message', () => {});
|
||||
});
|
||||
|
||||
it('calls the callback when a PluginChannel updatePluginSettings message is received', () => {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe('useOnPluginStateUpdate', () => {
|
|||
// Reset the mock callback after each test
|
||||
mockCallback.mockReset();
|
||||
// Ensure no event listeners are left hanging after each test
|
||||
window.removeEventListener('message', expect.any(Function));
|
||||
window.removeEventListener('message', () => {});
|
||||
});
|
||||
|
||||
it('calls the callback when a PluginChannel update message is received', () => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import OpenAI from 'openai';
|
|||
import { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
Embeddings,
|
||||
EmbeddingsOptions,
|
||||
|
|
@ -18,7 +18,7 @@ import {
|
|||
/* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
|
||||
export interface LobeRuntimeAI {
|
||||
baseURL?: string;
|
||||
chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions): Promise<Response>;
|
||||
chat(payload: ChatStreamPayload, options?: ChatMethodOptions): Promise<Response>;
|
||||
|
||||
embeddings?(payload: EmbeddingsPayload, options?: EmbeddingsOptions): Promise<Embeddings[]>;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ export abstract class LobeOpenAICompatibleRuntime {
|
|||
abstract baseURL: string;
|
||||
abstract client: OpenAI;
|
||||
|
||||
abstract chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions): Promise<Response>;
|
||||
abstract chat(payload: ChatStreamPayload, options?: ChatMethodOptions): Promise<Response>;
|
||||
|
||||
abstract models(): Promise<ChatModelCard[]>;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { LobeCloudflareParams } from './cloudflare';
|
|||
import { LobeOpenAI } from './openai';
|
||||
import { providerRuntimeMap } from './runtimeMap';
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
EmbeddingsOptions,
|
||||
EmbeddingsPayload,
|
||||
|
|
@ -60,7 +60,7 @@ class ModelRuntime {
|
|||
* }));
|
||||
* ```
|
||||
*/
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
return this._runtime.chat(payload, options);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import { LobeRuntimeAI } from '../BaseAI';
|
|||
import { LobeOpenAI } from '../openai';
|
||||
import { providerRuntimeMap } from '../runtimeMap';
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
type ChatCompletionErrorPayload,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
EmbeddingsOptions,
|
||||
EmbeddingsPayload,
|
||||
|
|
@ -70,7 +70,7 @@ class UniformRuntime {
|
|||
return runtimeItem.runtime;
|
||||
}
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
try {
|
||||
const runtime = this.getRuntimeByModel(payload.model);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobeAi21AI = LobeOpenAICompatibleFactory({
|
||||
export const LobeAi21AI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.ai21.com/studio/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface Ai360ModelCard {
|
||||
id: string;
|
||||
|
|
@ -9,7 +9,7 @@ export interface Ai360ModelCard {
|
|||
total_tokens: number;
|
||||
}
|
||||
|
||||
export const LobeAi360AI = LobeOpenAICompatibleFactory({
|
||||
export const LobeAi360AI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.360.cn/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
type ChatCompletionErrorPayload,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
ModelProvider,
|
||||
} from '../types';
|
||||
|
|
@ -52,15 +52,15 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|||
this.client = new Anthropic({
|
||||
apiKey,
|
||||
baseURL,
|
||||
...(betaHeaders ? { defaultHeaders: { "anthropic-beta": betaHeaders } } : {}),
|
||||
...res
|
||||
...(betaHeaders ? { defaultHeaders: { 'anthropic-beta': betaHeaders } } : {}),
|
||||
...res,
|
||||
});
|
||||
this.baseURL = this.client.baseURL;
|
||||
this.apiKey = apiKey;
|
||||
this.id = id || ModelProvider.Anthropic;
|
||||
}
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
try {
|
||||
const anthropicPayload = await this.buildAnthropicPayload(payload);
|
||||
const inputStartAt = Date.now();
|
||||
|
|
@ -112,7 +112,7 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|||
} = payload;
|
||||
|
||||
const { default: anthropicModels } = await import('@/config/aiModels/anthropic');
|
||||
const modelConfig = anthropicModels.find(m => m.id === model);
|
||||
const modelConfig = anthropicModels.find((m) => m.id === model);
|
||||
const defaultMaxOutput = modelConfig?.maxOutput;
|
||||
|
||||
// 配置优先级:用户设置 > 模型配置 > 硬编码默认值
|
||||
|
|
@ -137,7 +137,9 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|||
|
||||
const postMessages = await buildAnthropicMessages(user_messages, { enabledContextCaching });
|
||||
|
||||
let postTools: anthropicTools[] | undefined = buildAnthropicTools(tools, { enabledContextCaching });
|
||||
let postTools: anthropicTools[] | undefined = buildAnthropicTools(tools, {
|
||||
enabledContextCaching,
|
||||
});
|
||||
|
||||
if (enabledSearch) {
|
||||
// Limit the number of searches per request
|
||||
|
|
@ -146,9 +148,11 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|||
const webSearchTool: Anthropic.WebSearchTool20250305 = {
|
||||
name: 'web_search',
|
||||
type: 'web_search_20250305',
|
||||
...(maxUses && Number.isInteger(Number(maxUses)) && Number(maxUses) > 0 && {
|
||||
max_uses: Number(maxUses)
|
||||
}),
|
||||
...(maxUses &&
|
||||
Number.isInteger(Number(maxUses)) &&
|
||||
Number(maxUses) > 0 && {
|
||||
max_uses: Number(maxUses),
|
||||
}),
|
||||
};
|
||||
|
||||
// 如果已有工具,则添加到现有工具列表中;否则创建新的工具列表
|
||||
|
|
@ -171,8 +175,8 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|||
system: systemPrompts,
|
||||
thinking: {
|
||||
...thinking,
|
||||
budget_tokens: thinking?.budget_tokens
|
||||
? Math.min(thinking.budget_tokens, maxTokens - 1) // `max_tokens` must be greater than `thinking.budget_tokens`.
|
||||
budget_tokens: thinking?.budget_tokens
|
||||
? Math.min(thinking.budget_tokens, maxTokens - 1) // `max_tokens` must be greater than `thinking.budget_tokens`.
|
||||
: 1024,
|
||||
},
|
||||
tools: postTools,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { systemToUserModels } from '@/const/models';
|
|||
|
||||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ChatCompetitionOptions, ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { ChatMethodOptions, ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { AgentRuntimeError } from '../utils/createError';
|
||||
import { debugStream } from '../utils/debugStream';
|
||||
import { transformResponseToStream } from '../utils/openaiCompatibleFactory';
|
||||
|
|
@ -32,7 +32,7 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
|
|||
|
||||
baseURL: string;
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
const { messages, model, ...params } = payload;
|
||||
// o1 series models on Azure OpenAI does not support streaming currently
|
||||
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { systemToUserModels } from '@/const/models';
|
|||
|
||||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ChatCompetitionOptions, ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { ChatMethodOptions, ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { AgentRuntimeError } from '../utils/createError';
|
||||
import { debugStream } from '../utils/debugStream';
|
||||
import { transformResponseToStream } from '../utils/openaiCompatibleFactory';
|
||||
|
|
@ -33,7 +33,7 @@ export class LobeAzureAI implements LobeRuntimeAI {
|
|||
|
||||
baseURL: string;
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
const { messages, model, temperature, top_p, ...params } = payload;
|
||||
// o1 series models on Azure OpenAI does not support streaming currently
|
||||
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true);
|
||||
|
|
@ -56,9 +56,9 @@ export class LobeAzureAI implements LobeRuntimeAI {
|
|||
model,
|
||||
...params,
|
||||
stream: enableStreaming,
|
||||
temperature: (model.includes('o3') || model.includes('o4')) ? undefined : temperature,
|
||||
temperature: model.includes('o3') || model.includes('o4') ? undefined : temperature,
|
||||
tool_choice: params.tools ? 'auto' : undefined,
|
||||
top_p: (model.includes('o3') || model.includes('o4')) ? undefined : top_p,
|
||||
top_p: model.includes('o3') || model.includes('o4') ? undefined : top_p,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface BaichuanModelCard {
|
||||
function_call: boolean;
|
||||
|
|
@ -11,7 +11,7 @@ export interface BaichuanModelCard {
|
|||
model_show_name: string;
|
||||
}
|
||||
|
||||
export const LobeBaichuanAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeBaichuanAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.baichuan-ai.com/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload: ChatStreamPayload) => {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { experimental_buildLlama2Prompt } from 'ai/prompts';
|
|||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
Embeddings,
|
||||
EmbeddingsOptions,
|
||||
|
|
@ -51,7 +51,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
|
|||
});
|
||||
}
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
if (payload.model.startsWith('meta')) return this.invokeLlamaModel(payload, options);
|
||||
|
||||
return this.invokeClaudeModel(payload, options);
|
||||
|
|
@ -114,7 +114,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
|
|||
|
||||
private invokeClaudeModel = async (
|
||||
payload: ChatStreamPayload,
|
||||
options?: ChatCompetitionOptions,
|
||||
options?: ChatMethodOptions,
|
||||
): Promise<Response> => {
|
||||
const { max_tokens, messages, model, temperature, top_p, tools } = payload;
|
||||
const system_message = messages.find((m) => m.role === 'system');
|
||||
|
|
@ -169,7 +169,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
|
|||
|
||||
private invokeLlamaModel = async (
|
||||
payload: ChatStreamPayload,
|
||||
options?: ChatCompetitionOptions,
|
||||
options?: ChatMethodOptions,
|
||||
): Promise<Response> => {
|
||||
const { max_tokens, messages, model } = payload;
|
||||
const command = new InvokeModelWithResponseStreamCommand({
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { ChatModelCard } from '@/types/llm';
|
|||
|
||||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ChatCompetitionOptions, ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { ChatMethodOptions, ChatStreamPayload, ModelProvider } from '../types';
|
||||
import {
|
||||
CloudflareStreamTransformer,
|
||||
DEFAULT_BASE_URL_PREFIX,
|
||||
|
|
@ -54,7 +54,7 @@ export class LobeCloudflareAI implements LobeRuntimeAI {
|
|||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions): Promise<Response> {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions): Promise<Response> {
|
||||
try {
|
||||
const { model, tools, ...restPayload } = payload;
|
||||
const functions = tools?.map((tool) => tool.function);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface CohereModelCard {
|
||||
context_length: number;
|
||||
|
|
@ -10,7 +10,7 @@ export interface CohereModelCard {
|
|||
supports_vision: boolean;
|
||||
}
|
||||
|
||||
export const LobeCohereAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeCohereAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.cohere.ai/compatibility/v1',
|
||||
chatCompletion: {
|
||||
// https://docs.cohere.com/v2/docs/compatibility-api#unsupported-parameters
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface DeepSeekModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeDeepSeekAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeDeepSeekAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.deepseek.com/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_DEEPSEEK_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface FireworksAIModelCard {
|
||||
context_length: number;
|
||||
|
|
@ -10,7 +10,7 @@ export interface FireworksAIModelCard {
|
|||
supports_tools: boolean;
|
||||
}
|
||||
|
||||
export const LobeFireworksAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeFireworksAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.fireworks.ai/inference/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_FIREWORKSAI_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface GiteeAIModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeGiteeAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeGiteeAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://ai.gitee.com/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_GITEE_AI_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { pruneReasoningPayload } from '../utils/openaiHelpers';
|
||||
|
||||
export interface GithubModelCard {
|
||||
|
|
@ -16,7 +16,7 @@ export interface GithubModelCard {
|
|||
|
||||
/* eslint-enable typescript-sort-keys/interface */
|
||||
|
||||
export const LobeGithubAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeGithubAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://models.github.ai/inference',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ import { safeParseJSON } from '@/utils/safeParseJSON';
|
|||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../error';
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
ChatCompletionTool,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
OpenAIChatMessage,
|
||||
UserMessageContentPart,
|
||||
|
|
@ -111,15 +111,15 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|||
this.provider = id || (isVertexAi ? 'vertexai' : 'google');
|
||||
}
|
||||
|
||||
async chat(rawPayload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(rawPayload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
try {
|
||||
const payload = this.buildPayload(rawPayload);
|
||||
const { model, thinking } = payload;
|
||||
|
||||
const thinkingConfig: GoogleAIThinkingConfig = {
|
||||
includeThoughts:
|
||||
(thinking?.type === 'enabled') ||
|
||||
(!thinking && model && (model.includes('-2.5-') || model.includes('thinking')))
|
||||
thinking?.type === 'enabled' ||
|
||||
(!thinking && model && (model.includes('-2.5-') || model.includes('thinking')))
|
||||
? true
|
||||
: undefined,
|
||||
thinkingBudget:
|
||||
|
|
@ -142,7 +142,9 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|||
response_modalities: modelsWithModalities.has(model) ? ['Text', 'Image'] : undefined,
|
||||
temperature: payload.temperature,
|
||||
topP: payload.top_p,
|
||||
...(modelsDisableInstuction.has(model) || model.toLowerCase().includes('learnlm') ? {} : { thinkingConfig }),
|
||||
...(modelsDisableInstuction.has(model) || model.toLowerCase().includes('learnlm')
|
||||
? {}
|
||||
: { thinkingConfig }),
|
||||
},
|
||||
model,
|
||||
// avoid wide sensitive words
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface GroqModelCard {
|
||||
context_window: number;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeGroq = LobeOpenAICompatibleFactory({
|
||||
export const LobeGroq = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.groq.com/openai/v1',
|
||||
chatCompletion: {
|
||||
handleError: (error) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { uniqueId } from 'lodash-es';
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface HigressModelCard {
|
||||
context_length: number;
|
||||
|
|
@ -15,7 +15,7 @@ export interface HigressModelCard {
|
|||
};
|
||||
}
|
||||
|
||||
export const LobeHigressAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeHigressAI = createOpenAICompatibleRuntime({
|
||||
constructorOptions: {
|
||||
defaultHeaders: {
|
||||
'HTTP-Referer': 'https://chat-preview.lobehub.com',
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { convertIterableToStream } from '../utils/streams';
|
||||
|
||||
export interface HuggingFaceModelCard {
|
||||
|
|
@ -13,7 +13,7 @@ export interface HuggingFaceModelCard {
|
|||
tags: string[];
|
||||
}
|
||||
|
||||
export const LobeHuggingFaceAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeHuggingFaceAI = createOpenAICompatibleRuntime({
|
||||
chatCompletion: {
|
||||
handleStreamBizErrorType: (error) => {
|
||||
// e.g.: Server meta-llama/Meta-Llama-3.1-8B-Instruct does not seem to support chat completion. Error: Model requires a Pro subscription; check out hf.co/pricing to learn more. Make sure to include your HF token in your query.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface HunyuanModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeHunyuanAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeHunyuanAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.hunyuan.cloud.tencent.com/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export { LobeQwenAI } from './qwen';
|
|||
export { LobeTogetherAI } from './togetherai';
|
||||
export * from './types';
|
||||
export { AgentRuntimeError } from './utils/createError';
|
||||
export { LobeOpenAICompatibleFactory } from './utils/openaiCompatibleFactory';
|
||||
export { createOpenAICompatibleRuntime } from './utils/openaiCompatibleFactory';
|
||||
export { pruneReasoningPayload } from './utils/openaiHelpers';
|
||||
export { LobeVolcengineAI } from './volcengine';
|
||||
export { LobeZeroOneAI } from './zeroone';
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ChatCompletionErrorPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface InfiniAIModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeInfiniAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeInfiniAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://cloud.infini-ai.com/maas/v1',
|
||||
chatCompletion: {
|
||||
handleError(error): Omit<ChatCompletionErrorPayload, 'provider'> | undefined {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface InternLMModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeInternLMAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeInternLMAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://internlm-chat.intern-ai.org.cn/puyu/api/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
@ -23,9 +23,9 @@ export const LobeInternLMAI = LobeOpenAICompatibleFactory({
|
|||
models: async ({ client }) => {
|
||||
const { LOBE_DEFAULT_MODEL_LIST } = await import('@/config/aiModels');
|
||||
|
||||
const functionCallKeywords = ['internlm']
|
||||
const functionCallKeywords = ['internlm'];
|
||||
|
||||
const visionKeywords = ['internvl']
|
||||
const visionKeywords = ['internvl'];
|
||||
|
||||
const modelsPage = (await client.models.list()) as any;
|
||||
const modelList: InternLMModelCard[] = modelsPage.data;
|
||||
|
|
@ -41,15 +41,13 @@ export const LobeInternLMAI = LobeOpenAICompatibleFactory({
|
|||
displayName: knownModel?.displayName ?? undefined,
|
||||
enabled: knownModel?.enabled || false,
|
||||
functionCall:
|
||||
functionCallKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) ||
|
||||
functionCallKeywords.some((keyword) => model.id.toLowerCase().includes(keyword)) ||
|
||||
knownModel?.abilities?.functionCall ||
|
||||
false,
|
||||
id: model.id,
|
||||
reasoning:
|
||||
knownModel?.abilities?.reasoning ||
|
||||
false,
|
||||
reasoning: knownModel?.abilities?.reasoning || false,
|
||||
vision:
|
||||
visionKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) ||
|
||||
visionKeywords.some((keyword) => model.id.toLowerCase().includes(keyword)) ||
|
||||
knownModel?.abilities?.vision ||
|
||||
false,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface JinaModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeJinaAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeJinaAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://deepsearch.jina.ai/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_JINA_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface LMStudioModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeLMStudioAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeLMStudioAI = createOpenAICompatibleRuntime({
|
||||
apiKey: 'placeholder-to-avoid-error',
|
||||
baseURL: 'http://127.0.0.1:1234/v1',
|
||||
debug: {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import minimaxChatModels from '@/config/aiModels/minimax';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const getMinimaxMaxOutputs = (modelId: string): number | undefined => {
|
||||
const model = minimaxChatModels.find((model) => model.id === modelId);
|
||||
return model ? model.maxOutput : undefined;
|
||||
};
|
||||
|
||||
export const LobeMinimaxAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeMinimaxAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.minimax.chat/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface MistralModelCard {
|
||||
capabilities: {
|
||||
|
|
@ -13,7 +13,7 @@ export interface MistralModelCard {
|
|||
max_context_length: number;
|
||||
}
|
||||
|
||||
export const LobeMistralAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeMistralAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.mistral.ai/v1',
|
||||
chatCompletion: {
|
||||
// Mistral API does not support stream_options: { include_usage: true }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface ModelScopeModelCard {
|
||||
created: number;
|
||||
|
|
@ -11,7 +10,7 @@ export interface ModelScopeModelCard {
|
|||
owned_by: string;
|
||||
}
|
||||
|
||||
export const LobeModelScopeAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeModelScopeAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api-inference.modelscope.cn/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_MODELSCOPE_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface MoonshotModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeMoonshotAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeMoonshotAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.moonshot.cn/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload: ChatStreamPayload) => {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { NovitaModelCard } from './type';
|
||||
|
||||
export const LobeNovitaAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeNovitaAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.novita.ai/v3/openai',
|
||||
constructorOptions: {
|
||||
defaultHeaders: {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface NvidiaModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeNvidiaAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeNvidiaAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://integrate.api.nvidia.com/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_NVIDIA_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { createErrorResponse } from '@/utils/errorResponse';
|
|||
import { LobeRuntimeAI } from '../BaseAI';
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import {
|
||||
ChatCompetitionOptions,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
Embeddings,
|
||||
EmbeddingsPayload,
|
||||
|
|
@ -43,7 +43,7 @@ export class LobeOllamaAI implements LobeRuntimeAI {
|
|||
if (baseURL) this.baseURL = baseURL;
|
||||
}
|
||||
|
||||
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
try {
|
||||
const abort = () => {
|
||||
this.client.abort();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { pruneReasoningPayload } from '../utils/openaiHelpers';
|
||||
|
||||
export interface OpenAIModelCard {
|
||||
|
|
@ -10,13 +10,13 @@ export interface OpenAIModelCard {
|
|||
|
||||
const prunePrefixes = ['o1', 'o3', 'o4'];
|
||||
|
||||
export const LobeOpenAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeOpenAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.openai.com/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
const { model } = payload;
|
||||
|
||||
if (prunePrefixes.some(prefix => model.startsWith(prefix))) {
|
||||
if (prunePrefixes.some((prefix) => model.startsWith(prefix))) {
|
||||
return pruneReasoningPayload(payload) as any;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { OpenRouterModelCard, OpenRouterModelExtraInfo, OpenRouterReasoning } from './type';
|
||||
|
||||
const formatPrice = (price: string) => {
|
||||
|
|
@ -9,7 +9,7 @@ const formatPrice = (price: string) => {
|
|||
return Number((Number(price) * 1e6).toPrecision(5));
|
||||
};
|
||||
|
||||
export const LobeOpenRouterAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeOpenRouterAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://openrouter.ai/api/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import OpenAI from 'openai';
|
||||
|
||||
import { ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobePerplexityAI = LobeOpenAICompatibleFactory({
|
||||
export const LobePerplexityAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.perplexity.ai',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload: ChatStreamPayload) => {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { PPIOModelCard } from './type';
|
||||
|
||||
export const LobePPIOAI = LobeOpenAICompatibleFactory({
|
||||
export const LobePPIOAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.ppinfra.com/v3/openai',
|
||||
constructorOptions: {
|
||||
defaultHeaders: {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface QiniuModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeQiniuAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeQiniuAI = createOpenAICompatibleRuntime({
|
||||
apiKey: 'placeholder-to-avoid-error',
|
||||
baseURL: 'https://api.qnaigc.com/v1',
|
||||
debug: {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { QwenAIStream } from '../utils/streams';
|
||||
|
||||
export interface QwenModelCard {
|
||||
|
|
@ -20,7 +20,7 @@ export const QwenLegacyModels = new Set([
|
|||
'qwen-1.8b-longcontext-chat',
|
||||
]);
|
||||
|
||||
export const LobeQwenAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeQwenAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobeSambaNovaAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeSambaNovaAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.sambanova.ai/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_SAMBANOVA_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import OpenAI from 'openai';
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface Search1APIModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeSearch1API = LobeOpenAICompatibleFactory({
|
||||
export const LobeSearch1API = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.search1api.com/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload: ChatStreamPayload) => {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { convertSenseNovaMessage } from '../utils/sensenovaHelpers';
|
||||
|
||||
export interface SenseNovaModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeSenseNovaAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeSenseNovaAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.sensenova.cn/compatible-mode/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
|
||||
import { AgentRuntimeErrorType } from '../error';
|
||||
import { ChatCompletionErrorPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface SiliconCloudModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeSiliconCloudAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeSiliconCloudAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.siliconflow.cn/v1',
|
||||
chatCompletion: {
|
||||
handleError: (error: any): Omit<ChatCompletionErrorPayload, 'provider'> | undefined => {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,28 @@
|
|||
import { ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { SparkAIStream, transformSparkResponseToStream } from '../utils/streams';
|
||||
|
||||
export const LobeSparkAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeSparkAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://spark-api-open.xf-yun.com/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload: ChatStreamPayload) => {
|
||||
const { enabledSearch, tools, ...rest } = payload;
|
||||
|
||||
const sparkTools = enabledSearch ? [
|
||||
...(tools || []),
|
||||
{
|
||||
type: "web_search",
|
||||
web_search: {
|
||||
enable: true,
|
||||
search_mode: process.env.SPARK_SEARCH_MODE || "normal", // normal or deep
|
||||
/*
|
||||
const sparkTools = enabledSearch
|
||||
? [
|
||||
...(tools || []),
|
||||
{
|
||||
type: 'web_search',
|
||||
web_search: {
|
||||
enable: true,
|
||||
search_mode: process.env.SPARK_SEARCH_MODE || 'normal', // normal or deep
|
||||
/*
|
||||
show_ref_label: true,
|
||||
*/
|
||||
},
|
||||
}
|
||||
] : tools;
|
||||
},
|
||||
},
|
||||
]
|
||||
: tools;
|
||||
|
||||
return {
|
||||
...rest,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface StepfunModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeStepfunAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeStepfunAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.stepfun.com/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import OpenAI from 'openai';
|
||||
|
||||
import { ChatStreamPayload, ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobeTaichuAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeTaichuAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://ai-maas.wair.ac.cn/maas/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload: ChatStreamPayload) => {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface TencentCloudModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeTencentCloudAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeTencentCloudAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.lkeap.cloud.tencent.com/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_TENCENT_CLOUD_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
import { TogetherAIModel } from './type';
|
||||
|
||||
export const LobeTogetherAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeTogetherAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.together.xyz/v1',
|
||||
constructorOptions: {
|
||||
defaultHeaders: {
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ export interface ChatStreamPayload {
|
|||
top_p?: number;
|
||||
}
|
||||
|
||||
export interface ChatCompetitionOptions {
|
||||
export interface ChatMethodOptions {
|
||||
callback?: ChatStreamCallbacks;
|
||||
/**
|
||||
* response headers
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobeUpstageAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeUpstageAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.upstage.ai/v1/solar',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_UPSTAGE_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import officalOpenAIModels from '@/libs/model-runtime/openai/fixtures/openai-mod
|
|||
import { sleep } from '@/utils/sleep';
|
||||
|
||||
import * as debugStreamModule from '../debugStream';
|
||||
import { LobeOpenAICompatibleFactory } from './index';
|
||||
import { createOpenAICompatibleRuntime } from './index';
|
||||
|
||||
const provider = 'groq';
|
||||
const defaultBaseURL = 'https://api.groq.com/openai/v1';
|
||||
|
|
@ -26,7 +26,7 @@ vi.spyOn(console, 'error').mockImplementation(() => {});
|
|||
|
||||
let instance: LobeOpenAICompatibleRuntime;
|
||||
|
||||
const LobeMockProvider = LobeOpenAICompatibleFactory({
|
||||
const LobeMockProvider = createOpenAICompatibleRuntime({
|
||||
baseURL: defaultBaseURL,
|
||||
chatCompletion: {
|
||||
handleError: (error) => {
|
||||
|
|
@ -426,7 +426,7 @@ describe('LobeOpenAICompatibleFactory', () => {
|
|||
|
||||
describe('noUserId option', () => {
|
||||
it('should not add user to payload when noUserId is true', async () => {
|
||||
const LobeMockProvider = LobeOpenAICompatibleFactory({
|
||||
const LobeMockProvider = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.mistral.ai/v1',
|
||||
chatCompletion: {
|
||||
noUserId: true,
|
||||
|
|
@ -457,7 +457,7 @@ describe('LobeOpenAICompatibleFactory', () => {
|
|||
});
|
||||
|
||||
it('should add user to payload when noUserId is false', async () => {
|
||||
const LobeMockProvider = LobeOpenAICompatibleFactory({
|
||||
const LobeMockProvider = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.mistral.ai/v1',
|
||||
chatCompletion: {
|
||||
noUserId: false,
|
||||
|
|
@ -488,7 +488,7 @@ describe('LobeOpenAICompatibleFactory', () => {
|
|||
});
|
||||
|
||||
it('should add user to payload when noUserId is not set in chatCompletion', async () => {
|
||||
const LobeMockProvider = LobeOpenAICompatibleFactory({
|
||||
const LobeMockProvider = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.mistral.ai/v1',
|
||||
provider: ModelProvider.Mistral,
|
||||
});
|
||||
|
|
@ -831,7 +831,7 @@ describe('LobeOpenAICompatibleFactory', () => {
|
|||
},
|
||||
);
|
||||
|
||||
const LobeMockProvider = LobeOpenAICompatibleFactory({
|
||||
const LobeMockProvider = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.test.com/v1',
|
||||
chatCompletion: {
|
||||
handleStream: customStreamHandler,
|
||||
|
|
@ -890,7 +890,7 @@ describe('LobeOpenAICompatibleFactory', () => {
|
|||
});
|
||||
});
|
||||
|
||||
const LobeMockProvider = LobeOpenAICompatibleFactory({
|
||||
const LobeMockProvider = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.test.com/v1',
|
||||
chatCompletion: {
|
||||
handleTransformResponseToStream: customTransformHandler,
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import type { ChatModelCard } from '@/types/llm';
|
|||
import { LobeRuntimeAI } from '../../BaseAI';
|
||||
import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../../error';
|
||||
import type {
|
||||
ChatCompetitionOptions,
|
||||
ChatCompletionErrorPayload,
|
||||
ChatMethodOptions,
|
||||
ChatStreamPayload,
|
||||
Embeddings,
|
||||
EmbeddingsOptions,
|
||||
|
|
@ -150,7 +150,7 @@ export function transformResponseToStream(data: OpenAI.ChatCompletion) {
|
|||
});
|
||||
}
|
||||
|
||||
export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>({
|
||||
export const createOpenAICompatibleRuntime = <T extends Record<string, any> = any>({
|
||||
provider,
|
||||
baseURL: DEFAULT_BASE_URL,
|
||||
apiKey: DEFAULT_API_LEY,
|
||||
|
|
@ -199,7 +199,7 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
|
|||
this.id = options.id || provider;
|
||||
}
|
||||
|
||||
async chat({ responseMode, ...payload }: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
||||
async chat({ responseMode, ...payload }: ChatStreamPayload, options?: ChatMethodOptions) {
|
||||
try {
|
||||
const inputStartAt = Date.now();
|
||||
const postPayload = chatCompletion?.handlePayload
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface VLLMModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeVLLMAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeVLLMAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'http://localhost:8000/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_VLLM_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobeVolcengineAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeVolcengineAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://ark.cn-beijing.volces.com/api/v3',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export const LobeWenxinAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeWenxinAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://qianfan.baidubce.com/v2',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface XAIModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeXAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeXAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.x.ai/v1',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
@ -21,7 +21,10 @@ export const LobeXAI = LobeOpenAICompatibleFactory({
|
|||
stream: true,
|
||||
...(enabledSearch && {
|
||||
search_parameters: {
|
||||
max_search_results: Math.min(Math.max(parseInt(process.env.XAI_MAX_SEARCH_RESULTS ?? '15', 10), 1), 30),
|
||||
max_search_results: Math.min(
|
||||
Math.max(parseInt(process.env.XAI_MAX_SEARCH_RESULTS ?? '15', 10), 1),
|
||||
30,
|
||||
),
|
||||
mode: 'auto',
|
||||
return_citations: true,
|
||||
sources: [
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface XinferenceModelCard {
|
||||
context_length: number;
|
||||
|
|
@ -12,7 +12,7 @@ export interface XinferenceModelCard {
|
|||
name: string;
|
||||
}
|
||||
|
||||
export const LobeXinferenceAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeXinferenceAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'http://localhost:9997/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_XINFERENCE_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface ZeroOneModelCard {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const LobeZeroOneAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeZeroOneAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://api.lingyiwanwu.com/v1',
|
||||
debug: {
|
||||
chatCompletion: () => process.env.DEBUG_ZEROONE_CHAT_COMPLETION === '1',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatModelCard } from '@/types/llm';
|
||||
|
||||
import { ModelProvider } from '../types';
|
||||
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
||||
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
||||
|
||||
export interface ZhipuModelCard {
|
||||
description: string;
|
||||
|
|
@ -9,7 +9,7 @@ export interface ZhipuModelCard {
|
|||
modelName: string;
|
||||
}
|
||||
|
||||
export const LobeZhipuAI = LobeOpenAICompatibleFactory({
|
||||
export const LobeZhipuAI = createOpenAICompatibleRuntime({
|
||||
baseURL: 'https://open.bigmodel.cn/api/paas/v4',
|
||||
chatCompletion: {
|
||||
handlePayload: (payload) => {
|
||||
|
|
|
|||
|
|
@ -104,8 +104,7 @@ describe('searchRouter', () => {
|
|||
query: 'test query',
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
costTime: 0,
|
||||
expect(result).toMatchObject({
|
||||
query: 'test query',
|
||||
results: [
|
||||
{
|
||||
|
|
@ -139,8 +138,7 @@ describe('searchRouter', () => {
|
|||
query: 'test query',
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
costTime: 0,
|
||||
expect(result).toMatchObject({
|
||||
query: 'test query',
|
||||
results: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -671,14 +671,16 @@ describe('chatMessage actions', () => {
|
|||
(chatService.createAssistantMessage as Mock).mockResolvedValue(aiResponse);
|
||||
const spy = vi.spyOn(chatService, 'createAssistantMessageStream');
|
||||
// 模拟消息创建
|
||||
(messageService.createMessage as Mock).mockResolvedValue('assistant-message-id');
|
||||
const createMessageSpyOn = vi
|
||||
.spyOn(messageService, 'createMessage')
|
||||
.mockResolvedValue('assistant-message-id');
|
||||
|
||||
await act(async () => {
|
||||
await result.current.internal_coreProcessMessage(messages, userMessage.id);
|
||||
});
|
||||
|
||||
// 验证是否创建了代表 AI 响应的消息
|
||||
expect(messageService.createMessage).toHaveBeenCalledWith(
|
||||
expect(createMessageSpyOn).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
role: 'assistant',
|
||||
content: LOADING_FLAT,
|
||||
|
|
|
|||
|
|
@ -369,11 +369,12 @@ describe('chatMessage actions', () => {
|
|||
const messageId = 'message-id';
|
||||
const newContent = 'Updated content';
|
||||
|
||||
const spy = vi.spyOn(messageService, 'updateMessage');
|
||||
await act(async () => {
|
||||
await result.current.internal_updateMessageContent(messageId, newContent);
|
||||
});
|
||||
|
||||
expect(messageService.updateMessage).toHaveBeenCalledWith(messageId, { content: newContent });
|
||||
expect(spy).toHaveBeenCalledWith(messageId, { content: newContent });
|
||||
});
|
||||
|
||||
it('should dispatch message update action', async () => {
|
||||
|
|
|
|||
|
|
@ -264,7 +264,8 @@ describe('topic action', () => {
|
|||
const topicId = 'topic-id';
|
||||
const newTitle = 'Updated Topic Title';
|
||||
// Mock the topicService.updateTitle to resolve immediately
|
||||
(topicService.updateTopic as Mock).mockResolvedValue(undefined);
|
||||
|
||||
const spyOn = vi.spyOn(topicService, 'updateTopic');
|
||||
|
||||
const { result } = renderHook(() => useChatStore());
|
||||
|
||||
|
|
@ -276,7 +277,7 @@ describe('topic action', () => {
|
|||
});
|
||||
|
||||
// Verify that the topicService.updateTitle was called with correct parameters
|
||||
expect(topicService.updateTopic).toHaveBeenCalledWith(topicId, {
|
||||
expect(spyOn).toHaveBeenCalledWith(topicId, {
|
||||
title: 'Updated Topic Title',
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue