Skip to content
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

Add content type headers in llm #212

Merged
merged 2 commits into from
Nov 6, 2024
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
8 changes: 8 additions & 0 deletions src/client/api/llm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("llm", () => {
"upstash-forward-authorization": null,
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -77,6 +78,7 @@ describe("llm", () => {
"upstash-forward-helicone-auth": `Bearer ${analyticsToken}`,
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -110,6 +112,7 @@ describe("llm", () => {
"upstash-forward-authorization": `Bearer ${llmToken}`,
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -146,6 +149,7 @@ describe("llm", () => {
"upstash-forward-helicone-target-url": "https://api.openai.com",
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -179,6 +183,7 @@ describe("llm", () => {
"upstash-forward-x-api-key": llmToken,
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -215,6 +220,7 @@ describe("llm", () => {
"upstash-forward-helicone-target-url": "https://api.anthropic.com",
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -248,6 +254,7 @@ describe("llm", () => {
"upstash-forward-authorization": `Bearer ${llmToken}`,
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down Expand Up @@ -284,6 +291,7 @@ describe("llm", () => {
"upstash-forward-helicone-target-url": customBaseUrl,
"upstash-callback": callback,
"upstash-method": "POST",
"content-type": "application/json",
},
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/client/api/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ export class LLMProvider<TOwner extends LLMOwner> extends BaseProvider<"llm", LL
getHeaders(options: LLMOptions): Record<string, string> {
// don't send auth header in upstash
if (this.owner === "upstash" && !options.analytics) {
return {};
return { "content-type": "application/json" };
}

const header = this.owner === "anthropic" ? "x-api-key" : "authorization";
const headerValue = this.owner === "anthropic" ? this.token : `Bearer ${this.token}`;

const headers = { [header]: headerValue };
const headers = {
[header]: headerValue,
"content-type": "application/json",
};

if (this.owner === "openai" && this.organization) {
headers["OpenAI-Organization"] = this.organization;
}
Expand Down
16 changes: 16 additions & 0 deletions src/client/llm/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ describe("Test QStash chat", () => {
callback: "https://example.com",
});
expect(result.messageId).toBeTruthy();

// sleep before checking the message
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await new Promise((r) => setTimeout(r, 3000));

const { events } = await client.events({ filter: { messageId: result.messageId } });
const deliveredEvent = events.find((event) => event.state === "DELIVERED");
expect(deliveredEvent).not.toBeUndefined();
});

test("should batch with llm api", async () => {
Expand Down Expand Up @@ -298,6 +306,14 @@ describe("Test QStash chat with third party LLMs", () => {
callback: "https://oz.requestcatcher.com/",
});
expect(result.messageId).toBeTruthy();

// sleep before checking the message
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await new Promise((r) => setTimeout(r, 3000));

const { events } = await client.events({ filter: { messageId: result.messageId } });
const deliveredEvent = events.find((event) => event.state === "DELIVERED");
expect(deliveredEvent).not.toBeUndefined();
});

test("should publish with llm api", () => {
Expand Down
Loading