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 support for tags in function calls #62

Merged
merged 1 commit into from
Dec 4, 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
29 changes: 29 additions & 0 deletions examples/example-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
};

export type OpperFunctionSchema = {
Expand Down
Loading