Skip to content

Commit

Permalink
🐛 fix: Avoid baseURL being an empty string, resulting in incorrect cl…
Browse files Browse the repository at this point in the history
…ient fetch (lobehub#3308)
  • Loading branch information
mosade authored Jul 26, 2024
1 parent 4327799 commit 15a9bc1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
private _options: ConstructorOptions<T>;

constructor(options: ClientOptions & Record<string, any> = {}) {
const { apiKey, baseURL = DEFAULT_BASE_URL, ...res } = options;
this._options = options as ConstructorOptions<T>;
const _options = { ...options, baseURL: options.baseURL?.trim() || DEFAULT_BASE_URL };
const { apiKey, baseURL = DEFAULT_BASE_URL, ...res } = _options;
this._options = _options as ConstructorOptions<T>;

if (!apiKey) throw AgentRuntimeError.createError(ErrorType?.invalidAPIKey);

this.client = new OpenAI({ apiKey, baseURL, ...constructorOptions, ...res });
Expand Down
4 changes: 4 additions & 0 deletions src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export function initializeWithClientStore(provider: string, payload: any) {
break;
}
case ModelProvider.Perplexity: {
providerOptions = {
apikey: providerAuthPayload?.apiKey,
baseURL: providerAuthPayload?.endpoint,
};
break;
}
case ModelProvider.Qwen: {
Expand Down

0 comments on commit 15a9bc1

Please sign in to comment.