@lobehub/chat 0.133.5 → 0.134.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/CHANGELOG.md +25 -0
- package/locales/ar/setting.json +6 -1
- package/locales/de-DE/setting.json +6 -1
- package/locales/en-US/setting.json +6 -1
- package/locales/es-ES/setting.json +6 -1
- package/locales/fr-FR/setting.json +6 -1
- package/locales/it-IT/setting.json +6 -1
- package/locales/ja-JP/setting.json +6 -1
- package/locales/ko-KR/setting.json +6 -1
- package/locales/nl-NL/setting.json +6 -1
- package/locales/pl-PL/setting.json +6 -1
- package/locales/pt-BR/setting.json +6 -1
- package/locales/ru-RU/setting.json +6 -1
- package/locales/tr-TR/setting.json +6 -1
- package/locales/vi-VN/setting.json +6 -1
- package/locales/zh-CN/setting.json +6 -1
- package/locales/zh-TW/setting.json +6 -1
- package/package.json +1 -1
- package/src/app/api/chat/[provider]/agentRuntime.ts +3 -3
- package/src/app/settings/llm/Anthropic/index.tsx +16 -1
- package/src/config/server/provider.ts +2 -0
- package/src/libs/agent-runtime/anthropic/index.test.ts +21 -2
- package/src/libs/agent-runtime/anthropic/index.ts +17 -3
- package/src/locales/default/setting.ts +5 -0
- package/src/services/_auth.ts +3 -1
- package/src/store/global/slices/settings/selectors/modelProvider.ts +2 -0
- package/src/types/settings/modelProvider.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## [Version 0.134.0](https://github.com/lobehub/lobe-chat/compare/v0.133.5...v0.134.0)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-03-13**</sup>
|
|
8
|
+
|
|
9
|
+
#### ✨ Features
|
|
10
|
+
|
|
11
|
+
- **misc**: Support anthropic proxy url.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's improved
|
|
19
|
+
|
|
20
|
+
- **misc**: Support anthropic proxy url, closes [#1529](https://github.com/lobehub/lobe-chat/issues/1529) ([a5a9257](https://github.com/lobehub/lobe-chat/commit/a5a9257))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.133.5](https://github.com/lobehub/lobe-chat/compare/v0.133.4...v0.133.5)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2024-03-12**</sup>
|
package/locales/ar/setting.json
CHANGED
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "بخلاف العنوان الافتراضي، يجب أن يتضمن http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "عنوان وكيل الواجهة البرمجية للتطبيقات"
|
|
39
|
+
},
|
|
35
40
|
"title": "أنثروبيك",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "أدخل مفتاح API من أنثروبيك",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "أدوات الامتداد"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "Muss die Standardadresse enthalten sowie http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API-Proxy-Adresse"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Geben Sie den API-Schlüssel von Anthropic ein",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Erweiterungswerkzeuge"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "Must include http(s):// besides the default address",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API Proxy Address"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Enter the API Key from Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Extension Tools"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "Debe incluir http(s):// además de la dirección predeterminada",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "Dirección del proxy de la API"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Introduce la clave API de Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Herramientas de extensión"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "En dehors de l'adresse par défaut, doit inclure http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "Adresse de l'API proxy"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Entrez votre clé API Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Outils supplémentaires"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "Deve includere http(s):// oltre all'indirizzo predefinito",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "Indirizzo dell'API proxy"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Inserisci la chiave API di Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Strumenti aggiuntivi"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "デフォルトのアドレスに加えて、http(s)://を含める必要があります",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "APIプロキシアドレス"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Anthropic の API キーを入力してください",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "拡張ツール"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "기본 주소 이외에 http(s)://를 포함해야 합니다",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API 프록시 주소"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Anthropic의 API 키를 입력하세요",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "확장 도구"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "除默认地址外,必须包含 http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API 代理地址"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Voer de API-sleutel van Anthropic in",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Uitbreidingsgereedschap"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "除默认地址外,必须包含 http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API 代理地址"
|
|
39
|
+
},
|
|
35
40
|
"title": "Antropijny",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Wprowadź klucz API z Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Narzędzia rozszerzeń"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "Além do endereço padrão, deve incluir http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "Endereço do Proxy da API"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Insira a chave da API da Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Ferramentas de Extensão"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "除默认地址外,必须包含 http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API 代理地址"
|
|
39
|
+
},
|
|
35
40
|
"title": "Антропный",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Введите ключ API от Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Дополнительные инструменты"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "默认地址以外,必须包含 http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API Proxy Adresi"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Anthropic 的 API 密钥",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Uzantı Araçları"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "Ngoài địa chỉ mặc định, phải bao gồm http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "Địa chỉ Proxy API"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "Nhập API Key từ Anthropic",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "Công cụ mở rộng"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "除默认地址外,必须包含 http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API 代理地址"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "填入来自 Anthropic 的 API Key",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "扩展插件"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"llm": {
|
|
34
34
|
"Anthropic": {
|
|
35
|
+
"endpoint": {
|
|
36
|
+
"desc": "除預設地址外,必須包含 http(s)://",
|
|
37
|
+
"placeholder": "https://api.anthropic.com",
|
|
38
|
+
"title": "API 代理地址"
|
|
39
|
+
},
|
|
35
40
|
"title": "Anthropic",
|
|
36
41
|
"token": {
|
|
37
42
|
"desc": "填入來自 Anthropic 的 API 金鑰",
|
|
@@ -423,4 +428,4 @@
|
|
|
423
428
|
},
|
|
424
429
|
"title": "擴展工具"
|
|
425
430
|
}
|
|
426
|
-
}
|
|
431
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.134.0",
|
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -256,10 +256,10 @@ class AgentRuntime {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
private static initAnthropic(payload: JWTPayload) {
|
|
259
|
-
const { ANTHROPIC_API_KEY } = getServerConfig();
|
|
259
|
+
const { ANTHROPIC_API_KEY, ANTHROPIC_PROXY_URL } = getServerConfig();
|
|
260
260
|
const apiKey = apiKeyManager.pick(payload?.apiKey || ANTHROPIC_API_KEY);
|
|
261
|
-
|
|
262
|
-
return new LobeAnthropicAI({ apiKey });
|
|
261
|
+
const baseURL = payload?.endpoint || ANTHROPIC_PROXY_URL;
|
|
262
|
+
return new LobeAnthropicAI({ apiKey, baseURL });
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
private static initMistral(payload: JWTPayload) {
|
|
@@ -8,7 +8,11 @@ import { ModelProvider } from '@/libs/agent-runtime';
|
|
|
8
8
|
|
|
9
9
|
import Checker from '../components/Checker';
|
|
10
10
|
import ProviderConfig from '../components/ProviderConfig';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
LLMProviderApiTokenKey,
|
|
13
|
+
LLMProviderBaseUrlKey,
|
|
14
|
+
LLMProviderConfigKey
|
|
15
|
+
} from '../const';
|
|
12
16
|
|
|
13
17
|
const providerKey = 'anthropic';
|
|
14
18
|
|
|
@@ -31,6 +35,17 @@ const AnthropicProvider = memo(() => {
|
|
|
31
35
|
label: t('llm.Anthropic.token.title'),
|
|
32
36
|
name: [LLMProviderConfigKey, providerKey, LLMProviderApiTokenKey],
|
|
33
37
|
},
|
|
38
|
+
{
|
|
39
|
+
children: (
|
|
40
|
+
<Input
|
|
41
|
+
allowClear
|
|
42
|
+
placeholder={t('llm.Anthropic.endpoint.placeholder')}
|
|
43
|
+
/>
|
|
44
|
+
),
|
|
45
|
+
desc: t('llm.Anthropic.endpoint.desc'),
|
|
46
|
+
label: t('llm.Anthropic.endpoint.title'),
|
|
47
|
+
name: [LLMProviderConfigKey, providerKey, LLMProviderBaseUrlKey],
|
|
48
|
+
},
|
|
34
49
|
{
|
|
35
50
|
children: <Checker model={'claude-2.1'} provider={ModelProvider.Anthropic} />,
|
|
36
51
|
desc: t('llm.checker.desc'),
|
|
@@ -35,6 +35,7 @@ declare global {
|
|
|
35
35
|
|
|
36
36
|
// Anthropic Provider
|
|
37
37
|
ANTHROPIC_API_KEY?: string;
|
|
38
|
+
ANTHROPIC_PROXY_URL?: string;
|
|
38
39
|
|
|
39
40
|
// Mistral Provider
|
|
40
41
|
MISTRAL_API_KEY?: string;
|
|
@@ -94,6 +95,7 @@ export const getProviderConfig = () => {
|
|
|
94
95
|
|
|
95
96
|
ENABLED_ANTHROPIC: !!ANTHROPIC_API_KEY,
|
|
96
97
|
ANTHROPIC_API_KEY,
|
|
98
|
+
ANTHROPIC_PROXY_URL: process.env.ANTHROPIC_PROXY_URL,
|
|
97
99
|
|
|
98
100
|
ENABLED_MISTRAL: !!MISTRAL_API_KEY,
|
|
99
101
|
MISTRAL_API_KEY,
|
|
@@ -24,10 +24,19 @@ afterEach(() => {
|
|
|
24
24
|
|
|
25
25
|
describe('LobeAnthropicAI', () => {
|
|
26
26
|
describe('init', () => {
|
|
27
|
+
|
|
27
28
|
it('should correctly initialize with an API key', async () => {
|
|
28
29
|
const instance = new LobeAnthropicAI({ apiKey: 'test_api_key' });
|
|
29
30
|
expect(instance).toBeInstanceOf(LobeAnthropicAI);
|
|
31
|
+
expect(instance.baseURL).toBe('https://api.anthropic.com');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should correctly initialize with a baseURL', async () => {
|
|
35
|
+
const instance = new LobeAnthropicAI({ apiKey: 'test_api_key', baseURL: 'https://api.anthropic.proxy' });
|
|
36
|
+
expect(instance).toBeInstanceOf(LobeAnthropicAI);
|
|
37
|
+
expect(instance.baseURL).toBe('https://api.anthropic.proxy');
|
|
30
38
|
});
|
|
39
|
+
|
|
31
40
|
});
|
|
32
41
|
|
|
33
42
|
describe('chat', () => {
|
|
@@ -235,7 +244,12 @@ describe('LobeAnthropicAI', () => {
|
|
|
235
244
|
});
|
|
236
245
|
} catch (e) {
|
|
237
246
|
// Assert
|
|
238
|
-
expect(e).toEqual({
|
|
247
|
+
expect(e).toEqual({
|
|
248
|
+
endpoint: "https://api.anthropic.com",
|
|
249
|
+
error: apiError,
|
|
250
|
+
errorType: 'InvalidAnthropicAPIKey',
|
|
251
|
+
provider
|
|
252
|
+
});
|
|
239
253
|
}
|
|
240
254
|
});
|
|
241
255
|
it('should throw BizError error', async () => {
|
|
@@ -261,7 +275,12 @@ describe('LobeAnthropicAI', () => {
|
|
|
261
275
|
});
|
|
262
276
|
} catch (e) {
|
|
263
277
|
// Assert
|
|
264
|
-
expect(e).toEqual({
|
|
278
|
+
expect(e).toEqual({
|
|
279
|
+
endpoint: "https://api.anthropic.com",
|
|
280
|
+
error: apiError,
|
|
281
|
+
errorType: 'AnthropicBizError',
|
|
282
|
+
provider
|
|
283
|
+
});
|
|
265
284
|
}
|
|
266
285
|
});
|
|
267
286
|
|
|
@@ -15,15 +15,21 @@ import {
|
|
|
15
15
|
} from '../types';
|
|
16
16
|
import { AgentRuntimeError } from '../utils/createError';
|
|
17
17
|
import { debugStream } from '../utils/debugStream';
|
|
18
|
+
import { desensitizeUrl } from '../utils/desensitizeUrl';
|
|
18
19
|
import { parseDataUri } from '../utils/uriParser';
|
|
19
20
|
|
|
21
|
+
const DEFAULT_BASE_URL = 'https://api.anthropic.com';
|
|
22
|
+
|
|
20
23
|
export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
21
24
|
private client: Anthropic;
|
|
25
|
+
|
|
26
|
+
baseURL: string;
|
|
22
27
|
|
|
23
|
-
constructor({ apiKey }: ClientOptions) {
|
|
28
|
+
constructor({ apiKey, baseURL = DEFAULT_BASE_URL }: ClientOptions) {
|
|
24
29
|
if (!apiKey) throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidAnthropicAPIKey);
|
|
25
|
-
|
|
26
|
-
this.client = new Anthropic({ apiKey });
|
|
30
|
+
|
|
31
|
+
this.client = new Anthropic({ apiKey, baseURL });
|
|
32
|
+
this.baseURL = this.client.baseURL;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
private buildAnthropicMessages = (
|
|
@@ -70,10 +76,17 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
|
70
76
|
headers: options?.headers,
|
|
71
77
|
});
|
|
72
78
|
} catch (error) {
|
|
79
|
+
let desensitizedEndpoint = this.baseURL;
|
|
80
|
+
|
|
81
|
+
if (this.baseURL !== DEFAULT_BASE_URL) {
|
|
82
|
+
desensitizedEndpoint = desensitizeUrl(this.baseURL);
|
|
83
|
+
}
|
|
84
|
+
|
|
73
85
|
if ('status' in (error as any)) {
|
|
74
86
|
switch ((error as Response).status) {
|
|
75
87
|
case 401: {
|
|
76
88
|
throw AgentRuntimeError.chat({
|
|
89
|
+
endpoint: desensitizedEndpoint,
|
|
77
90
|
error: error as any,
|
|
78
91
|
errorType: AgentRuntimeErrorType.InvalidAnthropicAPIKey,
|
|
79
92
|
provider: ModelProvider.Anthropic,
|
|
@@ -85,6 +98,7 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
|
85
98
|
}
|
|
86
99
|
}
|
|
87
100
|
throw AgentRuntimeError.chat({
|
|
101
|
+
endpoint: desensitizedEndpoint,
|
|
88
102
|
error: error as any,
|
|
89
103
|
errorType: AgentRuntimeErrorType.AnthropicBizError,
|
|
90
104
|
provider: ModelProvider.Anthropic,
|
package/src/services/_auth.ts
CHANGED
|
@@ -53,7 +53,9 @@ export const getProviderAuthPayload = (provider: string) => {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
case ModelProvider.Anthropic: {
|
|
56
|
-
|
|
56
|
+
const apiKey = modelProviderSelectors.anthropicAPIKey(useGlobalStore.getState());
|
|
57
|
+
const endpoint = modelProviderSelectors.anthropicProxyUrl(useGlobalStore.getState());
|
|
58
|
+
return { apiKey, endpoint };
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
case ModelProvider.Mistral: {
|
|
@@ -59,6 +59,7 @@ const perplexityAPIKey = (s: GlobalStore) => modelProvider(s).perplexity.apiKey;
|
|
|
59
59
|
|
|
60
60
|
const enableAnthropic = (s: GlobalStore) => modelProvider(s).anthropic.enabled;
|
|
61
61
|
const anthropicAPIKey = (s: GlobalStore) => modelProvider(s).anthropic.apiKey;
|
|
62
|
+
const anthropicProxyUrl = (s: GlobalStore) => modelProvider(s).anthropic.endpoint;
|
|
62
63
|
|
|
63
64
|
// const azureModelList = (s: GlobalStore): ModelProviderCard => {
|
|
64
65
|
// const azure = azureConfig(s);
|
|
@@ -226,6 +227,7 @@ export const modelProviderSelectors = {
|
|
|
226
227
|
// Anthropic
|
|
227
228
|
enableAnthropic,
|
|
228
229
|
anthropicAPIKey,
|
|
230
|
+
anthropicProxyUrl,
|
|
229
231
|
|
|
230
232
|
// Mistral
|
|
231
233
|
enableMistral,
|