-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: replace axios with fetch to respect VSCode proxy settings #6994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,5 @@ | ||||||||||||||||||
| import { Anthropic } from "@anthropic-ai/sdk" | ||||||||||||||||||
| import OpenAI, { AzureOpenAI } from "openai" | ||||||||||||||||||
| import axios from "axios" | ||||||||||||||||||
|
|
||||||||||||||||||
| import { | ||||||||||||||||||
| type ModelInfo, | ||||||||||||||||||
|
|
@@ -423,7 +422,6 @@ export async function getOpenAiModels(baseUrl?: string, apiKey?: string, openAiH | |||||||||||||||||
| return [] | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const config: Record<string, any> = {} | ||||||||||||||||||
| const headers: Record<string, string> = { | ||||||||||||||||||
| ...DEFAULT_HEADERS, | ||||||||||||||||||
| ...(openAiHeaders || {}), | ||||||||||||||||||
|
|
@@ -433,12 +431,19 @@ export async function getOpenAiModels(baseUrl?: string, apiKey?: string, openAiH | |||||||||||||||||
| headers["Authorization"] = `Bearer ${apiKey}` | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (Object.keys(headers).length > 0) { | ||||||||||||||||||
| config["headers"] = headers | ||||||||||||||||||
| // Use fetch instead of axios to respect VSCode's proxy settings | ||||||||||||||||||
| // This matches how the OpenAI SDK makes requests internally | ||||||||||||||||||
| const response = await fetch(`${trimmedBaseUrl}/models`, { | ||||||||||||||||||
| method: "GET", | ||||||||||||||||||
| headers: headers, | ||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with the LM Studio implementation, should we include a Content-Type header here? While it's not strictly necessary for GET requests, maintaining consistency across our fetch implementations would be good:
Suggested change
|
||||||||||||||||||
| }) | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||
| return [] | ||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error logging here to help debug issues when model fetching fails. Currently we silently return an empty array for non-ok responses, which might make troubleshooting difficult:
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const response = await axios.get(`${trimmedBaseUrl}/models`, config) | ||||||||||||||||||
| const modelsArray = response.data?.data?.map((model: any) => model.id) || [] | ||||||||||||||||||
| const data = await response.json() | ||||||||||||||||||
| const modelsArray = data?.data?.map((model: any) => model.id) || [] | ||||||||||||||||||
| return [...new Set<string>(modelsArray)] | ||||||||||||||||||
| } catch (error) { | ||||||||||||||||||
| return [] | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpful to add a reference to the issue this fixes for future maintainability?