MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getOpenAiModels

Function getOpenAiModels

src/api/providers/openai.ts:541–574  ·  view source on GitHub ↗
(baseUrl?: string, apiKey?: string, openAiHeaders?: Record<string, string>)

Source from the content-addressed store, hash-verified

539}
540
541export async function getOpenAiModels(baseUrl?: string, apiKey?: string, openAiHeaders?: Record<string, string>) {
542 try {
543 if (!baseUrl) {
544 return []
545 }
546
547 // Trim whitespace from baseUrl to handle cases where users accidentally include spaces
548 const trimmedBaseUrl = baseUrl.trim()
549
550 if (!URL.canParse(trimmedBaseUrl)) {
551 return []
552 }
553
554 const config: Record<string, any> = {}
555 const headers: Record<string, string> = {
556 ...DEFAULT_HEADERS,
557 ...(openAiHeaders || {}),
558 }
559
560 if (apiKey) {
561 headers["Authorization"] = `Bearer ${apiKey}`
562 }
563
564 if (Object.keys(headers).length > 0) {
565 config["headers"] = headers
566 }
567
568 const response = await axios.get(`${trimmedBaseUrl}/models`, config)
569 const modelsArray = response.data?.data?.map((model: any) => model.id) || []
570 return [...new Set<string>(modelsArray)]
571 } catch (error) {
572 return []
573 }
574}

Callers 2

webviewMessageHandlerFunction · 0.90
openai.spec.tsFile · 0.90

Calls 2

keysMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected