Skip to content

Commit

Permalink
💄 style: Check siliconcloud API-Key Balance (lobehub#5667)
Browse files Browse the repository at this point in the history
* Update siliconcloud.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts
  • Loading branch information
sxjeru authored Feb 2, 2025
1 parent ae39c35 commit 8ab4a30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/config/modelProviders/siliconcloud.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ModelProviderCard } from '@/types/llm';

// ref :https://siliconflow.cn/zh-cn/pricing
// ref: https://siliconflow.cn/zh-cn/pricing
const SiliconCloud: ModelProviderCard = {
chatModels: [
{
Expand Down Expand Up @@ -582,7 +582,7 @@ const SiliconCloud: ModelProviderCard = {
vision: true,
},
],
checkModel: 'Qwen/Qwen2.5-7B-Instruct',
checkModel: 'Pro/Qwen/Qwen2-1.5B-Instruct',
description: 'SiliconCloud,基于优秀开源基础模型的高性价比 GenAI 云服务',
id: 'siliconcloud',
modelList: { showModelFetcher: true },
Expand Down
34 changes: 33 additions & 1 deletion src/libs/agent-runtime/siliconcloud/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ModelProvider } from '../types';
import { AgentRuntimeErrorType } from '../error';
import { ChatCompletionErrorPayload, ModelProvider } from '../types';
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';

import { LOBE_DEFAULT_MODEL_LIST } from '@/config/aiModels';
Expand All @@ -10,6 +11,33 @@ export interface SiliconCloudModelCard {
export const LobeSiliconCloudAI = LobeOpenAICompatibleFactory({
baseURL: 'https://api.siliconflow.cn/v1',
chatCompletion: {
handleError: (error: any): Omit<ChatCompletionErrorPayload, 'provider'> | undefined => {
let errorResponse: Response | undefined;
if (error instanceof Response) {
errorResponse = error;
} else if ('status' in (error as any)) {
errorResponse = error as Response;
}
if (errorResponse) {
if (errorResponse.status === 401) {
return {
error: errorResponse.status,
errorType: AgentRuntimeErrorType.InvalidProviderAPIKey,
};
}

if (errorResponse.status === 403) {
return {
error: errorResponse.status,
errorType: AgentRuntimeErrorType.ProviderBizError,
message: '请检查 API Key 余额是否充足,或者是否在用未实名的 API Key 访问需要实名的模型。',
};
}
}
return {
error,
};
},
handlePayload: (payload) => {
return {
...payload,
Expand All @@ -20,6 +48,10 @@ export const LobeSiliconCloudAI = LobeOpenAICompatibleFactory({
debug: {
chatCompletion: () => process.env.DEBUG_SILICONCLOUD_CHAT_COMPLETION === '1',
},
errorType: {
bizError: AgentRuntimeErrorType.ProviderBizError,
invalidAPIKey: AgentRuntimeErrorType.InvalidProviderAPIKey,
},
models: {
transformModel: (m) => {
const functionCallKeywords = [
Expand Down

0 comments on commit 8ab4a30

Please sign in to comment.