@lobehub/chat 1.21.12 → 1.21.14
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 +50 -0
- package/docs/usage/providers/ai21.mdx +63 -0
- package/docs/usage/providers/ai21.zh-CN.mdx +63 -0
- package/docs/usage/providers/ai360.mdx +63 -0
- package/docs/usage/providers/ai360.zh-CN.mdx +63 -0
- package/docs/usage/providers/fireworksai.mdx +75 -0
- package/docs/usage/providers/fireworksai.zh-CN.mdx +75 -0
- package/docs/usage/providers/github.mdx +92 -0
- package/docs/usage/providers/github.zh-CN.mdx +91 -0
- package/docs/usage/providers/hunyuan.mdx +71 -0
- package/docs/usage/providers/hunyuan.zh-CN.mdx +71 -0
- package/docs/usage/providers/siliconcloud.mdx +37 -21
- package/docs/usage/providers/siliconcloud.zh-CN.mdx +36 -18
- package/docs/usage/providers/spark.mdx +72 -0
- package/docs/usage/providers/spark.zh-CN.mdx +71 -0
- package/docs/usage/providers/upstage.mdx +64 -0
- package/docs/usage/providers/upstage.zh-CN.mdx +64 -0
- package/docs/usage/providers/wenxin.mdx +73 -0
- package/docs/usage/providers/wenxin.zh-CN.mdx +73 -0
- package/docs/usage/providers/{01ai.mdx → zeroone.mdx} +15 -16
- package/package.json +1 -1
- package/src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/index.tsx +5 -0
- package/src/libs/agent-runtime/AgentRuntime.ts +1 -1
- package/src/libs/agent-runtime/google/index.ts +2 -2
- package/src/libs/agent-runtime/utils/streams/anthropic.ts +2 -8
- package/src/libs/agent-runtime/utils/streams/azureOpenai.ts +2 -8
- package/src/libs/agent-runtime/utils/streams/google-ai.ts +1 -12
- package/src/libs/agent-runtime/utils/streams/ollama.ts +2 -8
- package/src/libs/agent-runtime/utils/streams/openai.ts +2 -8
- package/src/libs/agent-runtime/utils/streams/protocol.ts +7 -0
- package/src/libs/agent-runtime/utils/streams/qwen.ts +2 -3
- package/src/libs/agent-runtime/utils/streams/wenxin.test.ts +7 -3
- package/src/libs/agent-runtime/utils/streams/wenxin.ts +0 -8
- package/src/libs/agent-runtime/wenxin/index.ts +3 -2
- package/src/libs/agent-runtime/zhipu/index.test.ts +7 -24
- package/src/libs/agent-runtime/zhipu/index.ts +21 -99
- /package/docs/usage/providers/{01ai.zh-CN.mdx → zeroone.zh-CN.mdx} +0 -0
@@ -1,99 +1,21 @@
|
|
1
|
-
import OpenAI
|
2
|
-
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
constructor(oai: OpenAI) {
|
23
|
-
this.client = oai;
|
24
|
-
this.baseURL = this.client.baseURL;
|
25
|
-
}
|
26
|
-
|
27
|
-
static async fromAPIKey({ apiKey, baseURL = DEFAULT_BASE_URL, ...res }: ClientOptions = {}) {
|
28
|
-
const invalidZhipuAPIKey = AgentRuntimeError.createError(
|
29
|
-
AgentRuntimeErrorType.InvalidProviderAPIKey,
|
30
|
-
);
|
31
|
-
|
32
|
-
if (!apiKey) throw invalidZhipuAPIKey;
|
33
|
-
|
34
|
-
let token: string;
|
35
|
-
|
36
|
-
try {
|
37
|
-
token = await generateApiToken(apiKey);
|
38
|
-
} catch {
|
39
|
-
throw invalidZhipuAPIKey;
|
40
|
-
}
|
41
|
-
|
42
|
-
const header = { Authorization: `Bearer ${token}` };
|
43
|
-
const llm = new OpenAI({ apiKey, baseURL, defaultHeaders: header, ...res });
|
44
|
-
|
45
|
-
return new LobeZhipuAI(llm);
|
46
|
-
}
|
47
|
-
|
48
|
-
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
|
49
|
-
try {
|
50
|
-
const params = await this.buildCompletionsParams(payload);
|
51
|
-
|
52
|
-
const response = await this.client.chat.completions.create(
|
53
|
-
params as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
|
54
|
-
);
|
55
|
-
|
56
|
-
const [prod, debug] = response.tee();
|
57
|
-
|
58
|
-
if (process.env.DEBUG_ZHIPU_CHAT_COMPLETION === '1') {
|
59
|
-
debugStream(debug.toReadableStream()).catch(console.error);
|
60
|
-
}
|
61
|
-
|
62
|
-
return StreamingResponse(OpenAIStream(prod, options?.callback), {
|
63
|
-
headers: options?.headers,
|
64
|
-
});
|
65
|
-
} catch (error) {
|
66
|
-
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
67
|
-
|
68
|
-
const errorType = RuntimeError || AgentRuntimeErrorType.ProviderBizError;
|
69
|
-
let desensitizedEndpoint = this.baseURL;
|
70
|
-
|
71
|
-
if (this.baseURL !== DEFAULT_BASE_URL) {
|
72
|
-
desensitizedEndpoint = desensitizeUrl(this.baseURL);
|
73
|
-
}
|
74
|
-
throw AgentRuntimeError.chat({
|
75
|
-
endpoint: desensitizedEndpoint,
|
76
|
-
error: errorResult,
|
77
|
-
errorType,
|
78
|
-
provider: ModelProvider.ZhiPu,
|
79
|
-
});
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
private async buildCompletionsParams(payload: ChatStreamPayload) {
|
84
|
-
const { messages, temperature, top_p, ...params } = payload;
|
85
|
-
|
86
|
-
return {
|
87
|
-
messages: await convertOpenAIMessages(messages as any),
|
88
|
-
...params,
|
89
|
-
do_sample: temperature === 0,
|
90
|
-
stream: true,
|
91
|
-
// 当前的模型侧不支持 top_p=1 和 temperature 为 0
|
92
|
-
// refs: https://zhipu-ai.feishu.cn/wiki/TUo0w2LT7iswnckmfSEcqTD0ncd
|
93
|
-
temperature: temperature === 0 ? undefined : temperature,
|
94
|
-
top_p: top_p === 1 ? 0.99 : top_p,
|
95
|
-
};
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
export default LobeZhipuAI;
|
1
|
+
import OpenAI from 'openai';
|
2
|
+
|
3
|
+
import { ChatStreamPayload, ModelProvider } from '../types';
|
4
|
+
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
|
5
|
+
|
6
|
+
export const LobeZhipuAI = LobeOpenAICompatibleFactory({
|
7
|
+
baseURL: 'https://open.bigmodel.cn/api/paas/v4',
|
8
|
+
chatCompletion: {
|
9
|
+
handlePayload: ({ temperature, ...payload }: ChatStreamPayload) =>
|
10
|
+
({
|
11
|
+
...payload,
|
12
|
+
do_sample: temperature === 0,
|
13
|
+
stream: true,
|
14
|
+
temperature,
|
15
|
+
}) as OpenAI.ChatCompletionCreateParamsStreaming,
|
16
|
+
},
|
17
|
+
debug: {
|
18
|
+
chatCompletion: () => process.env.DEBUG_ZHIPU_CHAT_COMPLETION === '1',
|
19
|
+
},
|
20
|
+
provider: ModelProvider.ZhiPu,
|
21
|
+
});
|
File without changes
|