Skip to content

Commit

Permalink
🐛 fix: fix incorrect baseURL for Groq in client mode (lobehub#2747)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosade authored Jun 23, 2024
1 parent fa78599 commit af14225
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/services/__tests__/chat.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
import { act } from '@testing-library/react';
import { merge } from 'lodash-es';
import OpenAI from 'openai';
import { describe, expect, it, vi } from 'vitest';

import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
Expand All @@ -15,6 +16,7 @@ import {
LobeMoonshotAI,
LobeOllamaAI,
LobeOpenAI,
LobeOpenAICompatibleRuntime,
LobeOpenRouterAI,
LobePerplexityAI,
LobeQwenAI,
Expand Down Expand Up @@ -863,19 +865,24 @@ describe('AgentRuntimeOnClient', () => {
expect(runtime['_runtime']).toBeInstanceOf(LobeZeroOneAI);
});

it('Groq provider: with apiKey', async () => {
it('Groq provider: with apiKey,endpoint', async () => {
merge(initialSettingsState, {
settings: {
keyVaults: {
groq: {
apiKey: 'user-groq-key',
baseURL: 'user-groq-endpoint',
},
},
},
} as UserSettingsState) as unknown as UserStore;
const runtime = await initializeWithClientStore(ModelProvider.Groq, {});
expect(runtime).toBeInstanceOf(AgentRuntime);
expect(runtime['_runtime']).toBeInstanceOf(LobeGroq);
const lobeOpenAICompatibleInstance = runtime['_runtime'] as LobeOpenAICompatibleRuntime;
expect(lobeOpenAICompatibleInstance).toBeInstanceOf(LobeGroq);
expect(lobeOpenAICompatibleInstance.baseURL).toBe('user-groq-endpoint');
expect(lobeOpenAICompatibleInstance.client).toBeInstanceOf(OpenAI);
expect(lobeOpenAICompatibleInstance.client.apiKey).toBe('user-groq-key');
});

it('DeepSeek provider: with apiKey', async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export function initializeWithClientStore(provider: string, payload: any) {
break;
}
case ModelProvider.Groq: {
providerOptions = {
apikey: providerAuthPayload?.apiKey,
baseURL: providerAuthPayload?.endpoint,
};
break;
}
case ModelProvider.DeepSeek: {
Expand Down

0 comments on commit af14225

Please sign in to comment.