### Example Data Structure Field Definitions Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/example.md This section details the fields comprising the `Example` data structure. It specifies each field's name, data type, whether it is required, and a brief description. ```APIDOC Example Type Fields: input: Type: any Required: Yes Description: N/A output: Type: any Required: Yes Description: N/A comment: Type: string Required: No Description: N/A ``` -------------------------------- ### Display MCP Server Start Command Help Source: https://github.com/opper-ai/opper-node/blob/main/README.md This command shows the full list of available arguments and options for starting the Opper AI SDK's MCP server. It uses `npx` to execute the `mcp start` command with the `--help` flag, providing detailed usage information. ```sh npx -y --package opperai -- mcp start --help ``` -------------------------------- ### Import and Define Example Type in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/example.md This snippet demonstrates how to import the `Example` type from the `opperai` library and initialize a variable with its structure, showcasing the expected `input` and `output` fields. ```typescript import { Example } from "opperai"; let value: Example = { input: "", output: "", }; ``` -------------------------------- ### TypeScript Example for AppApiPublicV2FunctionsCallFunctionRequest Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/appapipublicv2functionscallfunctionrequest.md Demonstrates how to instantiate and populate an `AppApiPublicV2FunctionsCallFunctionRequest` object in TypeScript. This example illustrates the typical structure for defining function inputs, providing examples, and attaching tags for a function call request. ```typescript import { AppApiPublicV2FunctionsCallFunctionRequest } from "opperai"; let value: AppApiPublicV2FunctionsCallFunctionRequest = { input: { "x": 4, "y": 5, }, examples: [ { input: { "x": 1, "y": 3, }, output: { "sum": 4, }, comment: "Adds two numbers", }, ], tags: { "tag": "value", }, }; ``` -------------------------------- ### Get Trace API Parameters and Response Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/traces/README.md Defines the input parameters and the expected output for the 'Get Trace' API operation. It includes details on required fields, optional configurations, and the structure of the successful response. ```APIDOC Get Trace API: Parameters: traceId: string (Required) - Description: The id of the trace to get options: RequestOptions (Optional) - Description: Used to set various options for making HTTP requests. options.fetchOptions: RequestInit (Optional) - Description: Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. options.retries: RetryConfig (Optional) - Description: Enables retrying HTTP requests under certain failure conditions. Response: Promise ``` -------------------------------- ### Install OpperAI TypeScript SDK Source: https://github.com/opper-ai/opper-node/blob/main/README.md This snippet provides commands to install the OpperAI TypeScript SDK using different JavaScript package managers. It covers npm, pnpm, bun, and yarn, with a specific note for yarn users regarding peer dependencies. ```bash npm add opperai ``` ```bash pnpm add opperai ``` ```bash bun add opperai ``` ```bash yarn add opperai zod # Note that Yarn does not install peer dependencies automatically. You will need # to install zod as shown above. ``` -------------------------------- ### Opper AI Node.js Function Configuration Parameters Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/getfunctionresponse.md This section details the configuration parameters for defining functions within the Opper AI Node.js environment, including how to specify instructions and structure input data using JSON schemas. These parameters guide the model's behavior and validate input. ```APIDOC Opper AI Node.js Function Parameters: instructions: Type: string Required: Yes Description: The prompt that will be sent to the model to complete the task. Recommended to be concise and to the point. Example: "You are a calculator that adds two numbers and returns the result." inputSchema: Type: Record (JSON Schema) Required: No Description: Optional input schema for the function. Can preferably include field descriptions to allow the model to reason about the input variables. Schema is validated against the input data and issues an error if it does not match. With the Opper SDKs you can define these schemas through libraries like Pydantic and Zod. For schemas with definitions, prefer using '$defs' and '#/$defs/...' references. Example: { "properties": { "x": { "title": "X", "type": "integer" }, "y": { "title": "Y", "type": "integer" } }, "required": [ "x", "y" ], "title": "OpperInputExample", "type": "object" } ``` -------------------------------- ### Opper AI SDK Call with Input/Output Schemas and Examples Source: https://github.com/opper-ai/opper-node/blob/main/README.md Illustrates a more complex usage of the `opper.call` method, including defining both input and output JSON schemas, providing input data, and adding examples for better task understanding. It also shows how to pass `parentSpanId` for tracing and `tags` for categorization. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.call({ name: "add_numbers", instructions: "Calculate the sum of two numbers", inputSchema: { "properties": { "x": { "title": "X", "type": "integer" }, "y": { "title": "Y", "type": "integer" } }, "required": [ "x", "y" ], "title": "OpperInputExample", "type": "object" }, outputSchema: { "properties": { "sum": { "title": "Sum", "type": "integer" } }, "required": [ "sum" ], "title": "OpperOutputExample", "type": "object" }, input: { "x": 4, "y": 5 }, examples: [ { input: { "x": 1, "y": 3 }, output: { "sum": 4 }, comment: "Adds two numbers" } ], parentSpanId: "123e4567-e89b-12d3-a456-426614174000", // Pass the id you need tags: { "project": "project_456", "user": "company_123" }, configuration: {} }); console.log(result); } run(); ``` -------------------------------- ### List Traces using Opper SDK Client (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/traces/README.md This TypeScript example demonstrates how to list traces using the main Opper SDK client. It initializes the Opper client with an HTTP bearer token, then calls the `traces.list()` method to fetch and log trace data. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.traces.list(); console.log(result); } run(); ``` -------------------------------- ### Opper-Node API Call Parameters Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/appapipublicv2functioncallcallfunctionrequest.md Describes the optional parameters that can be provided for an Opper-Node API call or data structure, including their types, detailed descriptions, and illustrative example values. These parameters enhance model understanding and tracing capabilities. ```APIDOC Opper-Node API Call Parameters: examples: [models.Example][] (Optional) - Description: Optionally provide examples of successful task completions. Will be added to the prompt to help the model understand the task from examples. - Example Value: [ { "comment": "Adds two numbers", "input": { "x": 1, "y": 3 }, "output": { "sum": 4 } } ] parentSpanId: string (Optional) - Description: Optionally provide the parent span ID to add to the call event. This will automatically tie the call to a parent span in the UI. - Example Value: 123e4567-e89b-12d3-a456-426614174000 ``` -------------------------------- ### Example Usage of ListModelsModelsGetRequest in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/listmodelsmodelsgetrequest.md This snippet demonstrates how to initialize an instance of `ListModelsModelsGetRequest` in TypeScript. It shows a basic instantiation without any parameters, serving as a starting point for making API requests. ```typescript import { ListModelsModelsGetRequest } from "opperai/models/operations"; let value: ListModelsModelsGetRequest = {}; ``` -------------------------------- ### Stream Opper AI Function Call with SDK in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/functions/README.md This TypeScript example demonstrates how to stream a function call using the Opper AI SDK. It initializes the Opper client with an API key and then calls the `functions.stream` method, providing the function ID, input parameters, example data, and optional tags. The example then iterates over the streamed events to process real-time updates. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.functions.stream("e35c595b-59f2-40b8-bc8a-d6f71ebd3c63", { input: { "x": 4, "y": 5, }, examples: [ { input: { "x": 1, "y": 3, }, output: { "sum": 4, }, comment: "Adds two numbers", }, ], tags: { "tag": "value", }, }); for await (const event of result) { // Handle the event console.log(event); } } run(); ``` -------------------------------- ### TypeScript Example Usage of ListFunctionRevisionResponse Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/listfunctionrevisionresponse.md Demonstrates how to instantiate and use the `ListFunctionRevisionResponse` type in TypeScript, showing its structure with example values for `id`, `configuration`, and `createdAt`. ```typescript import { ListFunctionRevisionResponse } from "opperai"; let value: ListFunctionRevisionResponse = { id: "e69ec275-3322-4716-af76-29a77cc33aa1", configuration: { "key": "", "key1": "", "key2": "" }, createdAt: new Date("2024-10-08T02:50:59.242Z") }; ``` -------------------------------- ### Retrieve Span Metrics using Opper AI Client Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/spanmetrics/README.md Demonstrates how to initialize the Opper AI client and fetch a specific span metric using the `spanMetrics.get` method. This example covers basic client setup, authentication, and asynchronous call handling. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.spanMetrics.get("79eccc0e-04d4-4c88-9b48-e9c1fba622be", "f6486ef2-ef7b-4221-8f8f-e12202849ee1"); console.log(result); } run(); ``` -------------------------------- ### Create Function using Opper SDK Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/functions/README.md This TypeScript example demonstrates how to create a new function using the Opper AI SDK. It initializes the SDK with an API key and then calls the `functions.create` method, providing details such as the function's name, description, instructions, and input/output schemas. The example defines a simple function that adds two numbers. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.functions.create({ name: "my-function", description: "This function is used to add two numbers and return the result.", instructions: "You are a calculator that adds two numbers and returns the result.", inputSchema: { "properties": { "x": { "title": "X", "type": "integer", }, "y": { "title": "Y", "type": "integer", }, }, "required": [ "x", "y", ], "title": "OpperInputExample", "type": "object", }, outputSchema: { "properties": { "sum": { "title": "Sum", "type": "integer", }, }, "required": [ "sum", ], "title": "OpperOutputExample", "type": "object", }, configuration: {}, }); console.log(result); } run(); ``` -------------------------------- ### Get Upload URL using Opper SDK (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/knowledge/README.md Demonstrates how to obtain an upload URL for a knowledge base using the main Opper SDK client. This example showcases the asynchronous call to `opper.knowledge.getUploadUrl` and logs the result, initiating the file upload process. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.knowledge.getUploadUrl("70e60583-3f45-4ab8-9a7f-cce7ab08546e", "example.pdf"); console.log(result); } run(); ``` -------------------------------- ### TypeScript Example: Instantiating UpdateSpanMetricResponse Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/updatespanmetricresponse.md This snippet demonstrates how to create an instance of the `UpdateSpanMetricResponse` type in TypeScript, populating its fields with example values. It illustrates the expected structure and data types for this response object. ```typescript import { UpdateSpanMetricResponse } from "opperai"; let value: UpdateSpanMetricResponse = { dimension: "", value: 5618.82, id: "806b7081-e7a4-4171-9d1b-faac2dcd0772", spanId: "17dfd351-45d2-4891-89ef-388e11706ffc", createdAt: new Date("2024-10-21T17:44:25.601Z") }; ``` -------------------------------- ### Example Usage of GetUploadUrlResponse in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/getuploadurlresponse.md Demonstrates how to import and instantiate a `GetUploadUrlResponse` object in TypeScript, populating it with example values for its `url`, `fields`, and `id` properties. ```typescript import { GetUploadUrlResponse } from "opperai"; let value: GetUploadUrlResponse = { url: "https://authorized-cake.name/", fields: {}, id: "7e399f6a-c95e-44d5-a8f9-1fd24a76c94a" }; ``` -------------------------------- ### Instantiate AppApiPublicV2FunctionCallCallFunctionRequest in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/appapipublicv2functioncallcallfunctionrequest.md This TypeScript snippet demonstrates how to create an instance of `AppApiPublicV2FunctionCallCallFunctionRequest`. It illustrates the structure for defining a function call, including its name, instructions, detailed input and output JSON schemas, example inputs and outputs, and optional metadata like `parentSpanId` and `tags`. ```typescript import { AppApiPublicV2FunctionCallCallFunctionRequest } from "opperai"; let value: AppApiPublicV2FunctionCallCallFunctionRequest = { name: "add_numbers", instructions: "Calculate the sum of two numbers", inputSchema: { "properties": { "x": { "title": "X", "type": "integer" }, "y": { "title": "Y", "type": "integer" } }, "required": [ "x", "y" ], "title": "OpperInputExample", "type": "object" }, outputSchema: { "properties": { "sum": { "title": "Sum", "type": "integer" } }, "required": [ "sum" ], "title": "OpperOutputExample", "type": "object" }, input: { "x": 4, "y": 5 }, examples: [ { input: { "x": 1, "y": 3 }, output: { "sum": 4 }, comment: "Adds two numbers" } ], parentSpanId: "123e4567-e89b-12d3-a456-426614174000", tags: { "project": "project_456", "user": "company_123" }, configuration: {} }; ``` -------------------------------- ### TypeScript Example: Instantiating ListFunctionsResponseItem Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/listfunctionsresponseitem.md This snippet demonstrates how to import and instantiate a `ListFunctionsResponseItem` object in TypeScript. It illustrates the typical structure and required fields such as `id`, `name`, and `revisionId` with example values, showing how to create a valid instance of this data type. ```typescript import { ListFunctionsResponseItem } from "opperai"; let value: ListFunctionsResponseItem = { id: "de4d3f01-4815-4bf2-8db1-c7371a2e3679", name: "my-function", revisionId: "8d3f4d1a-320c-4855-ba5b-547a63cb0c82" }; ``` -------------------------------- ### Call Opper AI Function with TypeScript SDK Source: https://github.com/opper-ai/opper-node/blob/main/USAGE.md This snippet illustrates how to initialize the Opper AI SDK and make a function call. It defines an 'add_numbers' function with explicit input and output schemas, provides an example of its usage, and includes optional metadata like 'parentSpanId' and 'tags' for tracing and categorization. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.call({ name: "add_numbers", instructions: "Calculate the sum of two numbers", inputSchema: { "properties": { "x": { "title": "X", "type": "integer" }, "y": { "title": "Y", "type": "integer" } }, "required": [ "x", "y" ], "title": "OpperInputExample", "type": "object" }, outputSchema: { "properties": { "sum": { "title": "Sum", "type": "integer" } }, "required": [ "sum" ], "title": "OpperOutputExample", "type": "object" }, input: { "x": 4, "y": 5 }, examples: [ { input: { "x": 1, "y": 3 }, output: { "sum": 4 }, comment: "Adds two numbers" } ], parentSpanId: "123e4567-e89b-12d3-a456-426614174000", tags: { "project": "project_456", "user": "company_123" }, configuration: {} }); console.log(result); } run(); ``` -------------------------------- ### Call Function Revision using Opper SDK Client (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/functions/README.md This example demonstrates how to initialize the Opper SDK client and use its `functions.callRevision` method to invoke a function. It shows how to pass input data, example inputs/outputs, and tags, and then log the result. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.functions.callRevision("b7391b0d-f115-4145-ae29-a136ae2d6a7a", "de9b5cac-c926-4aa1-a5ab-dc3aa3cd539c", { input: { "x": 4, "y": 5, }, examples: [ { input: { "x": 1, "y": 3, }, output: { "sum": 4, }, comment: "Adds two numbers", }, ], tags: { "tag": "value", }, }); console.log(result); } run(); ``` -------------------------------- ### Stream Opper AI Function Call using Opper SDK Class Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/opper/README.md This TypeScript example demonstrates how to stream the execution of an Opper AI function call using the `Opper` class. It initializes the client, defines input and output schemas, provides example inputs, and iterates over the streamed events to process real-time results. This method is suitable for integrating Opper AI streaming directly into applications using the main SDK client. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.stream({ name: "add_numbers", instructions: "Calculate the sum of two numbers", inputSchema: { "properties": { "x": { "title": "X", "type": "integer", }, "y": { "title": "Y", "type": "integer", }, }, "required": [ "x", "y", ], "title": "OpperInputExample", "type": "object", }, outputSchema: { "properties": { "sum": { "title": "Sum", "type": "integer", }, }, "required": [ "sum", ], "title": "OpperOutputExample", "type": "object", }, input: { "x": 4, "y": 5, }, examples: [ { input: { "x": 1, "y": 3, }, output: { "sum": 4, }, comment: "Adds two numbers", }, ], parentSpanId: "123e4567-e89b-12d3-a456-426614174000", tags: { "project": "project_456", "user": "company_123", }, }); for await (const event of result) { // Handle the event console.log(event); } } run(); ``` -------------------------------- ### TypeScript Example for FunctionCallInput Initialization Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/functioncallinput.md Illustrates how to import and initialize a `FunctionCallInput` object in TypeScript, demonstrating the basic assignment of values to its `arguments` and `name` properties. ```typescript import { FunctionCallInput } from "opperai"; let value: FunctionCallInput = { arguments: "", name: "", }; ``` -------------------------------- ### List Traces using Standalone Function (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/traces/README.md This TypeScript example illustrates how to list traces using a standalone function, which is beneficial for tree-shaking performance. It initializes `OpperCore` and then invokes the `tracesList` function, including error handling for the API response. ```typescript import { OpperCore } from "opperai/core.js"; import { tracesList } from "opperai/funcs/tracesList.js"; // Use `OpperCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const opper = new OpperCore({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const res = await tracesList(opper); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("tracesList failed:", res.error); } } run(); ``` -------------------------------- ### TypeScript Example: Instantiating GetFunctionByRevision Request Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/getfunctionbyrevisionfunctionsfunctionidrevisionsrevisionidgetrequest.md Illustrates how to create an instance of the `GetFunctionByRevisionFunctionsFunctionIdRevisionsRevisionIdGetRequest` type, populating it with example `functionId` and `revisionId` values for a GET request. ```typescript import { GetFunctionByRevisionFunctionsFunctionIdRevisionsRevisionIdGetRequest } from "opperai/models/operations"; let value: GetFunctionByRevisionFunctionsFunctionIdRevisionsRevisionIdGetRequest = { functionId: "de96e053-f718-4678-a1ed-35e3e0197129", revisionId: "8bdc812c-a76a-4cbc-9050-e1f50e762e59", }; ``` -------------------------------- ### Importing and Instantiating ExampleIn in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/examplein.md This snippet demonstrates how to import the `ExampleIn` type from the 'opperai' library and initialize a variable with its structure, providing placeholders for input and output values. ```typescript import { ExampleIn } from "opperai"; let value: ExampleIn = { input: "", output: "" }; ``` -------------------------------- ### Opper AI Traces API: Get Trace by ID Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/traces/README.md Documents the API endpoint for retrieving a specific trace by its ID, including expected response types and potential error conditions. It details the 'get' method within the 'traces' module. ```APIDOC Method: GET /traces/{id} Description: Get a trace by its id Response: Promise Errors: - errors.BadRequestError: Status Code 400, Content Type application/json - errors.UnauthorizedError: Status Code 401, Content Type application/json - errors.NotFoundError: Status Code 404, Content Type application/json - errors.RequestValidationError: Status Code 422, Content Type application/json - errors.APIError: Status Code 4XX, 5XX, Content Type */* ``` -------------------------------- ### Initialize ListLanguageModelsResponse in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/listlanguagemodelsresponse.md Demonstrates how to create and initialize an instance of `ListLanguageModelsResponse` with example data, showing the structure and typical values for its properties. ```typescript import { ListLanguageModelsResponse } from "opperai"; let value: ListLanguageModelsResponse = { hostingProvider: "azure", name: "azure/gpt-4o-eu", location: "us", inputCostPerToken: 0.00015, outputCostPerToken: 0.0006, }; ``` -------------------------------- ### Example JSON Schema for Opper Function Output Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/createfunctionrequest.md This JSON schema defines an example output structure for an Opper function. It specifies an object with a single required property 'sum' of type integer. This schema can be used to validate the function's output data and guide the AI model in generating structured responses. ```JSON { "properties": { "sum": { "title": "Sum", "type": "integer" } }, "required": [ "sum" ], "title": "OpperOutputExample", "type": "object" } ``` -------------------------------- ### Example Usage of ListMetricsSpansSpanIdMetricsGetRequest in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/listmetricsspansspanidmetricsgetrequest.md Demonstrates how to import and instantiate the `ListMetricsSpansSpanIdMetricsGetRequest` object in TypeScript, populating it with a sample `spanId` for making a request. ```typescript import { ListMetricsSpansSpanIdMetricsGetRequest } from "opperai/models/operations"; let value: ListMetricsSpansSpanIdMetricsGetRequest = { spanId: "38af9115-1881-4f9f-b07f-7d55b7b379d3" }; ``` -------------------------------- ### Example Usage: Get Knowledge Base by Name Request in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/getknowledgebasebynameknowledgebynameknowledgebasenamegetrequest.md This snippet demonstrates how to instantiate the `GetKnowledgeBaseByNameKnowledgeByNameKnowledgeBaseNameGetRequest` object in TypeScript, assigning a placeholder value to the `knowledgeBaseName` field. It shows the necessary import statement and object initialization. ```typescript import { GetKnowledgeBaseByNameKnowledgeByNameKnowledgeBaseNameGetRequest } from "opperai/models/operations"; let value: GetKnowledgeBaseByNameKnowledgeByNameKnowledgeBaseNameGetRequest = { knowledgeBaseName: "", }; ``` -------------------------------- ### Download and Configure Standalone MCP Server Binary Source: https://github.com/opper-ai/opper-node/blob/main/README.md This snippet demonstrates how to download a pre-compiled MCP server binary from a GitHub release using `curl` and make it executable. It also provides the JSON configuration for integrating this standalone binary as an MCP server, specifying its execution path and arguments. ```bash curl -L -o mcp-server \ https://github.com/{org}/{repo}/releases/download/{tag}/mcp-server-bun-darwin-arm64 && \ chmod +x mcp-server ``` ```json { "mcpServers": { "Todos": { "command": "./DOWNLOAD/PATH/mcp-server", "args": [ "start" ] } } } ``` -------------------------------- ### Initialize Opper SDK with Custom Server URL and Make a Call Source: https://github.com/opper-ai/opper-node/blob/main/README.md This TypeScript snippet demonstrates how to initialize the Opper SDK client, explicitly overriding the default server URL. It then illustrates making an asynchronous `call` to the SDK with a detailed configuration, including input/output schemas, examples, and metadata tags. ```typescript import { Opper } from "opperai"; const opper = new Opper({ serverURL: "https://api.opper.ai/v2", httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.call({ name: "add_numbers", instructions: "Calculate the sum of two numbers", inputSchema: { "properties": { "x": { "title": "X", "type": "integer" }, "y": { "title": "Y", "type": "integer" } }, "required": [ "x", "y" ], "title": "OpperInputExample", "type": "object" }, outputSchema: { "properties": { "sum": { "title": "Sum", "type": "integer" } }, "required": [ "sum" ], "title": "OpperOutputExample", "type": "object" }, input: { "x": 4, "y": 5 }, examples: [ { input: { "x": 1, "y": 3 }, output: { "sum": 4 }, comment: "Adds two numbers" } ], parentSpanId: "123e4567-e89b-12d3-a456-426614174000", tags: { "project": "project_456", "user": "company_123" }, configuration: {} }); console.log(result); } run(); ``` -------------------------------- ### Create Knowledge Base using Opper SDK Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/knowledge/README.md This TypeScript example demonstrates how to create a new knowledge base using the main Opper AI SDK client. It initializes the client with an API key and then calls the `knowledge.create` method with the desired knowledge base name. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.knowledge.create({ name: "", }); console.log(result); } run(); ``` -------------------------------- ### Instantiating GetDatasetEntry Request Object in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/getdatasetentrydatasetsdatasetidentriesentryidgetrequest.md This TypeScript code demonstrates how to create an instance of the `GetDatasetEntryDatasetsDatasetIdEntriesEntryIdGetRequest` object. It shows the required `datasetId` and `entryId` properties being assigned example string values, preparing the object for use in an API call. ```typescript import { GetDatasetEntryDatasetsDatasetIdEntriesEntryIdGetRequest } from "opperai/models/operations"; let value: GetDatasetEntryDatasetsDatasetIdEntriesEntryIdGetRequest = { datasetId: "5b142d7e-055a-45e9-9b08-5858f089e043", entryId: "50e6f4ca-77e9-47a5-8cfa-46db8d8ac505" }; ``` -------------------------------- ### TypeScript Example for ResponseFormatJSONSchema Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/responseformatjsonschema.md This snippet illustrates how to import and instantiate the `ResponseFormatJSONSchema` type in TypeScript, demonstrating its basic structure with a placeholder `jsonSchema` field. ```typescript import { ResponseFormatJSONSchema } from "opperai"; let value: ResponseFormatJSONSchema = { jsonSchema: { name: "", }, }; ``` -------------------------------- ### Get Upload URL using Standalone Function (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/knowledge/README.md Illustrates how to retrieve an upload URL for a knowledge base using the standalone `knowledgeGetUploadUrl` function, which is recommended for better tree-shaking performance. The example includes error handling for robust application development. ```typescript import { OpperCore } from "opperai/core.js"; import { knowledgeGetUploadUrl } from "opperai/funcs/knowledgeGetUploadUrl.js"; // Use `OpperCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const opper = new OpperCore({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const res = await knowledgeGetUploadUrl(opper, "70e60583-3f45-4ab8-9a7f-cce7ab08546e", "example.pdf"); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("knowledgeGetUploadUrl failed:", res.error); n} } run(); ``` -------------------------------- ### Update Span Metric using Opper Class (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/spanmetrics/README.md Demonstrates how to update a span metric using the `Opper` class instance. This example shows the typical setup for interacting with the Opper API, including client initialization and an asynchronous call to update a specific metric. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.spanMetrics.updateMetric("a6608e7f-16ba-44c7-944b-d024a416ad8b", "e5a732b2-6b58-43f9-ab70-e75a98267516", {}); console.log(result); } run(); ``` -------------------------------- ### List Language Models using Opper SDK (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/languagemodels/README.md Demonstrates how to list all available language models in the Opper platform using the `Opper` client library in TypeScript. It initializes the client with an API key and then calls the `languageModels.list()` method to retrieve and log the results. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.languageModels.list(); console.log(result); } run(); ``` -------------------------------- ### List Opper AI Knowledge Bases (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/knowledge/README.md Demonstrates how to list all knowledge bases for the current project using the Opper AI Node.js client. This snippet provides two approaches: one using the main `Opper` class and another using the tree-shakable `OpperCore` with a standalone function, both illustrating client initialization and asynchronous API calls. ```TypeScript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.knowledge.list(); console.log(result); } run(); ``` ```TypeScript import { OpperCore } from "opperai/core.js"; import { knowledgeList } from "opperai/funcs/knowledgeList.js"; // Use `OpperCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const opper = new OpperCore({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const res = await knowledgeList(opper); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("knowledgeList failed:", res.error); } } run(); ``` -------------------------------- ### Knowledge Base File Upload Process and getUploadUrl Endpoint Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/knowledge/README.md Details the three-step process for uploading files to a knowledge base, starting with obtaining an upload URL via the `GET /v2/knowledge/{knowledge_base_id}/upload_url` endpoint. This endpoint is crucial for initiating the file upload workflow. ```APIDOC Endpoint: GET /v2/knowledge/{knowledge_base_id}/upload_url Description: Get upload URL for a knowledge base by its id. File Upload Process: 1. Get upload URL (GET /v2/knowledge/{knowledge_base_id}/upload_url) 2. Upload file to the URL (using the URL obtained in step 1) 3. Register file (POST /v2/knowledge/{knowledge_base_id}/register_file) ``` -------------------------------- ### Query Opper AI Knowledge Base using Opper Client (TypeScript) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/knowledge/README.md Demonstrates how to query a knowledge base by its ID using the main `Opper` client instance. It shows how to initialize the client with an API key and perform a query with optional filters for price and category. The result is logged to the console. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.knowledge.query("1944d10d-ea53-4b17-ad7e-d92d98c8620e", { query: "What is the capital of France?", filters: [ { field: "price", operation: ">", value: 100, }, { field: "category", operation: "in", value: [ "product", "service", ], }, ], }); console.log(result); } run(); ``` -------------------------------- ### Task Configuration Parameters Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/appapipublicv2functioncallcallfunctionrequest.md Defines the configurable parameters for a task within the Opper AI system, including its unique name and optional instructions for the model. These parameters are crucial for defining how a task is identified and executed. ```APIDOC name: string (required) Description: Provide a unique name of the task. A function with this name will be created in the project. Functions configuration is overridden by the request parameters. Example: add_numbers instructions: string (optional) Description: Optionally provide an instruction for the model to complete the task. Recommended to be concise and to the point. Example: Calculate the sum of two numbers ``` -------------------------------- ### Create OpenAI Chat Completion using Opper SDK (Class-based) Source: https://github.com/opper-ai/opper-node/blob/main/docs/sdks/openai/README.md This TypeScript example demonstrates how to initialize the Opper SDK using the main `Opper` class and then call the `createChatCompletion` method on the `openai` client. It shows a basic usage pattern for generating chat completions, requiring an `OPPER_HTTP_BEARER` environment variable for authentication. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); async function run() { const result = await opper.openai.createChatCompletion({ messages: [], }); console.log(result); } run(); ``` -------------------------------- ### Initialize Opper AI SDK and Extract Room Details Source: https://github.com/opper-ai/opper-node/blob/main/README.md Demonstrates how to initialize the Opper AI SDK and use the `opper.call` method to extract structured data (room details) from a text input. It defines a JSON schema for the expected output, ensuring the extracted data conforms to a predefined structure. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); // Define the output structure (JSON Schema instead of Pydantic) const roomDescriptionSchema = { type: "object", properties: { room_count: { type: "number" }, view: { type: "string" }, bed_size: { type: "string" }, hotel_name: { type: "string" }, }, required: ["room_count", "view", "bed_size", "hotel_name"], }; async function main() { // Complete a task const completion = await opper.call({ name: "extractRoom", instructions: "Extract details about the room from the provided text", input: "The Grand Hotel offers a luxurious suite with 3 spacious rooms, each providing a breathtaking view of the ocean. The suite includes a king-sized bed, an en-suite bathroom, and a private balcony for an unforgettable stay.", outputSchema: roomDescriptionSchema, }); console.log(completion.jsonPayload); // Expected: { room_count: 3, view: 'ocean', bed_size: 'king-sized', hotel_name: 'The Grand Hotel' } } main(); ``` -------------------------------- ### TypeScript InputAudio Type Example Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/inputaudio.md Demonstrates how to declare and initialize an `InputAudio` object in TypeScript, specifying its `data` and `format` properties as required by the type definition. ```typescript import { InputAudio } from "opperai"; let value: InputAudio = { data: "", format: "wav" }; ``` -------------------------------- ### Example Usage of UpdateMetricSpansSpanIdMetricsMetricIdPatchRequest in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/updatemetricspansspanidmetricsmetricidpatchrequest.md Demonstrates how to import and instantiate the `UpdateMetricSpansSpanIdMetricsMetricIdPatchRequest` object, populating its required `spanId` and `metricId` fields with example UUIDs. ```typescript import { UpdateMetricSpansSpanIdMetricsMetricIdPatchRequest } from "opperai/models/operations"; let value: UpdateMetricSpansSpanIdMetricsMetricIdPatchRequest = { spanId: "e987b39d-f263-494e-a919-91046b02e1a6", metricId: "fd1a1dbd-bc97-464a-8dec-2edb491c8a6d", }; ``` -------------------------------- ### Example Usage of FunctionStreamCallStreamPostData in TypeScript Source: https://github.com/opper-ai/opper-node/blob/main/docs/models/operations/functionstreamcallstreampostdata.md Demonstrates how to initialize and use the `FunctionStreamCallStreamPostData` object in TypeScript, providing example values for its `delta` and `spanId` fields. ```typescript import { FunctionStreamCallStreamPostData } from "opperai/models/operations"; let value: FunctionStreamCallStreamCallStreamPostData = { delta: "Hello", spanId: "123e4567-e89b-12d3-a456-426614174000", }; ``` -------------------------------- ### Opper Node.js SDK Development Commands Source: https://github.com/opper-ai/opper-node/blob/main/CLAUDE.md Essential shell commands for building, linting, and preparing the Opper Node.js SDK project. These commands facilitate compilation, code quality checks, and package preparation. ```Shell npm run build npm run build:mcp npm run lint npm run prepublishOnly ``` -------------------------------- ### Authenticate Opper AI SDK with HTTP Bearer Token Source: https://github.com/opper-ai/opper-node/blob/main/README.md Provides a code example demonstrating how to initialize the Opper AI SDK client by passing an `httpBearer` token, typically retrieved from an environment variable, to establish authenticated API calls. ```typescript import { Opper } from "opperai"; const opper = new Opper({ httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", }); ```