@lobehub/chat 0.146.2 → 0.147.1
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 +13 -0
- package/docs/self-hosting/advanced/analytics.zh-CN.mdx +11 -0
- package/docs/self-hosting/advanced/authentication.mdx +26 -6
- package/docs/self-hosting/advanced/authentication.zh-CN.mdx +22 -6
- package/docs/self-hosting/advanced/sso-providers/auth0.mdx +76 -33
- package/docs/self-hosting/advanced/sso-providers/auth0.zh-CN.mdx +74 -33
- package/docs/self-hosting/advanced/sso-providers/authentik.mdx +49 -30
- package/docs/self-hosting/advanced/sso-providers/authentik.zh-CN.mdx +43 -28
- package/docs/self-hosting/advanced/sso-providers/github.mdx +62 -20
- package/docs/self-hosting/advanced/sso-providers/github.zh-CN.mdx +70 -34
- package/docs/self-hosting/advanced/sso-providers/microsoft-entra-id.mdx +69 -35
- package/docs/self-hosting/advanced/sso-providers/microsoft-entra-id.zh-CN.mdx +57 -32
- package/docs/self-hosting/advanced/sso-providers/zitadel.mdx +80 -35
- package/docs/self-hosting/advanced/sso-providers/zitadel.zh-CN.mdx +75 -37
- package/docs/self-hosting/advanced/upstream-sync.mdx +45 -23
- package/docs/self-hosting/advanced/upstream-sync.zh-CN.mdx +42 -23
- package/docs/self-hosting/environment-variables/analytics.mdx +16 -0
- package/docs/self-hosting/environment-variables/analytics.zh-CN.mdx +14 -0
- package/docs/self-hosting/environment-variables/auth.mdx +15 -0
- package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +16 -1
- package/docs/self-hosting/environment-variables/basic.mdx +16 -0
- package/docs/self-hosting/environment-variables/basic.zh-CN.mdx +12 -0
- package/docs/self-hosting/environment-variables/model-provider.mdx +27 -0
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +11 -0
- package/docs/self-hosting/environment-variables.mdx +14 -2
- package/docs/self-hosting/environment-variables.zh-CN.mdx +10 -0
- package/docs/self-hosting/examples/azure-openai.mdx +24 -8
- package/docs/self-hosting/examples/azure-openai.zh-CN.mdx +24 -8
- package/docs/self-hosting/examples/ollama.mdx +14 -0
- package/docs/self-hosting/examples/ollama.zh-CN.mdx +12 -0
- package/docs/self-hosting/faq/no-v1-suffix.mdx +13 -0
- package/docs/self-hosting/faq/no-v1-suffix.zh-CN.mdx +10 -0
- package/docs/self-hosting/faq/proxy-with-unable-to-verify-leaf-signature.mdx +15 -0
- package/docs/self-hosting/faq/proxy-with-unable-to-verify-leaf-signature.zh-CN.mdx +12 -0
- package/docs/self-hosting/platform/docker-compose.mdx +103 -80
- package/docs/self-hosting/platform/docker-compose.zh-CN.mdx +92 -73
- package/docs/self-hosting/platform/docker.mdx +107 -89
- package/docs/self-hosting/platform/docker.zh-CN.mdx +106 -89
- package/docs/self-hosting/platform/netlify.mdx +109 -44
- package/docs/self-hosting/platform/netlify.zh-CN.mdx +102 -39
- package/docs/self-hosting/platform/railway.mdx +20 -6
- package/docs/self-hosting/platform/railway.zh-CN.mdx +19 -6
- package/docs/self-hosting/platform/repocloud.mdx +20 -6
- package/docs/self-hosting/platform/repocloud.zh-CN.mdx +18 -6
- package/docs/self-hosting/platform/sealos.mdx +19 -6
- package/docs/self-hosting/platform/sealos.zh-CN.mdx +18 -6
- package/docs/self-hosting/platform/vercel.mdx +21 -7
- package/docs/self-hosting/platform/vercel.zh-CN.mdx +20 -7
- package/docs/self-hosting/platform/zeabur.mdx +19 -6
- package/docs/self-hosting/platform/zeabur.zh-CN.mdx +18 -6
- package/docs/self-hosting/start.mdx +23 -1
- package/docs/self-hosting/start.zh-CN.mdx +15 -1
- package/docs/usage/agents/concepts.mdx +26 -2
- package/docs/usage/agents/concepts.zh-CN.mdx +23 -2
- package/docs/usage/agents/custom-agent.mdx +25 -4
- package/docs/usage/agents/custom-agent.zh-CN.mdx +22 -6
- package/docs/usage/agents/model.mdx +14 -5
- package/docs/usage/agents/model.zh-CN.mdx +18 -5
- package/docs/usage/agents/prompt.mdx +22 -5
- package/docs/usage/agents/prompt.zh-CN.mdx +17 -5
- package/docs/usage/agents/topics.mdx +22 -1
- package/docs/usage/agents/topics.zh-CN.mdx +20 -1
- package/docs/usage/features/agent-market.mdx +16 -6
- package/docs/usage/features/agent-market.zh-CN.mdx +14 -0
- package/docs/usage/features/local-llm.mdx +18 -3
- package/docs/usage/features/local-llm.zh-CN.mdx +9 -4
- package/docs/usage/features/mobile.mdx +15 -2
- package/docs/usage/features/mobile.zh-CN.mdx +17 -1
- package/docs/usage/features/more.mdx +14 -0
- package/docs/usage/features/more.zh-CN.mdx +11 -0
- package/docs/usage/features/multi-ai-providers.mdx +25 -3
- package/docs/usage/features/multi-ai-providers.zh-CN.mdx +28 -2
- package/docs/usage/features/plugin-system.mdx +20 -8
- package/docs/usage/features/plugin-system.zh-CN.mdx +18 -7
- package/docs/usage/features/pwa.mdx +21 -5
- package/docs/usage/features/pwa.zh-CN.mdx +24 -4
- package/docs/usage/features/text-to-image.mdx +11 -1
- package/docs/usage/features/text-to-image.zh-CN.mdx +14 -0
- package/docs/usage/features/theme.mdx +18 -2
- package/docs/usage/features/theme.zh-CN.mdx +18 -1
- package/docs/usage/features/tts.mdx +14 -1
- package/docs/usage/features/tts.zh-CN.mdx +13 -0
- package/docs/usage/features/vision.mdx +11 -1
- package/docs/usage/features/vision.zh-CN.mdx +11 -0
- package/docs/usage/plugins/basic-usage.mdx +43 -7
- package/docs/usage/plugins/basic-usage.zh-CN.mdx +41 -7
- package/docs/usage/plugins/custom-plugin.mdx +13 -0
- package/docs/usage/plugins/custom-plugin.zh-CN.mdx +11 -0
- package/docs/usage/plugins/development.mdx +97 -30
- package/docs/usage/plugins/development.zh-CN.mdx +92 -31
- package/docs/usage/plugins/store.mdx +23 -2
- package/docs/usage/plugins/store.zh-CN.mdx +20 -2
- package/docs/usage/providers/groq.mdx +45 -13
- package/docs/usage/providers/groq.zh-CN.mdx +41 -13
- package/docs/usage/providers/ollama/gemma.mdx +40 -14
- package/docs/usage/providers/ollama/gemma.zh-CN.mdx +40 -14
- package/docs/usage/providers/ollama/qwen.mdx +41 -19
- package/docs/usage/providers/ollama/qwen.zh-CN.mdx +35 -14
- package/docs/usage/providers/ollama.mdx +44 -21
- package/docs/usage/providers/ollama.zh-CN.mdx +45 -21
- 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 +120 -116
- 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/locales/resources.test.ts +49 -0
- package/src/locales/resources.ts +7 -20
- 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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "haotian-liu/llava-13b",
|
|
4
|
+
"name": "Llava 13B",
|
|
5
|
+
"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\n\n#multimodal",
|
|
6
|
+
"pricing": { "prompt": "0.000005", "completion": "0.000005", "image": "0", "request": "0" },
|
|
7
|
+
"context_length": 2048,
|
|
8
|
+
"architecture": { "modality": "multimodal", "tokenizer": "Llama2", "instruct_type": null },
|
|
9
|
+
"top_provider": { "max_completion_tokens": null, "is_moderated": false },
|
|
10
|
+
"per_request_limits": { "prompt_tokens": "891204", "completion_tokens": "891204" }
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "nousresearch/nous-hermes-2-vision-7b",
|
|
14
|
+
"name": "Nous: Hermes 2 Vision 7B (alpha)",
|
|
15
|
+
"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\n\nThis project is led by [qnguyen3](https://twitter.com/stablequan) and [teknium](https://twitter.com/Teknium1).\n\n#multimodal",
|
|
16
|
+
"pricing": { "prompt": "0.000005", "completion": "0.000005", "image": "0", "request": "0" },
|
|
17
|
+
"context_length": 4096,
|
|
18
|
+
"architecture": { "modality": "multimodal", "tokenizer": "Mistral", "instruct_type": null },
|
|
19
|
+
"top_provider": { "max_completion_tokens": null, "is_moderated": false },
|
|
20
|
+
"per_request_limits": { "prompt_tokens": "891204", "completion_tokens": "891204" }
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"id": "openai/gpt-3.5-turbo",
|
|
24
|
+
"name": "OpenAI: GPT-3.5 Turbo",
|
|
25
|
+
"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.\n\nUpdated by OpenAI to point to the [latest version of GPT-3.5](/models?q=openai/gpt-3.5). Training data up to Sep 2021.",
|
|
26
|
+
"pricing": { "prompt": "0.0000005", "completion": "0.0000015", "image": "0", "request": "0" },
|
|
27
|
+
"context_length": 16385,
|
|
28
|
+
"architecture": { "modality": "text", "tokenizer": "GPT", "instruct_type": null },
|
|
29
|
+
"top_provider": { "max_completion_tokens": 4096, "is_moderated": true },
|
|
30
|
+
"per_request_limits": { "prompt_tokens": "8912044", "completion_tokens": "2970681" }
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "openai/gpt-4-vision-preview",
|
|
34
|
+
"name": "OpenAI: GPT-4 Vision",
|
|
35
|
+
"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.\n\n**Note:** heavily rate limited by OpenAI while in preview.\n\n#multimodal",
|
|
36
|
+
"pricing": { "prompt": "0.00001", "completion": "0.00003", "image": "0.01445", "request": "0" },
|
|
37
|
+
"context_length": 128000,
|
|
38
|
+
"architecture": { "modality": "multimodal", "tokenizer": "GPT", "instruct_type": null },
|
|
39
|
+
"top_provider": { "max_completion_tokens": 4096, "is_moderated": true },
|
|
40
|
+
"per_request_limits": { "prompt_tokens": "445602", "completion_tokens": "148534" }
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "google/gemma-7b-it",
|
|
44
|
+
"name": "Google: Gemma 7B",
|
|
45
|
+
"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.\n\nUsage of Gemma is subject to Google's [Gemma Terms of Use](https://ai.google.dev/gemma/terms).",
|
|
46
|
+
"pricing": { "prompt": "0.00000013", "completion": "0.00000013", "image": "0", "request": "0" },
|
|
47
|
+
"context_length": 8192,
|
|
48
|
+
"architecture": { "modality": "text", "tokenizer": "Llama2", "instruct_type": "gemma" },
|
|
49
|
+
"top_provider": { "max_completion_tokens": null, "is_moderated": false },
|
|
50
|
+
"per_request_limits": { "prompt_tokens": "34277093", "completion_tokens": "34277093" }
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "gryphe/mythomax-l2-13b:nitro",
|
|
54
|
+
"name": "MythoMax 13B (nitro)",
|
|
55
|
+
"description": "One of the highest performing and most popular fine-tunes of Llama 2 13B, with rich descriptions and roleplay. #merge\n\nNote: this is a higher-throughput version of [this model](/models/gryphe/mythomax-l2-13b), and may have higher prices and slightly different outputs.",
|
|
56
|
+
"pricing": { "prompt": "0.0000002", "completion": "0.0000002", "image": "0", "request": "0" },
|
|
57
|
+
"context_length": 4096,
|
|
58
|
+
"architecture": { "modality": "text", "tokenizer": "Llama2", "instruct_type": "alpaca" },
|
|
59
|
+
"top_provider": { "max_completion_tokens": null, "is_moderated": false },
|
|
60
|
+
"per_request_limits": { "prompt_tokens": "22280110", "completion_tokens": "22280110" }
|
|
61
|
+
}
|
|
62
|
+
]
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
|
-
import { ChatStreamCallbacks } from '@/libs/agent-runtime';
|
|
5
|
+
import { ChatStreamCallbacks, LobeOpenAICompatibleRuntime } from '@/libs/agent-runtime';
|
|
6
6
|
|
|
7
7
|
import * as debugStreamModule from '../utils/debugStream';
|
|
8
|
+
import models from './fixtures/models.json';
|
|
8
9
|
import { LobeOpenRouterAI } from './index';
|
|
9
10
|
|
|
10
11
|
const provider = 'openrouter';
|
|
@@ -15,7 +16,7 @@ const invalidErrorType = 'InvalidOpenRouterAPIKey';
|
|
|
15
16
|
// Mock the console.error to avoid polluting test output
|
|
16
17
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
18
|
|
|
18
|
-
let instance:
|
|
19
|
+
let instance: LobeOpenAICompatibleRuntime;
|
|
19
20
|
|
|
20
21
|
beforeEach(() => {
|
|
21
22
|
instance = new LobeOpenRouterAI({ apiKey: 'test' });
|
|
@@ -24,6 +25,7 @@ beforeEach(() => {
|
|
|
24
25
|
vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue(
|
|
25
26
|
new ReadableStream() as any,
|
|
26
27
|
);
|
|
28
|
+
vi.spyOn(instance['client'].models, 'list').mockResolvedValue({ data: [] } as any);
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
afterEach(() => {
|
|
@@ -75,13 +77,16 @@ describe('LobeOpenRouterAI', () => {
|
|
|
75
77
|
});
|
|
76
78
|
|
|
77
79
|
// Assert
|
|
78
|
-
expect(instance['client'].chat.completions.create).toHaveBeenCalledWith(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
expect(instance['client'].chat.completions.create).toHaveBeenCalledWith(
|
|
81
|
+
{
|
|
82
|
+
max_tokens: 1024,
|
|
83
|
+
messages: [{ content: 'Hello', role: 'user' }],
|
|
84
|
+
model: 'mistralai/mistral-7b-instruct:free',
|
|
85
|
+
temperature: 0.7,
|
|
86
|
+
top_p: 1,
|
|
87
|
+
},
|
|
88
|
+
{ headers: { Accept: '*/*' } },
|
|
89
|
+
);
|
|
85
90
|
expect(result).toBeInstanceOf(Response);
|
|
86
91
|
});
|
|
87
92
|
|
|
@@ -344,4 +349,15 @@ describe('LobeOpenRouterAI', () => {
|
|
|
344
349
|
});
|
|
345
350
|
});
|
|
346
351
|
});
|
|
352
|
+
|
|
353
|
+
describe('models', () => {
|
|
354
|
+
it('should get models', async () => {
|
|
355
|
+
// mock the models.list method
|
|
356
|
+
(instance['client'].models.list as Mock).mockResolvedValue({ data: models });
|
|
357
|
+
|
|
358
|
+
const list = await instance.models();
|
|
359
|
+
|
|
360
|
+
expect(list).toMatchSnapshot();
|
|
361
|
+
});
|
|
362
|
+
});
|
|
347
363
|
});
|
|
@@ -1,86 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import OpenAI, { ClientOptions } from 'openai';
|
|
1
|
+
import { LOBE_DEFAULT_MODEL_LIST } from '@/config/modelProviders';
|
|
3
2
|
|
|
4
|
-
import { LobeRuntimeAI } from '../BaseAI';
|
|
5
3
|
import { AgentRuntimeErrorType } from '../error';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
} catch (error) {
|
|
49
|
-
let desensitizedEndpoint = this.baseURL;
|
|
50
|
-
|
|
51
|
-
if (this.baseURL !== DEFAULT_BASE_URL) {
|
|
52
|
-
desensitizedEndpoint = desensitizeUrl(this.baseURL);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if ('status' in (error as any)) {
|
|
56
|
-
switch ((error as Response).status) {
|
|
57
|
-
case 401: {
|
|
58
|
-
throw AgentRuntimeError.chat({
|
|
59
|
-
endpoint: desensitizedEndpoint,
|
|
60
|
-
error: error as any,
|
|
61
|
-
errorType: AgentRuntimeErrorType.InvalidOpenRouterAPIKey,
|
|
62
|
-
provider: ModelProvider.OpenRouter,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
default: {
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
|
73
|
-
|
|
74
|
-
const errorType = RuntimeError || AgentRuntimeErrorType.OpenRouterBizError;
|
|
75
|
-
|
|
76
|
-
throw AgentRuntimeError.chat({
|
|
77
|
-
endpoint: desensitizedEndpoint,
|
|
78
|
-
error: errorResult,
|
|
79
|
-
errorType,
|
|
80
|
-
provider: ModelProvider.OpenRouter,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export default LobeOpenRouterAI;
|
|
4
|
+
import { ModelProvider } from '../types';
|
|
5
|
+
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
|
6
|
+
import { OpenRouterModelCard } from './type';
|
|
7
|
+
|
|
8
|
+
export const LobeOpenRouterAI = LobeOpenAICompatibleFactory({
|
|
9
|
+
baseURL: 'https://openrouter.ai/api/v1',
|
|
10
|
+
constructorOptions: {
|
|
11
|
+
defaultHeaders: {
|
|
12
|
+
'HTTP-Referer': 'https://chat-preview.lobehub.com',
|
|
13
|
+
'X-Title': 'Lobe Chat',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
debug: {
|
|
17
|
+
chatCompletion: () => process.env.DEBUG_OPENROUTER_CHAT_COMPLETION === '1',
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
errorType: {
|
|
21
|
+
bizError: AgentRuntimeErrorType.OpenRouterBizError,
|
|
22
|
+
invalidAPIKey: AgentRuntimeErrorType.InvalidOpenRouterAPIKey,
|
|
23
|
+
},
|
|
24
|
+
models: {
|
|
25
|
+
transformModel: (m) => {
|
|
26
|
+
const model = m as unknown as OpenRouterModelCard;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
description: model.description,
|
|
30
|
+
displayName: model.name,
|
|
31
|
+
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.endsWith(m.id))?.enabled || false,
|
|
32
|
+
functionCall: model.description.includes('function calling'),
|
|
33
|
+
id: model.id,
|
|
34
|
+
maxTokens:
|
|
35
|
+
typeof model.top_provider.max_completion_tokens === 'number'
|
|
36
|
+
? model.top_provider.max_completion_tokens
|
|
37
|
+
: undefined,
|
|
38
|
+
tokens: model.context_length,
|
|
39
|
+
vision: model.description.includes('vision') || model.id.includes('vision'),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
provider: ModelProvider.OpenRouter,
|
|
44
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface ModelPricing {
|
|
2
|
+
completion: string;
|
|
3
|
+
image: string;
|
|
4
|
+
prompt: string;
|
|
5
|
+
request: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface ModelArchitecture {
|
|
9
|
+
instruct_type: string | null;
|
|
10
|
+
modality: string;
|
|
11
|
+
tokenizer: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ModelTopProvider {
|
|
15
|
+
is_moderated: boolean;
|
|
16
|
+
max_completion_tokens: number | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface OpenRouterModelCard {
|
|
20
|
+
architecture: ModelArchitecture;
|
|
21
|
+
context_length: number;
|
|
22
|
+
description: string;
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
per_request_limits: any | null;
|
|
26
|
+
pricing: ModelPricing;
|
|
27
|
+
top_provider: ModelTopProvider;
|
|
28
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
|
-
import { ChatStreamCallbacks } from '@/libs/agent-runtime';
|
|
5
|
+
import { ChatStreamCallbacks, LobeOpenAICompatibleRuntime } from '@/libs/agent-runtime';
|
|
6
6
|
|
|
7
7
|
import * as debugStreamModule from '../utils/debugStream';
|
|
8
8
|
import { LobeTogetherAI } from './index';
|
|
@@ -15,7 +15,7 @@ const invalidErrorType = 'InvalidTogetherAIAPIKey';
|
|
|
15
15
|
// Mock the console.error to avoid polluting test output
|
|
16
16
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
17
|
|
|
18
|
-
let instance:
|
|
18
|
+
let instance: LobeOpenAICompatibleRuntime;
|
|
19
19
|
|
|
20
20
|
beforeEach(() => {
|
|
21
21
|
instance = new LobeTogetherAI({ apiKey: 'test' });
|
|
@@ -75,13 +75,16 @@ describe('LobeTogetherAI', () => {
|
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
// Assert
|
|
78
|
-
expect(instance['client'].chat.completions.create).toHaveBeenCalledWith(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
expect(instance['client'].chat.completions.create).toHaveBeenCalledWith(
|
|
79
|
+
{
|
|
80
|
+
max_tokens: 1024,
|
|
81
|
+
messages: [{ content: 'Hello', role: 'user' }],
|
|
82
|
+
model: 'mistralai/mistral-7b-instruct:free',
|
|
83
|
+
temperature: 0.7,
|
|
84
|
+
top_p: 1,
|
|
85
|
+
},
|
|
86
|
+
{ headers: { Accept: '*/*' } },
|
|
87
|
+
);
|
|
85
88
|
expect(result).toBeInstanceOf(Response);
|
|
86
89
|
});
|
|
87
90
|
|
|
@@ -1,86 +1,21 @@
|
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
'HTTP-Referer': 'https://chat-preview.lobehub.com',
|
|
27
|
-
'X-Title': 'Lobe Chat',
|
|
28
|
-
},
|
|
29
|
-
...res,
|
|
30
|
-
});
|
|
31
|
-
this.baseURL = this.client.baseURL;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
|
35
|
-
try {
|
|
36
|
-
const response = await this.client.chat.completions.create(
|
|
37
|
-
payload as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
|
|
38
|
-
);
|
|
39
|
-
const [prod, debug] = response.tee();
|
|
40
|
-
|
|
41
|
-
if (process.env.DEBUG_TOGETHERAI_CHAT_COMPLETION === '1') {
|
|
42
|
-
debugStream(debug.toReadableStream()).catch(console.error);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return new StreamingTextResponse(OpenAIStream(prod, options?.callback), {
|
|
46
|
-
headers: options?.headers,
|
|
47
|
-
});
|
|
48
|
-
} catch (error) {
|
|
49
|
-
let desensitizedEndpoint = this.baseURL;
|
|
50
|
-
|
|
51
|
-
if (this.baseURL !== DEFAULT_BASE_URL) {
|
|
52
|
-
desensitizedEndpoint = desensitizeUrl(this.baseURL);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if ('status' in (error as any)) {
|
|
56
|
-
switch ((error as Response).status) {
|
|
57
|
-
case 401: {
|
|
58
|
-
throw AgentRuntimeError.chat({
|
|
59
|
-
endpoint: desensitizedEndpoint,
|
|
60
|
-
error: error as any,
|
|
61
|
-
errorType: AgentRuntimeErrorType.InvalidTogetherAIAPIKey,
|
|
62
|
-
provider: ModelProvider.TogetherAI,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
default: {
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
|
73
|
-
|
|
74
|
-
const errorType = RuntimeError || AgentRuntimeErrorType.TogetherAIBizError;
|
|
75
|
-
|
|
76
|
-
throw AgentRuntimeError.chat({
|
|
77
|
-
endpoint: desensitizedEndpoint,
|
|
78
|
-
error: errorResult,
|
|
79
|
-
errorType,
|
|
80
|
-
provider: ModelProvider.TogetherAI,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export default LobeTogetherAI;
|
|
2
|
+
import { ModelProvider } from '../types';
|
|
3
|
+
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
|
4
|
+
|
|
5
|
+
export const LobeTogetherAI = LobeOpenAICompatibleFactory({
|
|
6
|
+
baseURL: 'https://api.together.xyz/v1',
|
|
7
|
+
constructorOptions: {
|
|
8
|
+
defaultHeaders: {
|
|
9
|
+
'HTTP-Referer': 'https://chat-preview.lobehub.com',
|
|
10
|
+
'X-Title': 'Lobe Chat',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
debug: {
|
|
14
|
+
chatCompletion: () => process.env.DEBUG_TOGETHERAI_CHAT_COMPLETION === '1',
|
|
15
|
+
},
|
|
16
|
+
errorType: {
|
|
17
|
+
bizError: AgentRuntimeErrorType.TogetherAIBizError,
|
|
18
|
+
invalidAPIKey: AgentRuntimeErrorType.InvalidTogetherAIAPIKey,
|
|
19
|
+
},
|
|
20
|
+
provider: ModelProvider.TogetherAI,
|
|
21
|
+
});
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
buildAnthropicBlock,
|
|
6
|
-
} from './anthropicHelpers';
|
|
7
|
-
|
|
3
|
+
import { OpenAIChatMessage, UserMessageContentPart } from '../types/chat';
|
|
4
|
+
import { buildAnthropicBlock, buildAnthropicMessage } from './anthropicHelpers';
|
|
8
5
|
import { parseDataUri } from './uriParser';
|
|
9
|
-
import {
|
|
10
|
-
OpenAIChatMessage,
|
|
11
|
-
UserMessageContentPart,
|
|
12
|
-
} from '../types/chat';
|
|
13
6
|
|
|
14
7
|
describe('anthropicHelpers', () => {
|
|
15
|
-
|
|
16
8
|
// Mock the parseDataUri function since it's an implementation detail
|
|
17
9
|
vi.mock('./uriParser', () => ({
|
|
18
10
|
parseDataUri: vi.fn().mockReturnValue({
|
|
@@ -23,15 +15,16 @@ describe('anthropicHelpers', () => {
|
|
|
23
15
|
|
|
24
16
|
describe('buildAnthropicBlock', () => {
|
|
25
17
|
it('should return the content as is for text type', () => {
|
|
26
|
-
const content: UserMessageContentPart =
|
|
27
|
-
{ type: 'text', text: 'Hello!' };
|
|
18
|
+
const content: UserMessageContentPart = { type: 'text', text: 'Hello!' };
|
|
28
19
|
const result = buildAnthropicBlock(content);
|
|
29
20
|
expect(result).toEqual(content);
|
|
30
21
|
});
|
|
31
|
-
|
|
22
|
+
|
|
32
23
|
it('should transform an image URL into an Anthropic.ImageBlockParam', () => {
|
|
33
|
-
const content: UserMessageContentPart =
|
|
34
|
-
|
|
24
|
+
const content: UserMessageContentPart = {
|
|
25
|
+
type: 'image_url',
|
|
26
|
+
image_url: { url: 'data:image/jpeg;base64,base64EncodedString' },
|
|
27
|
+
};
|
|
35
28
|
const result = buildAnthropicBlock(content);
|
|
36
29
|
expect(parseDataUri).toHaveBeenCalledWith(content.image_url.url);
|
|
37
30
|
expect(result).toEqual({
|
|
@@ -47,13 +40,12 @@ describe('anthropicHelpers', () => {
|
|
|
47
40
|
|
|
48
41
|
describe('buildAnthropicMessage', () => {
|
|
49
42
|
it('should correctly convert system message to assistant message', () => {
|
|
50
|
-
const message: OpenAIChatMessage =
|
|
51
|
-
|
|
43
|
+
const message: OpenAIChatMessage = {
|
|
44
|
+
content: [{ type: 'text', text: 'Hello!' }],
|
|
45
|
+
role: 'system',
|
|
46
|
+
};
|
|
52
47
|
const result = buildAnthropicMessage(message);
|
|
53
|
-
expect(result).toEqual(
|
|
54
|
-
{ content: [{ type: 'text', text: 'Hello!' }], role: 'assistant' }
|
|
55
|
-
);
|
|
48
|
+
expect(result).toEqual({ content: [{ type: 'text', text: 'Hello!' }], role: 'assistant' });
|
|
56
49
|
});
|
|
57
50
|
});
|
|
58
|
-
|
|
59
|
-
});
|
|
51
|
+
});
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
OpenAIChatMessage,
|
|
5
|
-
UserMessageContentPart,
|
|
6
|
-
} from '../types';
|
|
7
|
-
|
|
3
|
+
import { OpenAIChatMessage, UserMessageContentPart } from '../types';
|
|
8
4
|
import { parseDataUri } from './uriParser';
|
|
9
5
|
|
|
10
6
|
export const buildAnthropicBlock = (
|
|
@@ -28,20 +24,18 @@ export const buildAnthropicBlock = (
|
|
|
28
24
|
};
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
}
|
|
27
|
+
};
|
|
32
28
|
|
|
33
29
|
export const buildAnthropicMessage = (
|
|
34
30
|
message: OpenAIChatMessage,
|
|
35
31
|
): Anthropic.Messages.MessageParam => {
|
|
36
32
|
const content = message.content as string | UserMessageContentPart[];
|
|
37
33
|
return {
|
|
38
|
-
content:
|
|
39
|
-
typeof content === 'string' ? content : content.map((c) => buildAnthropicBlock(c)),
|
|
34
|
+
content: typeof content === 'string' ? content : content.map((c) => buildAnthropicBlock(c)),
|
|
40
35
|
role: message.role === 'function' || message.role === 'system' ? 'assistant' : message.role,
|
|
41
36
|
};
|
|
42
37
|
};
|
|
43
38
|
|
|
44
39
|
export const buildAnthropicMessages = (
|
|
45
40
|
messages: OpenAIChatMessage[],
|
|
46
|
-
): Anthropic.Messages.MessageParam[] =>
|
|
47
|
-
messages.map((message) => buildAnthropicMessage(message));
|
|
41
|
+
): Anthropic.Messages.MessageParam[] => messages.map((message) => buildAnthropicMessage(message));
|