Skip to content

Commit a854a46

Browse files
authored
Add content type headers in llm (#212)
* fix: add content type headers in llm * fix: update tests to catch llm fails
1 parent 72ffdfd commit a854a46

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/client/api/llm.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe("llm", () => {
4242
"upstash-forward-authorization": null,
4343
"upstash-callback": callback,
4444
"upstash-method": "POST",
45+
"content-type": "application/json",
4546
},
4647
},
4748
});
@@ -77,6 +78,7 @@ describe("llm", () => {
7778
"upstash-forward-helicone-auth": `Bearer ${analyticsToken}`,
7879
"upstash-callback": callback,
7980
"upstash-method": "POST",
81+
"content-type": "application/json",
8082
},
8183
},
8284
});
@@ -110,6 +112,7 @@ describe("llm", () => {
110112
"upstash-forward-authorization": `Bearer ${llmToken}`,
111113
"upstash-callback": callback,
112114
"upstash-method": "POST",
115+
"content-type": "application/json",
113116
},
114117
},
115118
});
@@ -146,6 +149,7 @@ describe("llm", () => {
146149
"upstash-forward-helicone-target-url": "https://api.openai.com",
147150
"upstash-callback": callback,
148151
"upstash-method": "POST",
152+
"content-type": "application/json",
149153
},
150154
},
151155
});
@@ -179,6 +183,7 @@ describe("llm", () => {
179183
"upstash-forward-x-api-key": llmToken,
180184
"upstash-callback": callback,
181185
"upstash-method": "POST",
186+
"content-type": "application/json",
182187
},
183188
},
184189
});
@@ -215,6 +220,7 @@ describe("llm", () => {
215220
"upstash-forward-helicone-target-url": "https://api.anthropic.com",
216221
"upstash-callback": callback,
217222
"upstash-method": "POST",
223+
"content-type": "application/json",
218224
},
219225
},
220226
});
@@ -248,6 +254,7 @@ describe("llm", () => {
248254
"upstash-forward-authorization": `Bearer ${llmToken}`,
249255
"upstash-callback": callback,
250256
"upstash-method": "POST",
257+
"content-type": "application/json",
251258
},
252259
},
253260
});
@@ -284,6 +291,7 @@ describe("llm", () => {
284291
"upstash-forward-helicone-target-url": customBaseUrl,
285292
"upstash-callback": callback,
286293
"upstash-method": "POST",
294+
"content-type": "application/json",
287295
},
288296
},
289297
});

src/client/api/llm.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ export class LLMProvider<TOwner extends LLMOwner> extends BaseProvider<"llm", LL
1818
getHeaders(options: LLMOptions): Record<string, string> {
1919
// don't send auth header in upstash
2020
if (this.owner === "upstash" && !options.analytics) {
21-
return {};
21+
return { "content-type": "application/json" };
2222
}
2323

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

27-
const headers = { [header]: headerValue };
27+
const headers = {
28+
[header]: headerValue,
29+
"content-type": "application/json",
30+
};
31+
2832
if (this.owner === "openai" && this.organization) {
2933
headers["OpenAI-Organization"] = this.organization;
3034
}

src/client/llm/chat.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ describe("Test QStash chat", () => {
132132
callback: "https://example.com",
133133
});
134134
expect(result.messageId).toBeTruthy();
135+
136+
// sleep before checking the message
137+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
138+
await new Promise((r) => setTimeout(r, 3000));
139+
140+
const { events } = await client.events({ filter: { messageId: result.messageId } });
141+
const deliveredEvent = events.find((event) => event.state === "DELIVERED");
142+
expect(deliveredEvent).not.toBeUndefined();
135143
});
136144

137145
test("should batch with llm api", async () => {
@@ -298,6 +306,14 @@ describe("Test QStash chat with third party LLMs", () => {
298306
callback: "https://oz.requestcatcher.com/",
299307
});
300308
expect(result.messageId).toBeTruthy();
309+
310+
// sleep before checking the message
311+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
312+
await new Promise((r) => setTimeout(r, 3000));
313+
314+
const { events } = await client.events({ filter: { messageId: result.messageId } });
315+
const deliveredEvent = events.find((event) => event.state === "DELIVERED");
316+
expect(deliveredEvent).not.toBeUndefined();
301317
});
302318

303319
test("should publish with llm api", () => {

0 commit comments

Comments
 (0)