### Install Dependencies and Build Project with Yarn Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Installs all project dependencies using Yarn and builds the project, outputting files to the 'dist/' directory. This is the initial setup step for the repository. ```shell yarn yarn build ``` -------------------------------- ### Add and Run TypeScript Example Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Demonstrates how to add a new TypeScript example file to the 'examples/' directory and execute it. Requires making the file executable and running it with 'yarn tsn'. ```typescript // add an example to examples/.ts #!/usr/bin/env -S npm run tsn -T … ``` ```shell chmod +x examples/.ts # run the example against your api yarn tsn -T examples/.ts ``` -------------------------------- ### Install SDK from Git Repository Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Installs the Node.js SDK directly from its Git repository using npm. This is an alternative to cloning and linking the repository locally. ```shell npm install git+ssh://git@github.com:withpi/sdk-node.git ``` -------------------------------- ### Mock Server Setup for Testing Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Explains how to set up a mock server using 'prism' to run tests against the OpenAPI specification. This is a prerequisite for executing the test suite. ```shell npx prism mock path/to/your/openapi.yml ``` -------------------------------- ### Publish NPM Package Manually Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Provides instructions for manually publishing the SDK package to npm. This requires setting the 'NPM_TOKEN' environment variable and running a specific script. ```shell bin/publish-npm ``` -------------------------------- ### Run Repository Tests Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Executes the test suite for the Node.js SDK repository. This command assumes the mock server or necessary testing environment is already configured. ```shell yarn run test ``` -------------------------------- ### Link Local SDK Repository with Yarn or pnpm Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Provides instructions for linking a local clone of the SDK repository to a project. This involves cloning the repository, linking it globally, and then linking it within the project's package. ```shell # Clone $ git clone https://www.github.com/withpi/sdk-node $ cd sdk-node # With yarn $ yarn link $ cd ../my-package $ yarn link withpi # With pnpm $ pnpm link --global $ cd ../my-package $ pnpm link -—global withpi ``` -------------------------------- ### Lint and Format Code with Yarn Source: https://github.com/withpi/sdk-node/blob/main/CONTRIBUTING.md Commands to run code linting and formatting using Prettier and ESLint. 'yarn lint' checks for issues, and 'yarn fix' automatically resolves linting problems. ```shell yarn lint yarn fix ``` -------------------------------- ### Install withpi Node.js Library Source: https://github.com/withpi/sdk-node/blob/main/README.md Installs the 'withpi' package using npm, which provides access to the Pi Client REST API. ```sh npm install withpi ``` -------------------------------- ### Installing Runtime Shims with setShims Source: https://github.com/withpi/sdk-node/blob/main/src/_shims/README.md Runtime shims are installed by calling the `setShims` function exported from `withpi/_shims/registry`. Manually importing the node or web shims automatically calls `setShims`. ```typescript import { setShims } from 'withpi/_shims/registry'; // Example: Setting Node.js shims // setShims(nodeShims); ``` -------------------------------- ### Provide Custom Fetch Implementation to PiClient Source: https://github.com/withpi/sdk-node/blob/main/README.md Shows how to instantiate the `PiClient` with a custom `fetch` function. This allows for intercepting, logging, or modifying requests and responses before they are processed by the SDK, using examples like logging with `undici`. ```typescript import { fetch } from 'undici'; // as one example import PiClient from 'withpi'; const client = new PiClient({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { console.log('About to make a request', url, init); const response = await fetch(url, init); console.log('Got response', response); return response; }, }); ``` -------------------------------- ### Automatic Shim Selection in withpi/_shims/index Source: https://github.com/withpi/sdk-node/blob/main/src/_shims/README.md The `withpi/_shims/index` file handles automatic shim selection. It checks for manual shims, otherwise installs shims from `withpi/_shims/auto/runtime` or `withpi/_shims/auto/runtime-node` based on the 'node' export condition. ```typescript // withpi/_shims/index (conceptual) // import { setShims } from './registry'; // import { autoRuntimeShims } from './auto/runtime'; // import { autoRuntimeNodeShims } from './auto/runtime-node'; // if (!shimsAreSetManually) { // if (isNodeEnvironment) { // setShims(autoRuntimeNodeShims); // } else { // setShims(autoRuntimeShims); // } // } // export * from './registry'; ``` -------------------------------- ### Calibrate API Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides endpoints for managing calibration jobs, including retrieving status, listing jobs, canceling jobs, starting new jobs, and streaming messages. ```APIDOC ## GET /scoring_system/calibrate/{job_id} ### Description Retrieves the status of a specific calibration job. ### Method GET ### Endpoint /scoring_system/calibrate/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the calibration job. ### Response #### Success Response (200) - **ScoringSpecCalibrationStatus** - The calibration status object. #### Response Example { "example": "{\"status\": \"completed\", \"progress\": 100}" } ``` ```APIDOC ## GET /scoring_system/calibrate ### Description Lists all calibration jobs with optional filtering parameters. ### Method GET ### Endpoint /scoring_system/calibrate ### Parameters #### Query Parameters - **params** (object) - Optional - Filtering and pagination parameters for the list of jobs. ### Response #### Success Response (200) - **CalibrateListResponse** - A response object containing a list of calibration jobs. #### Response Example { "example": "{\"jobs\": [{\"job_id\": \"job_123\", \"status\": \"running\"}] }" } ``` ```APIDOC ## DELETE /scoring_system/calibrate/{job_id} ### Description Cancels a running calibration job. ### Method DELETE ### Endpoint /scoring_system/calibrate/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the calibration job to cancel. ### Response #### Success Response (200) - **string** - A confirmation message indicating the job has been canceled. #### Response Example { "example": "Calibration job job_123 canceled successfully." } ``` ```APIDOC ## POST /scoring_system/calibrate ### Description Starts a new calibration job with the specified parameters. ### Method POST ### Endpoint /scoring_system/calibrate ### Parameters #### Request Body - **params** (object) - Required - Parameters required to start the calibration job. ### Request Example { "example": "{\"model_id\": \"model_abc\", \"dataset_id\": \"dataset_xyz\"}" } ### Response #### Success Response (200) - **ScoringSpecCalibrationStatus** - The status of the newly created calibration job. #### Response Example { "example": "{\"job_id\": \"job_456\", \"status\": \"pending\"}" } ``` ```APIDOC ## GET /scoring_system/calibrate/{job_id}/messages ### Description Streams messages related to a specific calibration job. ### Method GET ### Endpoint /scoring_system/calibrate/{job_id}/messages ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the calibration job to stream messages from. ### Response #### Success Response (200) - **string** - A stream of messages related to the calibration job. #### Response Example { "example": "Processing data...\nCalibration step 1 completed." } ``` -------------------------------- ### Generate Input Response Pairs API Source: https://github.com/withpi/sdk-node/blob/main/api.md Endpoints for generating and managing input-response pair jobs, including starting, retrieving status, canceling, and streaming data or messages. ```APIDOC ## GET /data/generate_input_response_pairs/{job_id} ### Description Retrieves the status of a generate input-response pairs job. ### Method GET ### Endpoint /data/generate_input_response_pairs/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job to retrieve. ### Response #### Success Response (200) - **SyntheticDataStatus** (object) - The status of the job. #### Response Example { "status": "completed", "progress": 100, "job_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ```APIDOC ## GET /data/generate_input_response_pairs ### Description Lists generate input-response pairs jobs with optional filtering parameters. ### Method GET ### Endpoint /data/generate_input_response_pairs ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of jobs to return. - **offset** (integer) - Optional - The number of jobs to skip. - **status** (string) - Optional - Filters jobs by their status. ### Response #### Success Response (200) - **GenerateInputResponsePairListResponse** (object) - A list of jobs. #### Response Example { "jobs": [ { "job_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "status": "completed", "created_at": "2023-01-02T11:00:00Z" } ], "total": 1 } ``` ```APIDOC ## DELETE /data/generate_input_response_pairs/{job_id} ### Description Cancels a running generate input-response pairs job. ### Method DELETE ### Endpoint /data/generate_input_response_pairs/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job to cancel. ### Response #### Success Response (200) - **string** - A confirmation message. #### Response Example "Job a1b2c3d4-e5f6-7890-1234-567890abcdef canceled successfully." ``` ```APIDOC ## POST /data/generate_input_response_pairs ### Description Starts a new generate input-response pairs job. ### Method POST ### Endpoint /data/generate_input_response_pairs ### Parameters #### Request Body - **input_schema** (object) - Required - The schema for the input. - **response_schema** (object) - Required - The schema for the response. - **num_pairs** (integer) - Required - The number of input-response pairs to generate. ### Request Example { "input_schema": {"type": "string"}, "response_schema": {"type": "integer"}, "num_pairs": 50 } ### Response #### Success Response (200) - **SyntheticDataStatus** (object) - The status of the newly created job. #### Response Example { "status": "pending", "progress": 0, "job_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ```APIDOC ## GET /data/generate_input_response_pairs/{job_id}/data ### Description Streams the generated input-response pairs data for a specific job. ### Method GET ### Endpoint /data/generate_input_response_pairs/{job_id}/data ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job whose data to stream. ### Response #### Success Response (200) - **GenerateInputResponsePairStreamDataResponse** (object) - The stream of generated pairs. #### Response Example { "input": "Sample input text", "response": 123 } ``` ```APIDOC ## GET /data/generate_input_response_pairs/{job_id}/messages ### Description Streams the messages or logs associated with a generate input-response pairs job. ### Method GET ### Endpoint /data/generate_input_response_pairs/{job_id}/messages ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job whose messages to stream. ### Response #### Success Response (200) - **string** - The stream of messages for the job. #### Response Example "INFO: Input-response pair generation started." ``` -------------------------------- ### Generate API Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides endpoints for managing generation jobs, including retrieving status, listing jobs, canceling jobs, starting new jobs, and streaming messages. ```APIDOC ## GET /scoring_system/generate/{job_id} ### Description Retrieves the status of a specific generation job. ### Method GET ### Endpoint /scoring_system/generate/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the generation job. ### Response #### Success Response (200) - **GenerateRetrieveResponse** - The generation job status object. #### Response Example { "example": "{\"status\": \"completed\", \"result_url\": \"http://example.com/result.txt\"}" } ``` ```APIDOC ## GET /scoring_system/generate ### Description Lists all generation jobs with optional filtering parameters. ### Method GET ### Endpoint /scoring_system/generate ### Parameters #### Query Parameters - **params** (object) - Optional - Filtering and pagination parameters for the list of jobs. ### Response #### Success Response (200) - **GenerateListResponse** - A response object containing a list of generation jobs. #### Response Example { "example": "{\"jobs\": [{\"job_id\": \"gen_job_1\", \"status\": \"pending\"}] }" } ``` ```APIDOC ## DELETE /scoring_system/generate/{job_id} ### Description Cancels a running generation job. ### Method DELETE ### Endpoint /scoring_system/generate/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the generation job to cancel. ### Response #### Success Response (200) - **string** - A confirmation message indicating the job has been canceled. #### Response Example { "example": "Generation job gen_job_1 canceled successfully." } ``` ```APIDOC ## POST /scoring_system/generate ### Description Starts a new generation job with the specified parameters. ### Method POST ### Endpoint /scoring_system/generate ### Parameters #### Request Body - **params** (object) - Required - Parameters required to start the generation job. ### Request Example { "example": "{\"prompt\": \"Generate a story about a robot.\", \"max_tokens\": 100}" } ### Response #### Success Response (200) - **GenerateStartJobResponse** - The status of the newly created generation job. #### Response Example { "example": "{\"job_id\": \"gen_job_2\", \"status\": \"running\"}" } ``` ```APIDOC ## GET /scoring_system/generate/{job_id}/messages ### Description Streams messages related to a specific generation job. ### Method GET ### Endpoint /scoring_system/generate/{job_id}/messages ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the generation job to stream messages from. ### Response #### Success Response (200) - **string** - A stream of messages related to the generation job. #### Response Example { "example": "Generating text...\nProgress: 50%." } ``` -------------------------------- ### Data Generation API Source: https://github.com/withpi/sdk-node/blob/main/api.md Endpoints for generating and managing synthetic data jobs, including starting, retrieving status, canceling, and streaming data or messages. ```APIDOC ## GET /data/generate/{job_id} ### Description Retrieves the status of a data generation job. ### Method GET ### Endpoint /data/generate/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job to retrieve. ### Response #### Success Response (200) - **DataGenerationStatus** (object) - The status of the data generation job. #### Response Example { "status": "completed", "progress": 100, "job_id": "123e4567-e89b-12d3-a456-426614174000" } ``` ```APIDOC ## GET /data/generate ### Description Lists data generation jobs with optional filtering parameters. ### Method GET ### Endpoint /data/generate ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of jobs to return. - **offset** (integer) - Optional - The number of jobs to skip. - **status** (string) - Optional - Filters jobs by their status (e.g., 'pending', 'running', 'completed', 'failed'). ### Response #### Success Response (200) - **GenerateListResponse** (object) - A list of data generation jobs. #### Response Example { "jobs": [ { "job_id": "123e4567-e89b-12d3-a456-426614174000", "status": "completed", "created_at": "2023-01-01T10:00:00Z" } ], "total": 1 } ``` ```APIDOC ## DELETE /data/generate/{job_id} ### Description Cancels a running data generation job. ### Method DELETE ### Endpoint /data/generate/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job to cancel. ### Response #### Success Response (200) - **string** - A confirmation message indicating the job has been canceled. #### Response Example "Job 123e4567-e89b-12d3-a456-426614174000 canceled successfully." ``` ```APIDOC ## POST /data/generate ### Description Starts a new data generation job. ### Method POST ### Endpoint /data/generate ### Parameters #### Request Body - **schema** (object) - Required - The schema for the data generation. - **num_rows** (integer) - Required - The number of rows to generate. - **calibration_spec** (object) - Optional - Calibration specifications for the data generation. ### Request Example { "schema": { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"} } }, "num_rows": 100, "calibration_spec": { "mean": 50, "stddev": 10 } } ### Response #### Success Response (200) - **DataGenerationStatus** (object) - The status of the newly created data generation job. #### Response Example { "status": "pending", "progress": 0, "job_id": "123e4567-e89b-12d3-a456-426614174000" } ``` ```APIDOC ## GET /data/generate/{job_id}/data ### Description Streams the generated data for a specific job. ### Method GET ### Endpoint /data/generate/{job_id}/data ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job whose data to stream. ### Response #### Success Response (200) - **string** - The generated data, typically in CSV or JSON format. #### Response Example "name,age\nAlice,30\nBob,25\n" ``` ```APIDOC ## GET /data/generate/{job_id}/messages ### Description Streams the messages or logs associated with a data generation job. ### Method GET ### Endpoint /data/generate/{job_id}/messages ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job whose messages to stream. ### Response #### Success Response (200) - **string** - The stream of messages for the job. #### Response Example "INFO: Data generation started.\nPROGRESS: 50%\n" ``` -------------------------------- ### Manage Input-Response Pair Generation Jobs (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Enables management of jobs that generate input-response pairs. Functions include starting jobs, listing jobs with query parameters, retrieving job status, canceling ongoing jobs, and streaming job-related data or messages. ```typescript client.data.generateInputResponsePairs.retrieve(jobId) client.data.generateInputResponsePairs.list({ ...params }) client.data.generateInputResponsePairs.cancel(jobId) client.data.generateInputResponsePairs.startJob({ ...params }) client.data.generateInputResponsePairs.streamData(jobId) client.data.generateInputResponsePairs.streamMessages(jobId) ``` -------------------------------- ### Calibrate Scoring System Methods (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides methods to manage calibration jobs within the scoring system. Includes starting, listing, retrieving status, canceling jobs, and streaming messages. Relies on the client object and specific methods within the scoringSystem.calibrate namespace. ```typescript client.scoringSystem.calibrate.retrieve(jobId) -> ScoringSpecCalibrationStatus client.scoringSystem.calibrate.list({ ...params }) -> CalibrateListResponse client.scoringSystem.calibrate.cancel(jobId) -> string client.scoringSystem.calibrate.startJob({ ...params }) -> ScoringSpecCalibrationStatus client.scoringSystem.calibrate.streamMessages(jobId) -> string ``` -------------------------------- ### Generate Scoring System Methods (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Enables management of generation jobs within the scoring system. Supports starting, listing, retrieving status, canceling jobs, and streaming messages. These operations are accessed via the client object's scoringSystem.generate namespace. ```typescript client.scoringSystem.generate.retrieve(jobId) -> GenerateRetrieveResponse client.scoringSystem.generate.list({ ...params }) -> GenerateListResponse client.scoringSystem.generate.cancel(jobId) -> string client.scoringSystem.generate.startJob({ ...params }) -> GenerateStartJobResponse client.scoringSystem.generate.streamMessages(jobId) -> string ``` -------------------------------- ### Manage Data Generation Jobs (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides methods to manage data generation jobs. This includes starting new jobs, listing existing jobs with optional parameters, retrieving the status of a specific job, canceling a job, and streaming data or messages associated with a job. ```typescript client.data.generate.retrieve(jobId) client.data.generate.list({ ...params }) client.data.generate.cancel(jobId) client.data.generate.startJob({ ...params }) client.data.generate.streamData(jobId) client.data.generate.streamMessages(jobId) ``` -------------------------------- ### Use Undocumented Request Parameters with @ts-expect-error Source: https://github.com/withpi/sdk-node/blob/main/README.md Demonstrates how to include undocumented parameters in requests by using the `// @ts-expect-error` directive. The library sends these extra parameters as-is, either in the query for GET requests or in the body for others. ```typescript client.foo.create({ foo: 'my_param', bar: 12, // @ts-expect-error baz is not yet public baz: 'undocumented option', }); ``` -------------------------------- ### Basic Pi Client Initialization and Scoring Source: https://github.com/withpi/sdk-node/blob/main/README.md Initializes the PiClient with an API key and performs a scoring request using the scoringSystem API. It logs the total score to the console. Requires an 'WITHPI_API_KEY' environment variable. ```js import PiClient from 'withpi'; const client = new PiClient({ apiKey: process.env['WITHPI_API_KEY'], // This is the default and can be omitted }); const scoringSystemMetrics = await client.scoringSystem.score({ llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }], }); console.log(scoringSystemMetrics.total_score); ``` -------------------------------- ### Configure SDK to Use Global Web Fetch Shim Source: https://github.com/withpi/sdk-node/blob/main/README.md Explains how to configure the SDK to use a global, web-standards-compliant `fetch` implementation, such as the one provided by `undici` in Node.js environments or available in modern browsers and Next.js. ```typescript // Tell TypeScript and the package to use the global web fetch instead of node-fetch. // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed. import 'withpi/shims/web'; import PiClient from 'withpi'; ``` -------------------------------- ### Configure SDK to Use Node-Fetch Shim Source: https://github.com/withpi/sdk-node/blob/main/README.md Details how to explicitly configure the SDK to use the Node.js `fetch` implementation, including any necessary polyfills. This is useful for ensuring compatibility or if the default behavior needs to be overridden. ```typescript import "withpi/shims/node" ``` -------------------------------- ### Configure HTTP(S) Agent with Proxy for PiClient Source: https://github.com/withpi/sdk-node/blob/main/README.md Demonstrates how to configure a custom HTTP(S) agent for all requests made by the PiClient, specifically for routing through a proxy server using HttpsProxyAgent. It also shows how to override the agent for a single request, disabling keep-alive. ```typescript import http from 'http'; import { HttpsProxyAgent } from 'https-proxy-agent'; // Configure the default for all requests: const client = new PiClient({ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL), }); // Override per-request: await client.scoringSystem.score( { llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }], }, { httpAgent: new http.Agent({ keepAlive: false }), }, ); ``` -------------------------------- ### Pi Client with TypeScript Types for Scoring Source: https://github.com/withpi/sdk-node/blob/main/README.md Demonstrates initializing the PiClient and making a scoring request using explicit TypeScript types for parameters and responses. This improves code safety and developer experience in TypeScript projects. ```ts import PiClient from 'withpi'; const client = new PiClient({ apiKey: process.env['WITHPI_API_KEY'], // This is the default and can be omitted }); const params: PiClient.ScoringSystemScoreParams = { llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }], }; const scoringSystemMetrics: PiClient.ScoringSystemMetrics = await client.scoringSystem.score(params); ``` -------------------------------- ### Manage Scoring Systems (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Facilitates interaction with scoring systems. This involves importing specifications for scoring systems, scoring data using specified parameters, and uploading scoring systems to Hugging Face. Each method is designed for specific scoring system management tasks. ```typescript client.scoringSystem.importSpec({ ...params }) client.scoringSystem.score({ ...params }) client.scoringSystem.uploadToHuggingface({ ...params }) ``` -------------------------------- ### Manual Shim Imports for Node.js Source: https://github.com/withpi/sdk-node/blob/main/src/_shims/README.md Users can manually import specific shims to resolve TypeScript module resolution issues. 'withpi/shims/node' is used for Node.js environments, and 'withpi/shims/web' for web-like environments. ```typescript import 'withpi/shims/node' ``` ```typescript import 'withpi/shims/web' ``` -------------------------------- ### Scoring System API Source: https://github.com/withpi/sdk-node/blob/main/api.md Endpoints for managing and interacting with scoring systems, including importing specifications, scoring data, and uploading models to Hugging Face. ```APIDOC ## POST /scoring_system/import_spec ### Description Imports a scoring system specification. ### Method POST ### Endpoint /scoring_system/import_spec ### Parameters #### Request Body - **spec_url** (string) - Required - The URL of the scoring system specification. ### Request Example { "spec_url": "http://example.com/scoring_spec.json" } ### Response #### Success Response (200) - **ScoringSystemImportSpecResponse** (object) - Response confirming the import. #### Response Example { "message": "Scoring system specification imported successfully." } ``` ```APIDOC ## POST /scoring_system/score ### Description Scores provided data using the configured scoring system. ### Method POST ### Endpoint /scoring_system/score ### Parameters #### Request Body - **data** (any) - Required - The data to be scored. - **scoring_config** (object) - Optional - Configuration for the scoring process. ### Request Example { "data": {"feature1": 10, "feature2": "A"}, "scoring_config": {"model_name": "default_model"} } ### Response #### Success Response (200) - **ScoringSystemMetrics** (object) - The metrics resulting from the scoring process. #### Response Example { "score": 0.85, "confidence": 0.92 } ``` ```APIDOC ## POST /scoring_system/to_huggingface ### Description Uploads a scoring system to Hugging Face. ### Method POST ### Endpoint /scoring_system/to_huggingface ### Parameters #### Request Body - **model_name** (string) - Required - The name of the model to upload. - **huggingface_token** (string) - Required - Your Hugging Face authentication token. - **repo_id** (string) - Required - The repository ID on Hugging Face. ### Request Example { "model_name": "my-scoring-model", "huggingface_token": "hf_YOUR_TOKEN_HERE", "repo_id": "your_username/my-scoring-model-repo" } ### Response #### Success Response (200) - **string** - A message confirming the upload status. #### Response Example "Model 'my-scoring-model' uploaded to repository 'your_username/my-scoring-model-repo' successfully." ``` -------------------------------- ### Access Raw Response Data and Headers using asResponse() Source: https://github.com/withpi/sdk-node/blob/main/README.md Demonstrates how to retrieve the raw Response object, including headers and status text, from an API call using the `.asResponse()` method. This allows direct inspection of the underlying HTTP response. ```typescript const client = new PiClient(); const response = await client.scoringSystem .score({ llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }], }) .asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object ``` -------------------------------- ### Access Raw Response Data and Parsed Data using withResponse() Source: https://github.com/withpi/sdk-node/blob/main/README.md Shows how to obtain both the parsed API data and the raw Response object simultaneously using the `.withResponse()` method. This is useful when you need both the processed results and the underlying HTTP details. ```typescript const { data: scoringSystemMetrics, response: raw } = await client.scoringSystem .score({ llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }], }) .withResponse(); console.log(raw.headers.get('X-My-Header')); console.log(scoringSystemMetrics.total_score); ``` -------------------------------- ### Pi Client Error Handling with APIError Source: https://github.com/withpi/sdk-node/blob/main/README.md Shows how to handle potential API errors, such as connection issues or non-success status codes, by catching subclasses of PiClient.APIError. It logs the status, name, and headers of the caught error. ```ts const scoringSystemMetrics = await client.scoringSystem .score({ llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }], }) .catch(async (err) => { if (err instanceof PiClient.APIError) { console.log(err.status); // 400 console.log(err.name); // BadRequestError console.log(err.headers); // {server: 'nginx', ...} } else { throw err; } }); ``` -------------------------------- ### Search Methods (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Facilitates search operations including embedding creation and ranking of query-to-passage results. These methods are accessed through the client.search namespace and require specific parameters. ```typescript client.search.embed({ ...params }) -> SearchEmbedResponse client.search.rank({ ...params }) -> SearchRankResponse ``` -------------------------------- ### Query Classifier Method (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides functionality to classify queries using the query classifier. This method is accessed via the client.search.queryClassifier namespace and requires parameters for classification. ```typescript client.search.queryClassifier.classify({ ...params }) -> QueryClassifierClassifyResponse ``` -------------------------------- ### QueryClassifier API Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides an endpoint for classifying user queries. ```APIDOC ## POST /search/query_classifier/classify ### Description Classifies a given user query. ### Method POST ### Endpoint /search/query_classifier/classify ### Parameters #### Request Body - **params** (object) - Required - The query to be classified. ### Request Example { "example": "{\"query\": \"What is the weather today?\"}" } ### Response #### Success Response (200) - **QueryClassifierClassifyResponse** - An object containing the classification result for the query. #### Response Example { "example": "{\"classification\": \"weather_inquiry\", \"confidence\": 0.85}" } ``` -------------------------------- ### Configure Pi Client Retries Source: https://github.com/withpi/sdk-node/blob/main/README.md Demonstrates how to configure the maximum number of automatic retries for API requests. The default is 2 retries. Setting `maxRetries` to 0 disables retries. ```js // Configure the default for all requests: const client = new PiClient({ maxRetries: 0, // default is 2 }); // Or, configure per-request: await client.scoringSystem.score({ llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }] }, { maxRetries: 5, }); ``` -------------------------------- ### Make Undocumented POST Requests Source: https://github.com/withpi/sdk-node/blob/main/README.md Illustrates how to make POST requests to undocumented API endpoints using the `client.post` method. This approach respects client-level configurations like retries and allows specifying custom body and query parameters. ```typescript await client.post('/some/path', { body: { some_prop: 'foo' }, query: { some_query_arg: 'bar' }, }); ``` -------------------------------- ### Shim Type Selection for TypeScript Source: https://github.com/withpi/sdk-node/blob/main/src/_shims/README.md Shim types are imported from `withpi/_shims/index`. It prioritizes manual types from `withpi/_shims/manual-types` or defaults to auto types from `withpi/_shims/auto/types` and `withpi/_shims/auto/types-node`. ```typescript // withpi/_shims/index (conceptual for types) // import { manualTypes } from './manual-types'; // import { autoTypes } from './auto/types'; // import { autoTypesNode } from './auto/types-node'; // let ShimTypes = manualTypes.length > 0 ? manualTypes : autoTypes; // if (isNodeEnvironment && tsConfig.moduleResolution === 'nodenext') { // ShimTypes = autoTypesNode; // } ``` -------------------------------- ### Groundedness API Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides an endpoint for checking the groundedness of a given text against a context. ```APIDOC ## POST /search/groundedness/check ### Description Checks if a given text is grounded in a provided context. ### Method POST ### Endpoint /search/groundedness/check ### Parameters #### Request Body - **params** (object) - Required - The text and context for groundedness checking. ### Request Example { "example": "{\"text\": \"The capital of France is Paris.\", \"context\": \"Paris is a major European city and the capital of France. Known for the Eiffel Tower.\"}" } ### Response #### Success Response (200) - **GroundednessCheckResponse** - An object indicating whether the text is grounded and a score. #### Response Example { "example": "{\"is_grounded\": true, \"score\": 0.92}" } ``` -------------------------------- ### Search API Source: https://github.com/withpi/sdk-node/blob/main/api.md Provides endpoints for search-related operations, including embedding text and ranking query-passage pairs. ```APIDOC ## POST /search/embed ### Description Generates embeddings for given text inputs. ### Method POST ### Endpoint /search/embed ### Parameters #### Request Body - **params** (object) - Required - Input text and model parameters for embedding generation. ### Request Example { "example": "{\"texts\": [\"This is the first sentence.\", \"This is the second sentence.\"], \"model\": \"embedding-model-v1\"}" } ### Response #### Success Response (200) - **SearchEmbedResponse** - An object containing embeddings for the input texts. #### Response Example { "example": "{\"embeddings\": [[0.1, 0.2, ...], [0.3, 0.4, ...]]}" } ``` ```APIDOC ## POST /search/query_to_passage/score ### Description Scores the relevance of passages to a given query. ### Method POST ### Endpoint /search/query_to_passage/score ### Parameters #### Request Body - **params** (object) - Required - Query and passage data for scoring. ### Request Example { "example": "{\"query\": \"What is the capital of France?\", \"passages\": [\"Paris is the capital of France.\", \"The Eiffel Tower is in Paris.\"], \"model\": \"ranking-model-v2\"}" } ### Response #### Success Response (200) - **SearchRankResponse** - An object containing relevance scores for each passage. #### Response Example { "example": "{\"scores\": [0.95, 0.60]}" } ``` -------------------------------- ### Groundedness Check Method (Node.js) Source: https://github.com/withpi/sdk-node/blob/main/api.md Allows for checking the groundedness of content. This operation is performed using the client.search.groundedness.check method and requires specific parameters. ```typescript client.search.groundedness.check({ ...params }) -> GroundednessCheckResponse ``` -------------------------------- ### Configure Pi Client Request Timeout Source: https://github.com/withpi/sdk-node/blob/main/README.md Shows how to set a custom timeout for API requests. The default timeout is 1 minute. An `APIConnectionTimeoutError` is thrown if a request exceeds this duration. ```ts // Configure the default for all requests: const client = new PiClient({ timeout: 20 * 1000, // 20 seconds (default is 1 minute) }); // Override per-request: await client.scoringSystem.score({ llm_input: 'Tell me something different', llm_output: 'The lazy dog was jumped over by the quick brown fox', scoring_spec: [{ question: 'Is this response truthful?' }, { question: 'Is this response relevant?' }] }, { timeout: 5 * 1000, }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.