diff --git a/examples/example-calls.ts b/examples/example-calls.ts index 12e188e..cb2730b 100644 --- a/examples/example-calls.ts +++ b/examples/example-calls.ts @@ -138,6 +138,35 @@ const client = new Client(); console.log("Fallback response: ", fallbackMessage); + // Example with tags + const { json_payload: taggedResponse } = await client.call({ + parent_span_uuid: trace.uuid, + name: "node-sdk/call/tags-example", + instructions: "Add two numbers together", + input: { + x: 10, + y: 20 + }, + tags: { + environment: "production", + feature: "arithmetic", + version: "1.0.0", + customer_id: "example-123" + }, + output_schema: { + type: "object", + properties: { + sum: { + type: "number", + description: "The sum of the two numbers" + } + }, + required: ["sum"] + } + }); + + console.log("Tagged response: ", taggedResponse); + await trace.end({ output: "example output", }); diff --git a/src/__tests__/client.test.ts b/src/__tests__/client.test.ts index e848da1..5a8883d 100644 --- a/src/__tests__/client.test.ts +++ b/src/__tests__/client.test.ts @@ -64,6 +64,44 @@ describe("OpperAIClient", () => { chatSpy.mockRestore(); }); + + it("should properly handle tags in function calls", async () => { + const callSpy = jest.spyOn(client.functions, "call").mockResolvedValue({ + message: "test response", + context: {}, + span_id: "test-span-id", + json_payload: { sum: 30 } + }); + + const response = await client.functions.call({ + name: "test-function", + input: { + x: 10, + y: 20 + }, + tags: { + environment: "test", + feature: "arithmetic", + version: "1.0.0" + } + }); + + expect(callSpy).toHaveBeenCalledWith({ + name: "test-function", + input: { + x: 10, + y: 20 + }, + tags: { + environment: "test", + feature: "arithmetic", + version: "1.0.0" + } + }); + + expect(response.json_payload).toEqual({ sum: 30 }); + callSpy.mockRestore(); + }); }); describe("indexes", () => { diff --git a/src/types.ts b/src/types.ts index 59c0752..f42de09 100644 --- a/src/types.ts +++ b/src/types.ts @@ -208,6 +208,12 @@ export type OpperCall = { * Fallback models to use if the primary model fails. */ fallback_models?: string[]; + + /** + * Tags to be associated with the function call. + * These can be used for tracking, filtering, and organizing function calls. + */ + tags?: Record; }; export type OpperFunctionSchema = {