Skip to content

Commit cc5db32

Browse files
committed
fix: pass gateway retry settings as headers
1 parent b9f7457 commit cc5db32

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

β€Žhandlers/complexity-analysis.test.jsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ function solution() { return 0; }`;
561561
expect(captured).not.toContain("SC: O(1)");
562562
});
563563

564-
it("dalestudy κ²Œμ΄νŠΈμ›¨μ΄μ˜ OpenAI chat/completions 둜 μž¬μ‹œλ„ μ„€μ •κ³Ό ν•¨κ»˜ 보낸닀", async () => {
564+
it("dalestudy κ²Œμ΄νŠΈμ›¨μ΄μ˜ OpenAI chat/completions 둜 μž¬μ‹œλ„ 헀더와 ν•¨κ»˜ 보낸닀", async () => {
565565
globalThis.fetch = vi
566566
.fn()
567567
.mockResolvedValueOnce(
@@ -578,7 +578,11 @@ function solution() { return 0; }`;
578578
expect(request).toMatchObject({
579579
provider: "openai",
580580
endpoint: "chat/completions",
581-
config: { maxAttempts: 3, retryDelay: 1000, backoff: "exponential" },
581+
headers: {
582+
"cf-aig-max-attempts": 3,
583+
"cf-aig-retry-delay": 1000,
584+
"cf-aig-backoff": "exponential",
585+
},
582586
});
583587
// 인증은 바인딩이 ν•˜λ―€λ‘œ κ²Œμ΄νŠΈμ›¨μ΄ 토큰을 μ‹£μ§€ μ•ŠλŠ”λ‹€
584588
expect(request.headers).not.toHaveProperty("cf-aig-authorization");

β€Žutils/openai.jsβ€Ž

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const AI_GATEWAY_ID = "dalestudy";
88

99
// κ²Œμ΄νŠΈμ›¨μ΄μ— μž¬μ‹œλ„λ₯Ό λ§‘κΈ΄λ‹€. Worker μ•ˆμ—μ„œ μž¬μ‹œλ„ν•˜λ©΄ CPU μ˜ˆμ‚°μ„ κΉŽμ§€λ§Œ,
1010
// μ—£μ§€μ—μ„œ μž¬μ‹œλ„ν•˜λ©΄ 응닡을 κΈ°λ‹€λ¦¬λŠ” μ‹œκ°„μΌ 뿐이닀.
11-
const AI_GATEWAY_RETRY_CONFIG = {
12-
maxAttempts: 3,
13-
retryDelay: 1000,
14-
backoff: "exponential",
11+
const AI_GATEWAY_RETRY_HEADERS = {
12+
"cf-aig-max-attempts": 3,
13+
"cf-aig-retry-delay": 1000,
14+
"cf-aig-backoff": "exponential",
1515
};
1616

1717
/**
@@ -25,9 +25,8 @@ export async function createChatCompletion(ai, body) {
2525
const response = await ai.gateway(AI_GATEWAY_ID).run({
2626
provider: "openai",
2727
endpoint: "chat/completions",
28-
headers: { "Content-Type": "application/json" },
28+
headers: { "Content-Type": "application/json", ...AI_GATEWAY_RETRY_HEADERS },
2929
query: body,
30-
config: AI_GATEWAY_RETRY_CONFIG,
3130
});
3231

3332
if (!response.ok) {

0 commit comments

Comments
Β (0)