Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async function main(): Promise<void> {
const advisoryAi = process.env.AI_ADVISORY_BASE_URL
? createOpenAiCompatibleAi({
baseUrl: process.env.AI_ADVISORY_BASE_URL,
apiKey: process.env.AI_ADVISORY_API_KEY ?? process.env.OPENAI_API_KEY,
apiKey: process.env.AI_ADVISORY_API_KEY,
model: process.env.AI_ADVISORY_MODEL,
})
: undefined;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/selfhost-ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ describe("createOpenAiCompatibleAi (#979)", () => {
expect(first?.body.model).toBe("llama3.1");
});

it("only sends an Authorization header when this OpenAI-compatible provider has its own apiKey", async () => {
const authHeaders: Array<string | null> = [];
vi.stubGlobal("fetch", vi.fn(async (_u: string, init?: RequestInit) => {
authHeaders.push(new Headers(init?.headers).get("authorization"));
return new Response(JSON.stringify({ choices: [{ message: { content: "ok" } }] }), { status: 200 });
}));

await createOpenAiCompatibleAi({ baseUrl: "http://advisory.local/v1" }).run("m", { prompt: "x" });
await createOpenAiCompatibleAi({ baseUrl: "http://advisory.local/v1", apiKey: "sk-advisory" }).run("m", { prompt: "x" });

expect(authHeaders).toEqual([null, "Bearer sk-advisory"]);
});

it("forwards providerOptions verbatim as the request's `options` field (#4327/#4335 num_ctx capping)", async () => {
let body: Record<string, unknown> | undefined;
vi.stubGlobal("fetch", vi.fn(async (_u: string, init: { body: string }) => {
Expand Down
Loading