Skip to content

Commit 3ab37c7

Browse files
committed
chore: adding x-title header and testing for litellm
1 parent b45252d commit 3ab37c7

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/api/providers/fetchers/__tests__/litellm.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ vi.mock("axios")
44
import type { Mock } from "vitest"
55
import axios from "axios"
66
import { getLiteLLMModels } from "../litellm"
7+
import { DEFAULT_HEADERS } from "../../constants"
78

89
const mockedAxios = axios as typeof axios & {
910
get: Mock
@@ -32,7 +33,10 @@ describe("getLiteLLMModels", () => {
3233
headers: {
3334
Authorization: "Bearer test-api-key",
3435
"Content-Type": "application/json",
36+
...DEFAULT_HEADERS,
37+
3538
},
39+
3640
timeout: 5000,
3741
})
3842
})
@@ -83,6 +87,8 @@ describe("getLiteLLMModels", () => {
8387
headers: {
8488
Authorization: "Bearer test-api-key",
8589
"Content-Type": "application/json",
90+
...DEFAULT_HEADERS,
91+
8692
},
8793
timeout: 5000,
8894
})
@@ -125,6 +131,8 @@ describe("getLiteLLMModels", () => {
125131
expect(mockedAxios.get).toHaveBeenCalledWith("http://localhost:4000/v1/model/info", {
126132
headers: {
127133
"Content-Type": "application/json",
134+
...DEFAULT_HEADERS,
135+
128136
},
129137
timeout: 5000,
130138
})

src/api/providers/fetchers/litellm.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { LITELLM_COMPUTER_USE_MODELS } from "@roo-code/types"
44

55
import type { ModelRecord } from "../../../shared/api"
66

7+
import { DEFAULT_HEADERS } from "../constants"
8+
9+
710
/**
811
* Fetches available models from a LiteLLM server
912
*
@@ -16,6 +19,8 @@ export async function getLiteLLMModels(apiKey: string, baseUrl: string): Promise
1619
try {
1720
const headers: Record<string, string> = {
1821
"Content-Type": "application/json",
22+
...DEFAULT_HEADERS,
23+
1924
}
2025

2126
if (apiKey) {

src/api/providers/router-provider.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { ApiHandlerOptions, RouterName, ModelRecord } from "../../shared/api"
77
import { BaseProvider } from "./base-provider"
88
import { getModels } from "./fetchers/modelCache"
99

10+
import { DEFAULT_HEADERS } from "./constants"
11+
12+
1013
type RouterProviderOptions = {
1114
name: RouterName
1215
baseURL: string
@@ -43,8 +46,14 @@ export abstract class RouterProvider extends BaseProvider {
4346
this.defaultModelId = defaultModelId
4447
this.defaultModelInfo = defaultModelInfo
4548

46-
this.client = new OpenAI({ baseURL, apiKey })
47-
}
49+
this.client = new OpenAI({
50+
baseURL,
51+
apiKey,
52+
defaultHeaders: {
53+
...DEFAULT_HEADERS,
54+
...(options.openAiHeaders || {})
55+
}
56+
}) }
4857

4958
public async fetchModel() {
5059
this.models = await getModels({ provider: this.name, apiKey: this.client.apiKey, baseUrl: this.client.baseURL })

0 commit comments

Comments
 (0)