Browse Source

Merge pull request #1414 from websentry-ai/pm/add-unbound-metadata

Adds Unbound metadata for non-streaming requests
Chris Estreich 1 year ago
parent
commit
c9e21eb091
2 changed files with 22 additions and 1 deletions
  1. 10 0
      src/api/providers/__tests__/unbound.test.ts
  2. 12 1
      src/api/providers/unbound.ts

+ 10 - 0
src/api/providers/__tests__/unbound.test.ts

@@ -192,6 +192,11 @@ describe("UnboundHandler", () => {
 					temperature: 0,
 					max_tokens: 8192,
 				}),
+				expect.objectContaining({
+					headers: expect.objectContaining({
+						"X-Unbound-Metadata": expect.stringContaining("roo-code"),
+					}),
+				}),
 			)
 		})
 
@@ -233,6 +238,11 @@ describe("UnboundHandler", () => {
 					messages: [{ role: "user", content: "Test prompt" }],
 					temperature: 0,
 				}),
+				expect.objectContaining({
+					headers: expect.objectContaining({
+						"X-Unbound-Metadata": expect.stringContaining("roo-code"),
+					}),
+				}),
 			)
 			expect(mockCreate.mock.calls[0][0]).not.toHaveProperty("max_tokens")
 		})

+ 12 - 1
src/api/providers/unbound.ts

@@ -157,7 +157,18 @@ export class UnboundHandler extends BaseProvider implements SingleCompletionHand
 				requestOptions.max_tokens = this.getModel().info.maxTokens
 			}
 
-			const response = await this.client.chat.completions.create(requestOptions)
+			const response = await this.client.chat.completions.create(requestOptions, {
+				headers: {
+					"X-Unbound-Metadata": JSON.stringify({
+						labels: [
+							{
+								key: "app",
+								value: "roo-code",
+							},
+						],
+					}),
+				},
+			})
 			return response.choices[0]?.message.content || ""
 		} catch (error) {
 			if (error instanceof Error) {