@lobehub/chat 0.146.1 → 0.147.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +3 -5
- package/.github/workflows/issue-close-require.yml +1 -1
- package/.github/workflows/release.yml +1 -1
- package/.github/workflows/test.yml +3 -1
- package/.i18nrc.js +13 -8
- package/.seorc.cjs +9 -0
- package/CHANGELOG.md +98 -0
- package/README.md +25 -25
- package/README.zh-CN.md +25 -25
- package/contributing/Home.md +1 -1
- package/docs/self-hosting/advanced/analytics.mdx +12 -0
- package/docs/self-hosting/advanced/analytics.zh-CN.mdx +10 -0
- package/docs/self-hosting/advanced/authentication.mdx +19 -0
- package/docs/self-hosting/advanced/authentication.zh-CN.mdx +15 -0
- package/docs/self-hosting/advanced/sso-providers/auth0.mdx +19 -2
- package/docs/self-hosting/advanced/sso-providers/auth0.zh-CN.mdx +15 -2
- package/docs/self-hosting/advanced/sso-providers/authentik.mdx +18 -3
- package/docs/self-hosting/advanced/sso-providers/authentik.zh-CN.mdx +14 -2
- package/docs/self-hosting/advanced/sso-providers/github.mdx +13 -0
- package/docs/self-hosting/advanced/sso-providers/github.zh-CN.mdx +13 -3
- package/docs/self-hosting/advanced/sso-providers/microsoft-entra-id.mdx +18 -2
- package/docs/self-hosting/advanced/sso-providers/microsoft-entra-id.zh-CN.mdx +15 -2
- package/docs/self-hosting/advanced/sso-providers/zitadel.mdx +17 -2
- package/docs/self-hosting/advanced/sso-providers/zitadel.zh-CN.mdx +14 -2
- package/docs/self-hosting/advanced/upstream-sync.mdx +13 -0
- package/docs/self-hosting/advanced/upstream-sync.zh-CN.mdx +10 -0
- package/docs/self-hosting/environment-variables/analytics.mdx +15 -0
- package/docs/self-hosting/environment-variables/analytics.zh-CN.mdx +13 -0
- package/docs/self-hosting/environment-variables/auth.mdx +14 -0
- package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +15 -1
- package/docs/self-hosting/environment-variables/basic.mdx +15 -0
- package/docs/self-hosting/environment-variables/basic.zh-CN.mdx +11 -0
- package/docs/self-hosting/environment-variables/model-provider.mdx +26 -0
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +10 -0
- package/docs/self-hosting/environment-variables.mdx +13 -2
- package/docs/self-hosting/environment-variables.zh-CN.mdx +9 -0
- package/docs/self-hosting/examples/azure-openai.mdx +12 -0
- package/docs/self-hosting/examples/azure-openai.zh-CN.mdx +12 -0
- package/docs/self-hosting/examples/ollama.mdx +13 -0
- package/docs/self-hosting/examples/ollama.zh-CN.mdx +11 -0
- package/docs/self-hosting/faq/no-v1-suffix.mdx +12 -0
- package/docs/self-hosting/faq/no-v1-suffix.zh-CN.mdx +9 -0
- package/docs/self-hosting/faq/proxy-with-unable-to-verify-leaf-signature.mdx +14 -0
- package/docs/self-hosting/faq/proxy-with-unable-to-verify-leaf-signature.zh-CN.mdx +11 -0
- package/docs/self-hosting/platform/docker-compose.mdx +21 -5
- package/docs/self-hosting/platform/docker-compose.zh-CN.mdx +18 -5
- package/docs/self-hosting/platform/docker.mdx +26 -8
- package/docs/self-hosting/platform/docker.zh-CN.mdx +27 -9
- package/docs/self-hosting/platform/netlify.mdx +18 -2
- package/docs/self-hosting/platform/netlify.zh-CN.mdx +14 -1
- package/docs/self-hosting/platform/railway.mdx +12 -0
- package/docs/self-hosting/platform/railway.zh-CN.mdx +11 -0
- package/docs/self-hosting/platform/repocloud.mdx +12 -0
- package/docs/self-hosting/platform/repocloud.zh-CN.mdx +10 -0
- package/docs/self-hosting/platform/sealos.mdx +11 -0
- package/docs/self-hosting/platform/sealos.zh-CN.mdx +10 -0
- package/docs/self-hosting/platform/vercel.mdx +12 -0
- package/docs/self-hosting/platform/vercel.zh-CN.mdx +11 -0
- package/docs/self-hosting/platform/zeabur.mdx +11 -0
- package/docs/self-hosting/platform/zeabur.zh-CN.mdx +10 -0
- package/docs/self-hosting/start.mdx +12 -0
- package/docs/self-hosting/start.zh-CN.mdx +13 -0
- package/docs/usage/agents/concepts.mdx +13 -0
- package/docs/usage/agents/concepts.zh-CN.mdx +10 -0
- package/docs/usage/agents/custom-agent.mdx +16 -2
- package/docs/usage/agents/custom-agent.zh-CN.mdx +14 -2
- package/docs/usage/agents/model.mdx +11 -2
- package/docs/usage/agents/model.zh-CN.mdx +12 -0
- package/docs/usage/agents/prompt.mdx +15 -0
- package/docs/usage/agents/prompt.zh-CN.mdx +10 -0
- package/docs/usage/agents/topics.mdx +13 -0
- package/docs/usage/agents/topics.zh-CN.mdx +11 -0
- package/docs/usage/features/agent-market.mdx +11 -1
- package/docs/usage/features/agent-market.zh-CN.mdx +13 -0
- package/docs/usage/features/local-llm.mdx +12 -2
- package/docs/usage/features/local-llm.zh-CN.mdx +3 -3
- package/docs/usage/features/mobile.mdx +10 -1
- package/docs/usage/features/mobile.zh-CN.mdx +11 -0
- package/docs/usage/features/more.mdx +13 -0
- package/docs/usage/features/more.zh-CN.mdx +10 -0
- package/docs/usage/features/multi-ai-providers.mdx +14 -1
- package/docs/usage/features/multi-ai-providers.zh-CN.mdx +16 -0
- package/docs/usage/features/plugin-system.mdx +12 -1
- package/docs/usage/features/plugin-system.zh-CN.mdx +9 -0
- package/docs/usage/features/pwa.mdx +11 -1
- package/docs/usage/features/pwa.zh-CN.mdx +13 -0
- package/docs/usage/features/text-to-image.mdx +11 -1
- package/docs/usage/features/text-to-image.zh-CN.mdx +13 -0
- package/docs/usage/features/theme.mdx +12 -1
- package/docs/usage/features/theme.zh-CN.mdx +11 -0
- package/docs/usage/features/tts.mdx +14 -1
- package/docs/usage/features/tts.zh-CN.mdx +12 -0
- package/docs/usage/features/vision.mdx +11 -1
- package/docs/usage/features/vision.zh-CN.mdx +10 -0
- package/docs/usage/plugins/basic-usage.mdx +12 -0
- package/docs/usage/plugins/basic-usage.zh-CN.mdx +10 -0
- package/docs/usage/plugins/custom-plugin.mdx +12 -0
- package/docs/usage/plugins/custom-plugin.zh-CN.mdx +10 -0
- package/docs/usage/plugins/development.mdx +18 -0
- package/docs/usage/plugins/development.zh-CN.mdx +12 -0
- package/docs/usage/plugins/store.mdx +12 -0
- package/docs/usage/plugins/store.zh-CN.mdx +9 -0
- package/docs/usage/providers/groq.mdx +14 -2
- package/docs/usage/providers/groq.zh-CN.mdx +12 -2
- package/docs/usage/providers/ollama/gemma.mdx +13 -3
- package/docs/usage/providers/ollama/gemma.zh-CN.mdx +12 -3
- package/docs/usage/providers/ollama/qwen.mdx +12 -4
- package/docs/usage/providers/ollama/qwen.zh-CN.mdx +10 -3
- package/docs/usage/providers/ollama.mdx +19 -9
- package/docs/usage/providers/ollama.zh-CN.mdx +20 -9
- package/docs/usage/start.mdx +13 -2
- package/docs/usage/start.zh-CN.mdx +11 -2
- package/locales/ar/common.json +0 -26
- package/locales/ar/components.json +15 -0
- package/locales/ar/error.json +1 -52
- package/locales/ar/modelProvider.json +226 -0
- package/locales/ar/setting.json +48 -199
- package/locales/bg-BG/common.json +0 -26
- package/locales/bg-BG/components.json +15 -0
- package/locales/bg-BG/error.json +1 -52
- package/locales/bg-BG/modelProvider.json +226 -0
- package/locales/bg-BG/setting.json +48 -199
- package/locales/de-DE/common.json +0 -26
- package/locales/de-DE/components.json +15 -0
- package/locales/de-DE/error.json +1 -52
- package/locales/de-DE/modelProvider.json +226 -0
- package/locales/de-DE/setting.json +48 -199
- package/locales/en-US/common.json +0 -26
- package/locales/en-US/components.json +15 -0
- package/locales/en-US/error.json +1 -52
- package/locales/en-US/modelProvider.json +226 -0
- package/locales/en-US/setting.json +48 -199
- package/locales/es-ES/common.json +0 -26
- package/locales/es-ES/components.json +15 -0
- package/locales/es-ES/error.json +1 -52
- package/locales/es-ES/modelProvider.json +226 -0
- package/locales/es-ES/setting.json +48 -199
- package/locales/fr-FR/common.json +0 -26
- package/locales/fr-FR/components.json +15 -0
- package/locales/fr-FR/error.json +1 -52
- package/locales/fr-FR/modelProvider.json +226 -0
- package/locales/fr-FR/setting.json +48 -199
- package/locales/it-IT/common.json +0 -26
- package/locales/it-IT/components.json +15 -0
- package/locales/it-IT/error.json +1 -52
- package/locales/it-IT/modelProvider.json +226 -0
- package/locales/it-IT/setting.json +59 -210
- package/locales/ja-JP/common.json +0 -26
- package/locales/ja-JP/components.json +15 -0
- package/locales/ja-JP/error.json +1 -52
- package/locales/ja-JP/modelProvider.json +226 -0
- package/locales/ja-JP/setting.json +59 -210
- package/locales/ko-KR/common.json +0 -26
- package/locales/ko-KR/components.json +15 -0
- package/locales/ko-KR/error.json +1 -52
- package/locales/ko-KR/modelProvider.json +226 -0
- package/locales/ko-KR/setting.json +48 -199
- package/locales/nl-NL/common.json +0 -26
- package/locales/nl-NL/components.json +15 -0
- package/locales/nl-NL/error.json +4 -55
- package/locales/nl-NL/modelProvider.json +226 -0
- package/locales/nl-NL/setting.json +49 -200
- package/locales/pl-PL/common.json +0 -26
- package/locales/pl-PL/components.json +15 -0
- package/locales/pl-PL/error.json +1 -52
- package/locales/pl-PL/modelProvider.json +226 -0
- package/locales/pl-PL/setting.json +48 -199
- package/locales/pt-BR/common.json +0 -26
- package/locales/pt-BR/components.json +15 -0
- package/locales/pt-BR/error.json +1 -52
- package/locales/pt-BR/modelProvider.json +226 -0
- package/locales/pt-BR/setting.json +48 -199
- package/locales/ru-RU/common.json +0 -26
- package/locales/ru-RU/components.json +15 -0
- package/locales/ru-RU/error.json +1 -52
- package/locales/ru-RU/modelProvider.json +226 -0
- package/locales/ru-RU/setting.json +48 -199
- package/locales/tr-TR/common.json +0 -26
- package/locales/tr-TR/components.json +15 -0
- package/locales/tr-TR/error.json +1 -52
- package/locales/tr-TR/modelProvider.json +226 -0
- package/locales/tr-TR/setting.json +48 -199
- package/locales/vi-VN/common.json +0 -26
- package/locales/vi-VN/components.json +15 -0
- package/locales/vi-VN/error.json +1 -52
- package/locales/vi-VN/modelProvider.json +226 -0
- package/locales/vi-VN/setting.json +48 -199
- package/locales/zh-CN/common.json +0 -26
- package/locales/zh-CN/components.json +15 -0
- package/locales/zh-CN/error.json +2 -53
- package/locales/zh-CN/modelProvider.json +226 -0
- package/locales/zh-CN/setting.json +48 -199
- package/locales/zh-TW/common.json +0 -26
- package/locales/zh-TW/components.json +15 -0
- package/locales/zh-TW/error.json +1 -52
- package/locales/zh-TW/modelProvider.json +226 -0
- package/locales/zh-TW/setting.json +48 -199
- package/package.json +121 -117
- package/scripts/mdxWorkflow/index.ts +48 -0
- package/src/app/api/chat/[provider]/route.test.ts +4 -9
- package/src/app/api/chat/[provider]/route.ts +6 -23
- package/src/app/api/chat/{[provider]/agentRuntime.test.ts → agentRuntime.test.ts} +12 -12
- package/src/app/api/chat/{[provider]/agentRuntime.ts → agentRuntime.ts} +11 -30
- package/src/app/api/chat/auth/index.ts +42 -0
- package/src/app/api/chat/models/[provider]/route.ts +45 -0
- package/src/app/api/config/__snapshots__/route.test.ts.snap +127 -0
- package/src/app/api/config/route.test.ts +170 -0
- package/src/app/api/config/route.ts +46 -11
- package/src/app/api/plugin/gateway/route.ts +1 -1
- package/src/app/settings/llm/Azure/index.tsx +36 -43
- package/src/app/settings/llm/Bedrock/index.tsx +12 -20
- package/src/app/settings/llm/Ollama/index.tsx +2 -2
- package/src/app/settings/llm/OpenAI/index.tsx +9 -121
- package/src/app/settings/llm/OpenRouter/index.tsx +1 -1
- package/src/app/settings/llm/TogetherAI/index.tsx +0 -1
- package/src/app/settings/llm/components/ProviderConfig/index.tsx +48 -32
- package/src/app/settings/llm/components/ProviderModelList/CustomModelOption.tsx +94 -0
- package/src/app/settings/llm/components/ProviderModelList/MaxTokenSlider.tsx +88 -0
- package/src/app/settings/llm/components/ProviderModelList/ModelConfigModal.tsx +128 -0
- package/src/app/settings/llm/components/ProviderModelList/ModelFetcher.tsx +81 -0
- package/src/app/settings/llm/components/ProviderModelList/Option.tsx +38 -0
- package/src/app/settings/llm/components/ProviderModelList/index.tsx +142 -0
- package/src/app/settings/llm/const.ts +1 -1
- package/src/app/settings/llm/index.tsx +7 -6
- package/src/app/settings/tts/TTS/index.tsx +1 -1
- package/src/components/AntdStaticMethods/index.test.tsx +43 -0
- package/src/components/ModelIcon/index.tsx +25 -7
- package/src/components/ModelSelect/index.tsx +67 -56
- package/src/config/modelProviders/anthropic.ts +6 -1
- package/src/config/modelProviders/azure.ts +42 -0
- package/src/config/modelProviders/bedrock.ts +4 -1
- package/src/config/modelProviders/google.ts +2 -14
- package/src/config/modelProviders/groq.ts +3 -0
- package/src/config/modelProviders/index.ts +19 -14
- package/src/config/modelProviders/mistral.ts +5 -0
- package/src/config/modelProviders/moonshot.ts +3 -1
- package/src/config/modelProviders/ollama.ts +6 -17
- package/src/config/modelProviders/openai.ts +9 -13
- package/src/config/modelProviders/openrouter.ts +6 -1
- package/src/config/modelProviders/perplexity.ts +2 -0
- package/src/config/modelProviders/togetherai.ts +11 -0
- package/src/config/modelProviders/zeroone.ts +3 -0
- package/src/config/modelProviders/zhipu.ts +3 -0
- package/src/config/server/provider.ts +52 -7
- package/src/const/auth.ts +0 -1
- package/src/const/{settings.ts → settings/index.ts} +31 -4
- package/src/const/url.ts +1 -1
- package/src/database/core/db.ts +14 -0
- package/src/database/schemas/user.ts +1 -25
- package/src/features/AgentSetting/AgentConfig/ModelSelect.tsx +7 -11
- package/src/features/ChatInput/STT/common.tsx +80 -78
- package/src/features/ChatInput/STT/index.tsx +8 -6
- package/src/features/Conversation/Error/APIKeyForm/Bedrock.tsx +8 -8
- package/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx +73 -0
- package/src/features/Conversation/Error/APIKeyForm/ProviderAvatar.tsx +74 -0
- package/src/features/Conversation/Error/APIKeyForm/index.tsx +25 -49
- package/src/features/ModelSwitchPanel/index.tsx +40 -13
- package/src/hooks/_header.ts +5 -20
- package/src/libs/agent-runtime/BaseAI.ts +17 -1
- package/src/libs/agent-runtime/anthropic/index.ts +3 -7
- package/src/libs/agent-runtime/azureOpenai/index.test.ts +166 -0
- package/src/libs/agent-runtime/azureOpenai/index.ts +16 -8
- package/src/libs/agent-runtime/bedrock/index.test.ts +199 -22
- package/src/libs/agent-runtime/bedrock/index.ts +11 -18
- package/src/libs/agent-runtime/groq/index.test.ts +350 -0
- package/src/libs/agent-runtime/groq/index.ts +14 -77
- package/src/libs/agent-runtime/mistral/index.test.ts +25 -19
- package/src/libs/agent-runtime/mistral/index.ts +24 -86
- package/src/libs/agent-runtime/moonshot/index.test.ts +2 -2
- package/src/libs/agent-runtime/moonshot/index.ts +14 -77
- package/src/libs/agent-runtime/openai/__snapshots__/index.test.ts.snap +99 -0
- package/src/libs/agent-runtime/openai/fixtures/openai-models.json +170 -0
- package/src/libs/agent-runtime/openai/index.test.ts +15 -50
- package/src/libs/agent-runtime/openai/index.ts +15 -107
- package/src/libs/agent-runtime/openrouter/__snapshots__/index.test.ts.snap +82 -0
- package/src/libs/agent-runtime/openrouter/fixtures/models.json +62 -0
- package/src/libs/agent-runtime/openrouter/index.test.ts +25 -9
- package/src/libs/agent-runtime/openrouter/index.ts +42 -84
- package/src/libs/agent-runtime/openrouter/type.ts +28 -0
- package/src/libs/agent-runtime/togetherai/index.test.ts +12 -9
- package/src/libs/agent-runtime/togetherai/index.ts +20 -85
- package/src/libs/agent-runtime/utils/anthropicHelpers.test.ts +14 -22
- package/src/libs/agent-runtime/utils/anthropicHelpers.ts +4 -10
- package/src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts +147 -0
- package/src/libs/agent-runtime/zeroone/index.test.ts +350 -0
- package/src/libs/agent-runtime/zeroone/index.ts +14 -77
- package/src/locales/default/common.ts +0 -28
- package/src/locales/default/components.ts +15 -0
- package/src/locales/default/error.ts +2 -54
- package/src/locales/default/index.ts +4 -0
- package/src/locales/default/modelProvider.ts +229 -0
- package/src/locales/default/setting.ts +51 -202
- package/src/migrations/FromV3ToV4/fixtures/azure-input-v3.json +79 -0
- package/src/migrations/FromV3ToV4/fixtures/azure-output-v4.json +75 -0
- package/src/migrations/FromV3ToV4/fixtures/ollama-input-v3.json +85 -0
- package/src/migrations/FromV3ToV4/fixtures/ollama-output-v4.json +86 -0
- package/src/migrations/FromV3ToV4/fixtures/openai-input-v3.json +77 -0
- package/src/migrations/FromV3ToV4/fixtures/openai-output-v4.json +79 -0
- package/src/migrations/FromV3ToV4/fixtures/openrouter-input-v3.json +82 -0
- package/src/migrations/FromV3ToV4/fixtures/openrouter-output-v4.json +89 -0
- package/src/migrations/FromV3ToV4/fixtures/output-v4-from-v1.json +203 -0
- package/src/migrations/FromV3ToV4/index.ts +96 -0
- package/src/migrations/FromV3ToV4/migrations.test.ts +195 -0
- package/src/migrations/FromV3ToV4/types/v3.ts +59 -0
- package/src/migrations/FromV3ToV4/types/v4.ts +37 -0
- package/src/migrations/index.ts +11 -3
- package/src/services/_auth.test.ts +4 -6
- package/src/services/_auth.ts +8 -60
- package/src/services/_header.ts +5 -22
- package/src/services/_url.ts +1 -0
- package/src/services/chat.ts +16 -6
- package/src/services/global.ts +1 -1
- package/src/services/models.ts +23 -0
- package/src/services/ollama.ts +2 -2
- package/src/store/chat/slices/share/action.test.ts +113 -0
- package/src/store/chat/slices/share/action.ts +1 -1
- package/src/store/global/slices/common/action.test.ts +166 -1
- package/src/store/global/slices/common/action.ts +2 -1
- package/src/store/global/slices/settings/{action.test.ts → actions/general.test.ts} +1 -19
- package/src/store/global/slices/settings/{action.ts → actions/general.ts} +4 -19
- package/src/store/global/slices/settings/actions/index.ts +18 -0
- package/src/store/global/slices/settings/actions/llm.test.ts +60 -0
- package/src/store/global/slices/settings/actions/llm.ts +88 -0
- package/src/store/global/slices/settings/initialState.ts +3 -1
- package/src/store/global/slices/settings/reducers/customModelCard.test.ts +204 -0
- package/src/store/global/slices/settings/reducers/customModelCard.ts +64 -0
- package/src/store/global/slices/settings/selectors/index.ts +1 -0
- package/src/store/global/slices/settings/selectors/modelConfig.test.ts +189 -0
- package/src/store/global/slices/settings/selectors/modelConfig.ts +179 -0
- package/src/store/global/slices/settings/selectors/modelProvider.test.ts +47 -138
- package/src/store/global/slices/settings/selectors/modelProvider.ts +102 -243
- package/src/store/global/store.ts +1 -1
- package/src/types/llm.ts +12 -1
- package/src/types/serverConfig.ts +22 -0
- package/src/types/settings/index.ts +0 -12
- package/src/types/settings/modelProvider.ts +34 -90
- package/src/utils/client/switchLang.test.ts +34 -0
- package/src/utils/difference.test.ts +46 -0
- package/src/utils/difference.ts +15 -2
- package/src/utils/fetch.ts +1 -3
- package/src/utils/parseModels.ts +62 -0
- package/vercel.json +1 -1
- package/docs/package.json +0 -5
- package/src/features/Conversation/Error/APIKeyForm/Anthropic.tsx +0 -40
- package/src/features/Conversation/Error/APIKeyForm/Google.tsx +0 -61
- package/src/features/Conversation/Error/APIKeyForm/Groq.tsx +0 -60
- package/src/features/Conversation/Error/APIKeyForm/Mistral.tsx +0 -60
- package/src/features/Conversation/Error/APIKeyForm/Moonshot.tsx +0 -60
- package/src/features/Conversation/Error/APIKeyForm/OpenAI.tsx +0 -63
- package/src/features/Conversation/Error/APIKeyForm/OpenRouter.tsx +0 -40
- package/src/features/Conversation/Error/APIKeyForm/Perplexity.tsx +0 -60
- package/src/features/Conversation/Error/APIKeyForm/TogetherAI.tsx +0 -40
- package/src/features/Conversation/Error/APIKeyForm/ZeroOne.tsx +0 -60
- package/src/features/Conversation/Error/APIKeyForm/Zhipu.tsx +0 -62
- package/src/libs/agent-runtime/utils/env.ts +0 -1
- package/src/store/global/slices/settings/selectors/__snapshots__/modelProvider.test.ts.snap +0 -230
- /package/src/app/api/chat/{auth.ts → auth/utils.ts} +0 -0
- /package/src/components/{AntdStaticMethods.tsx → AntdStaticMethods/index.tsx} +0 -0
|
@@ -1,78 +1,15 @@
|
|
|
1
|
-
import { OpenAIStream, StreamingTextResponse } from 'ai';
|
|
2
|
-
import OpenAI, { ClientOptions } from 'openai';
|
|
3
|
-
|
|
4
|
-
import { LobeRuntimeAI } from '../BaseAI';
|
|
5
1
|
import { AgentRuntimeErrorType } from '../error';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!apiKey) throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidMoonshotAPIKey);
|
|
21
|
-
|
|
22
|
-
this.client = new OpenAI({ apiKey, baseURL, ...res });
|
|
23
|
-
this.baseURL = this.client.baseURL;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
|
27
|
-
try {
|
|
28
|
-
const response = await this.client.chat.completions.create(
|
|
29
|
-
payload as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
|
|
30
|
-
);
|
|
31
|
-
const [prod, debug] = response.tee();
|
|
32
|
-
|
|
33
|
-
if (process.env.DEBUG_MOONSHOT_CHAT_COMPLETION === '1') {
|
|
34
|
-
debugStream(debug.toReadableStream()).catch(console.error);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return new StreamingTextResponse(OpenAIStream(prod, options?.callback), {
|
|
38
|
-
headers: options?.headers,
|
|
39
|
-
});
|
|
40
|
-
} catch (error) {
|
|
41
|
-
let desensitizedEndpoint = this.baseURL;
|
|
42
|
-
|
|
43
|
-
if (this.baseURL !== DEFAULT_BASE_URL) {
|
|
44
|
-
desensitizedEndpoint = desensitizeUrl(this.baseURL);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if ('status' in (error as any)) {
|
|
48
|
-
switch ((error as Response).status) {
|
|
49
|
-
case 401: {
|
|
50
|
-
throw AgentRuntimeError.chat({
|
|
51
|
-
endpoint: desensitizedEndpoint,
|
|
52
|
-
error: error as any,
|
|
53
|
-
errorType: AgentRuntimeErrorType.InvalidMoonshotAPIKey,
|
|
54
|
-
provider: ModelProvider.Moonshot,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
default: {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
|
65
|
-
|
|
66
|
-
const errorType = RuntimeError || AgentRuntimeErrorType.MoonshotBizError;
|
|
67
|
-
|
|
68
|
-
throw AgentRuntimeError.chat({
|
|
69
|
-
endpoint: desensitizedEndpoint,
|
|
70
|
-
error: errorResult,
|
|
71
|
-
errorType,
|
|
72
|
-
provider: ModelProvider.Moonshot,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default LobeMoonshotAI;
|
|
2
|
+
import { ModelProvider } from '../types';
|
|
3
|
+
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
|
4
|
+
|
|
5
|
+
export const LobeMoonshotAI = LobeOpenAICompatibleFactory({
|
|
6
|
+
baseURL: 'https://api.moonshot.cn/v1',
|
|
7
|
+
debug: {
|
|
8
|
+
chatCompletion: () => process.env.DEBUG_MOONSHOT_CHAT_COMPLETION === '1',
|
|
9
|
+
},
|
|
10
|
+
errorType: {
|
|
11
|
+
bizError: AgentRuntimeErrorType.MoonshotBizError,
|
|
12
|
+
invalidAPIKey: AgentRuntimeErrorType.InvalidMoonshotAPIKey,
|
|
13
|
+
},
|
|
14
|
+
provider: ModelProvider.Moonshot,
|
|
15
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`LobeOpenAI > models > should get models 1`] = `
|
|
4
|
+
[
|
|
5
|
+
{
|
|
6
|
+
"description": "GPT 3.5 Turbo,适用于各种文本生成和理解任务",
|
|
7
|
+
"displayName": "GPT-3.5 Turbo",
|
|
8
|
+
"enabled": true,
|
|
9
|
+
"functionCall": true,
|
|
10
|
+
"id": "gpt-3.5-turbo",
|
|
11
|
+
"tokens": 16385,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"displayName": "GPT-3.5 Turbo 16K",
|
|
15
|
+
"id": "gpt-3.5-turbo-16k",
|
|
16
|
+
"tokens": 16385,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"displayName": "GPT-3.5 Turbo 16K (0613)",
|
|
20
|
+
"id": "gpt-3.5-turbo-16k-0613",
|
|
21
|
+
"legacy": true,
|
|
22
|
+
"tokens": 4096,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"displayName": "GPT-4 Turbo Vision Preview (1106)",
|
|
26
|
+
"id": "gpt-4-1106-vision-preview",
|
|
27
|
+
"tokens": 128000,
|
|
28
|
+
"vision": true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "gpt-3.5-turbo-instruct-0914",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"displayName": "GPT-4 Turbo Preview (0125)",
|
|
35
|
+
"functionCall": true,
|
|
36
|
+
"id": "gpt-4-0125-preview",
|
|
37
|
+
"tokens": 128000,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"displayName": "GPT-4 Turbo Preview",
|
|
41
|
+
"enabled": true,
|
|
42
|
+
"functionCall": true,
|
|
43
|
+
"id": "gpt-4-turbo-preview",
|
|
44
|
+
"tokens": 128000,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"displayName": "GPT-3.5 Turbo Instruct",
|
|
48
|
+
"id": "gpt-3.5-turbo-instruct",
|
|
49
|
+
"tokens": 4096,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "gpt-3.5-turbo-0301",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"displayName": "GPT-3.5 Turbo (0613)",
|
|
56
|
+
"id": "gpt-3.5-turbo-0613",
|
|
57
|
+
"legacy": true,
|
|
58
|
+
"tokens": 4096,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"displayName": "GPT-3.5 Turbo (1106)",
|
|
62
|
+
"functionCall": true,
|
|
63
|
+
"id": "gpt-3.5-turbo-1106",
|
|
64
|
+
"tokens": 16385,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"displayName": "GPT-4 Turbo Preview (1106)",
|
|
68
|
+
"functionCall": true,
|
|
69
|
+
"id": "gpt-4-1106-preview",
|
|
70
|
+
"tokens": 128000,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"description": "GPT-4 视觉预览版,支持视觉任务",
|
|
74
|
+
"displayName": "GPT-4 Turbo Vision Preview",
|
|
75
|
+
"enabled": true,
|
|
76
|
+
"id": "gpt-4-vision-preview",
|
|
77
|
+
"tokens": 128000,
|
|
78
|
+
"vision": true,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"displayName": "GPT-4",
|
|
82
|
+
"functionCall": true,
|
|
83
|
+
"id": "gpt-4",
|
|
84
|
+
"tokens": 8192,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"displayName": "GPT-3.5 Turbo (0125)",
|
|
88
|
+
"functionCall": true,
|
|
89
|
+
"id": "gpt-3.5-turbo-0125",
|
|
90
|
+
"tokens": 16385,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"displayName": "GPT-4 (0613)",
|
|
94
|
+
"functionCall": true,
|
|
95
|
+
"id": "gpt-4-0613",
|
|
96
|
+
"tokens": 8192,
|
|
97
|
+
},
|
|
98
|
+
]
|
|
99
|
+
`;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "whisper-1",
|
|
4
|
+
"object": "model",
|
|
5
|
+
"created": 1677532384,
|
|
6
|
+
"owned_by": "openai-internal"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"id": "davinci-002",
|
|
10
|
+
"object": "model",
|
|
11
|
+
"created": 1692634301,
|
|
12
|
+
"owned_by": "system"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "gpt-3.5-turbo",
|
|
16
|
+
"object": "model",
|
|
17
|
+
"created": 1677610602,
|
|
18
|
+
"owned_by": "openai"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "dall-e-2",
|
|
22
|
+
"object": "model",
|
|
23
|
+
"created": 1698798177,
|
|
24
|
+
"owned_by": "system"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "gpt-3.5-turbo-16k",
|
|
28
|
+
"object": "model",
|
|
29
|
+
"created": 1683758102,
|
|
30
|
+
"owned_by": "openai-internal"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "tts-1-hd-1106",
|
|
34
|
+
"object": "model",
|
|
35
|
+
"created": 1699053533,
|
|
36
|
+
"owned_by": "system"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "tts-1-hd",
|
|
40
|
+
"object": "model",
|
|
41
|
+
"created": 1699046015,
|
|
42
|
+
"owned_by": "system"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "gpt-3.5-turbo-16k-0613",
|
|
46
|
+
"object": "model",
|
|
47
|
+
"created": 1685474247,
|
|
48
|
+
"owned_by": "openai"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "text-embedding-3-large",
|
|
52
|
+
"object": "model",
|
|
53
|
+
"created": 1705953180,
|
|
54
|
+
"owned_by": "system"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "gpt-4-1106-vision-preview",
|
|
58
|
+
"object": "model",
|
|
59
|
+
"created": 1711473033,
|
|
60
|
+
"owned_by": "system"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "gpt-3.5-turbo-instruct-0914",
|
|
64
|
+
"object": "model",
|
|
65
|
+
"created": 1694122472,
|
|
66
|
+
"owned_by": "system"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": "gpt-4-0125-preview",
|
|
70
|
+
"object": "model",
|
|
71
|
+
"created": 1706037612,
|
|
72
|
+
"owned_by": "system"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "gpt-4-turbo-preview",
|
|
76
|
+
"object": "model",
|
|
77
|
+
"created": 1706037777,
|
|
78
|
+
"owned_by": "system"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "gpt-3.5-turbo-instruct",
|
|
82
|
+
"object": "model",
|
|
83
|
+
"created": 1692901427,
|
|
84
|
+
"owned_by": "system"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"id": "gpt-3.5-turbo-0301",
|
|
88
|
+
"object": "model",
|
|
89
|
+
"created": 1677649963,
|
|
90
|
+
"owned_by": "openai"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "gpt-3.5-turbo-0613",
|
|
94
|
+
"object": "model",
|
|
95
|
+
"created": 1686587434,
|
|
96
|
+
"owned_by": "openai"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"id": "tts-1",
|
|
100
|
+
"object": "model",
|
|
101
|
+
"created": 1681940951,
|
|
102
|
+
"owned_by": "openai-internal"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"id": "dall-e-3",
|
|
106
|
+
"object": "model",
|
|
107
|
+
"created": 1698785189,
|
|
108
|
+
"owned_by": "system"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"id": "gpt-3.5-turbo-1106",
|
|
112
|
+
"object": "model",
|
|
113
|
+
"created": 1698959748,
|
|
114
|
+
"owned_by": "system"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"id": "gpt-4-1106-preview",
|
|
118
|
+
"object": "model",
|
|
119
|
+
"created": 1698957206,
|
|
120
|
+
"owned_by": "system"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"id": "babbage-002",
|
|
124
|
+
"object": "model",
|
|
125
|
+
"created": 1692634615,
|
|
126
|
+
"owned_by": "system"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"id": "tts-1-1106",
|
|
130
|
+
"object": "model",
|
|
131
|
+
"created": 1699053241,
|
|
132
|
+
"owned_by": "system"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"id": "gpt-4-vision-preview",
|
|
136
|
+
"object": "model",
|
|
137
|
+
"created": 1698894917,
|
|
138
|
+
"owned_by": "system"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"id": "text-embedding-3-small",
|
|
142
|
+
"object": "model",
|
|
143
|
+
"created": 1705948997,
|
|
144
|
+
"owned_by": "system"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"id": "gpt-4",
|
|
148
|
+
"object": "model",
|
|
149
|
+
"created": 1687882411,
|
|
150
|
+
"owned_by": "openai"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"id": "text-embedding-ada-002",
|
|
154
|
+
"object": "model",
|
|
155
|
+
"created": 1671217299,
|
|
156
|
+
"owned_by": "openai-internal"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"id": "gpt-3.5-turbo-0125",
|
|
160
|
+
"object": "model",
|
|
161
|
+
"created": 1706048358,
|
|
162
|
+
"owned_by": "system"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "gpt-4-0613",
|
|
166
|
+
"object": "model",
|
|
167
|
+
"created": 1686588896,
|
|
168
|
+
"owned_by": "openai"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
@@ -3,16 +3,17 @@ import OpenAI from 'openai';
|
|
|
3
3
|
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
5
|
// 引入模块以便于对函数进行spy
|
|
6
|
-
import { ChatStreamCallbacks } from '@/libs/agent-runtime';
|
|
6
|
+
import { ChatStreamCallbacks, LobeOpenAICompatibleRuntime } from '@/libs/agent-runtime';
|
|
7
7
|
|
|
8
8
|
import * as debugStreamModule from '../utils/debugStream';
|
|
9
|
+
import officalOpenAIModels from './fixtures/openai-models.json';
|
|
9
10
|
import { LobeOpenAI } from './index';
|
|
10
11
|
|
|
11
12
|
// Mock the console.error to avoid polluting test output
|
|
12
13
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
13
14
|
|
|
14
15
|
describe('LobeOpenAI', () => {
|
|
15
|
-
let instance:
|
|
16
|
+
let instance: LobeOpenAICompatibleRuntime;
|
|
16
17
|
|
|
17
18
|
beforeEach(() => {
|
|
18
19
|
instance = new LobeOpenAI({ apiKey: 'test' });
|
|
@@ -21,60 +22,13 @@ describe('LobeOpenAI', () => {
|
|
|
21
22
|
vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue(
|
|
22
23
|
new ReadableStream() as any,
|
|
23
24
|
);
|
|
25
|
+
vi.spyOn(instance['client'].models, 'list').mockResolvedValue({ data: [] } as any);
|
|
24
26
|
});
|
|
25
27
|
|
|
26
28
|
afterEach(() => {
|
|
27
29
|
vi.clearAllMocks();
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
describe('init', () => {
|
|
31
|
-
it('should correctly initialize with Azure options', () => {
|
|
32
|
-
const baseURL = 'https://abc.com';
|
|
33
|
-
const modelName = 'abc';
|
|
34
|
-
const client = new LobeOpenAI({
|
|
35
|
-
apiKey: 'test',
|
|
36
|
-
useAzure: true,
|
|
37
|
-
baseURL,
|
|
38
|
-
azureOptions: {
|
|
39
|
-
apiVersion: '2023-08-01-preview',
|
|
40
|
-
model: 'abc',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(client.baseURL).toEqual(baseURL + '/openai/deployments/' + modelName);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('initWithAzureOpenAI', () => {
|
|
48
|
-
it('should correctly initialize with Azure options', () => {
|
|
49
|
-
const baseURL = 'https://abc.com';
|
|
50
|
-
const modelName = 'abc';
|
|
51
|
-
const client = LobeOpenAI.initWithAzureOpenAI({
|
|
52
|
-
apiKey: 'test',
|
|
53
|
-
useAzure: true,
|
|
54
|
-
baseURL,
|
|
55
|
-
azureOptions: {
|
|
56
|
-
apiVersion: '2023-08-01-preview',
|
|
57
|
-
model: 'abc',
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(client.baseURL).toEqual(baseURL + '/openai/deployments/' + modelName);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should use default Azure options when not explicitly provided', () => {
|
|
65
|
-
const baseURL = 'https://abc.com';
|
|
66
|
-
|
|
67
|
-
const client = LobeOpenAI.initWithAzureOpenAI({
|
|
68
|
-
apiKey: 'test',
|
|
69
|
-
useAzure: true,
|
|
70
|
-
baseURL,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(client.baseURL).toEqual(baseURL + '/openai/deployments/');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
32
|
describe('chat', () => {
|
|
79
33
|
it('should return a StreamingTextResponse on successful API call', async () => {
|
|
80
34
|
// Arrange
|
|
@@ -330,4 +284,15 @@ describe('LobeOpenAI', () => {
|
|
|
330
284
|
});
|
|
331
285
|
});
|
|
332
286
|
});
|
|
287
|
+
|
|
288
|
+
describe('models', () => {
|
|
289
|
+
it('should get models', async () => {
|
|
290
|
+
// mock the models.list method
|
|
291
|
+
(instance['client'].models.list as Mock).mockResolvedValue({ data: officalOpenAIModels });
|
|
292
|
+
|
|
293
|
+
const list = await instance.models();
|
|
294
|
+
|
|
295
|
+
expect(list).toMatchSnapshot();
|
|
296
|
+
});
|
|
297
|
+
});
|
|
333
298
|
});
|
|
@@ -1,108 +1,16 @@
|
|
|
1
|
-
import { OpenAIStream, StreamingTextResponse } from 'ai';
|
|
2
|
-
import OpenAI, { ClientOptions } from 'openai';
|
|
3
|
-
import urlJoin from 'url-join';
|
|
4
|
-
|
|
5
|
-
import { ChatStreamPayload } from '@/types/openai/chat';
|
|
6
|
-
|
|
7
|
-
import { LobeRuntimeAI } from '../BaseAI';
|
|
8
1
|
import { AgentRuntimeErrorType } from '../error';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class LobeOpenAI implements LobeRuntimeAI {
|
|
26
|
-
private client: OpenAI;
|
|
27
|
-
|
|
28
|
-
constructor(options: LobeOpenAIOptions) {
|
|
29
|
-
if (!options.apiKey) throw AgentRuntimeError.createError(AgentRuntimeErrorType.NoOpenAIAPIKey);
|
|
30
|
-
|
|
31
|
-
if (options.useAzure) {
|
|
32
|
-
this.client = LobeOpenAI.initWithAzureOpenAI(options);
|
|
33
|
-
} else {
|
|
34
|
-
this.client = new OpenAI(options);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.baseURL = this.client.baseURL;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
baseURL: string;
|
|
41
|
-
|
|
42
|
-
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
|
43
|
-
// ============ 1. preprocess messages ============ //
|
|
44
|
-
const { messages, ...params } = payload;
|
|
45
|
-
|
|
46
|
-
// ============ 2. send api ============ //
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const response = await this.client.chat.completions.create(
|
|
50
|
-
{
|
|
51
|
-
messages,
|
|
52
|
-
...params,
|
|
53
|
-
stream: true,
|
|
54
|
-
} as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
|
|
55
|
-
{ headers: { Accept: '*/*' } },
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const [prod, debug] = response.tee();
|
|
59
|
-
|
|
60
|
-
if (process.env.DEBUG_OPENAI_CHAT_COMPLETION === '1') {
|
|
61
|
-
debugStream(debug.toReadableStream()).catch(console.error);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return new StreamingTextResponse(OpenAIStream(prod, options?.callback), {
|
|
65
|
-
headers: options?.headers,
|
|
66
|
-
});
|
|
67
|
-
} catch (error) {
|
|
68
|
-
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
|
69
|
-
|
|
70
|
-
const errorType = RuntimeError || AgentRuntimeErrorType.OpenAIBizError;
|
|
71
|
-
|
|
72
|
-
let desensitizedEndpoint = this.baseURL;
|
|
73
|
-
|
|
74
|
-
// refs: https://github.com/lobehub/lobe-chat/issues/842
|
|
75
|
-
if (this.baseURL !== DEFAULT_BASE_URL) {
|
|
76
|
-
desensitizedEndpoint = desensitizeUrl(this.baseURL);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
throw AgentRuntimeError.chat({
|
|
80
|
-
endpoint: desensitizedEndpoint,
|
|
81
|
-
error: errorResult,
|
|
82
|
-
errorType,
|
|
83
|
-
provider: ModelProvider.OpenAI,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static initWithAzureOpenAI(options: LobeOpenAIOptions) {
|
|
89
|
-
const endpoint = options.baseURL!;
|
|
90
|
-
const model = options.azureOptions?.model || '';
|
|
91
|
-
|
|
92
|
-
// refs: https://test-001.openai.azure.com/openai/deployments/gpt-35-turbo
|
|
93
|
-
const baseURL = urlJoin(endpoint, `/openai/deployments/${model.replace('.', '')}`);
|
|
94
|
-
|
|
95
|
-
const apiVersion = options.azureOptions?.apiVersion || '2023-08-01-preview';
|
|
96
|
-
const apiKey = options.apiKey!;
|
|
97
|
-
|
|
98
|
-
const config: ClientOptions = {
|
|
99
|
-
...options,
|
|
100
|
-
apiKey,
|
|
101
|
-
baseURL,
|
|
102
|
-
defaultHeaders: { 'api-key': apiKey },
|
|
103
|
-
defaultQuery: { 'api-version': apiVersion },
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return new OpenAI(config);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
2
|
+
import { ModelProvider } from '../types';
|
|
3
|
+
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
|
4
|
+
|
|
5
|
+
export const LobeOpenAI = LobeOpenAICompatibleFactory({
|
|
6
|
+
baseURL: 'https://api.openai.com/v1',
|
|
7
|
+
debug: {
|
|
8
|
+
chatCompletion: () => process.env.DEBUG_OPENAI_CHAT_COMPLETION === '1',
|
|
9
|
+
},
|
|
10
|
+
errorType: {
|
|
11
|
+
bizError: AgentRuntimeErrorType.OpenAIBizError,
|
|
12
|
+
invalidAPIKey: AgentRuntimeErrorType.NoOpenAIAPIKey,
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
provider: ModelProvider.OpenAI,
|
|
16
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`LobeOpenRouterAI > models > should get models 1`] = `
|
|
4
|
+
[
|
|
5
|
+
{
|
|
6
|
+
"description": "LLaVA is a large multimodal model that combines a vision encoder and Vicuna for general-purpose visual and language understanding, achieving impressive chat capabilities mimicking [GPT-4](/models/openai/gpt-4-vision-preview) and setting a new state-of-the-art accuracy on Science QA
|
|
7
|
+
|
|
8
|
+
#multimodal",
|
|
9
|
+
"displayName": "Llava 13B",
|
|
10
|
+
"enabled": false,
|
|
11
|
+
"functionCall": false,
|
|
12
|
+
"id": "haotian-liu/llava-13b",
|
|
13
|
+
"maxTokens": undefined,
|
|
14
|
+
"tokens": 2048,
|
|
15
|
+
"vision": true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "This vision-language model builds on innovations from the popular [OpenHermes-2.5](/models/teknium/openhermes-2.5-mistral-7b) model, by Teknium. It adds vision support, and is trained on a custom dataset enriched with function calling
|
|
19
|
+
|
|
20
|
+
This project is led by [qnguyen3](https://twitter.com/stablequan) and [teknium](https://twitter.com/Teknium1).
|
|
21
|
+
|
|
22
|
+
#multimodal",
|
|
23
|
+
"displayName": "Nous: Hermes 2 Vision 7B (alpha)",
|
|
24
|
+
"enabled": false,
|
|
25
|
+
"functionCall": true,
|
|
26
|
+
"id": "nousresearch/nous-hermes-2-vision-7b",
|
|
27
|
+
"maxTokens": undefined,
|
|
28
|
+
"tokens": 4096,
|
|
29
|
+
"vision": true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"description": "GPT-3.5 Turbo is OpenAI's fastest model. It can understand and generate natural language or code, and is optimized for chat and traditional completion tasks.
|
|
33
|
+
|
|
34
|
+
Updated by OpenAI to point to the [latest version of GPT-3.5](/models?q=openai/gpt-3.5). Training data up to Sep 2021.",
|
|
35
|
+
"displayName": "OpenAI: GPT-3.5 Turbo",
|
|
36
|
+
"enabled": true,
|
|
37
|
+
"functionCall": false,
|
|
38
|
+
"id": "openai/gpt-3.5-turbo",
|
|
39
|
+
"maxTokens": 4096,
|
|
40
|
+
"tokens": 16385,
|
|
41
|
+
"vision": false,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"description": "Ability to understand images, in addition to all other [GPT-4 Turbo capabilties](/models/openai/gpt-4-turbo). Training data: up to Apr 2023.
|
|
45
|
+
|
|
46
|
+
**Note:** heavily rate limited by OpenAI while in preview.
|
|
47
|
+
|
|
48
|
+
#multimodal",
|
|
49
|
+
"displayName": "OpenAI: GPT-4 Vision",
|
|
50
|
+
"enabled": true,
|
|
51
|
+
"functionCall": false,
|
|
52
|
+
"id": "openai/gpt-4-vision-preview",
|
|
53
|
+
"maxTokens": 4096,
|
|
54
|
+
"tokens": 128000,
|
|
55
|
+
"vision": true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"description": "Gemma by Google is an advanced, open-source language model family, leveraging the latest in decoder-only, text-to-text technology. It offers English language capabilities across text generation tasks like question answering, summarization, and reasoning. The Gemma 7B variant is comparable in performance to leading open source models.
|
|
59
|
+
|
|
60
|
+
Usage of Gemma is subject to Google's [Gemma Terms of Use](https://ai.google.dev/gemma/terms).",
|
|
61
|
+
"displayName": "Google: Gemma 7B",
|
|
62
|
+
"enabled": true,
|
|
63
|
+
"functionCall": false,
|
|
64
|
+
"id": "google/gemma-7b-it",
|
|
65
|
+
"maxTokens": undefined,
|
|
66
|
+
"tokens": 8192,
|
|
67
|
+
"vision": false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"description": "One of the highest performing and most popular fine-tunes of Llama 2 13B, with rich descriptions and roleplay. #merge
|
|
71
|
+
|
|
72
|
+
Note: this is a higher-throughput version of [this model](/models/gryphe/mythomax-l2-13b), and may have higher prices and slightly different outputs.",
|
|
73
|
+
"displayName": "MythoMax 13B (nitro)",
|
|
74
|
+
"enabled": false,
|
|
75
|
+
"functionCall": false,
|
|
76
|
+
"id": "gryphe/mythomax-l2-13b:nitro",
|
|
77
|
+
"maxTokens": undefined,
|
|
78
|
+
"tokens": 4096,
|
|
79
|
+
"vision": false,
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
`;
|