### Install FinetuneDB SDK Source: https://docs.finetunedb.com/logging-data/node-js-sdk Install the FinetuneDB Node.js SDK using npm or yarn. ```sh npm install --save finetunedb # or yarn add finetunedb ``` -------------------------------- ### OpenAI Completion Output Example Source: https://docs.finetunedb.com/logging-data/web-api Example of formatting the response from openai.chat.completions.create for log output. ```javascript const response = await openai.chat.completions.create(...); const output = [response.choices[0].message]; ``` -------------------------------- ### OpenAI Embedding Output Example Source: https://docs.finetunedb.com/logging-data/web-api Example of formatting the response.data from openai.embeddings.create for log output. ```javascript const response = await openai.embeddings.create(...); const output = response.data; ``` -------------------------------- ### OpenAI Completion Input Example Source: https://docs.finetunedb.com/logging-data/web-api Example of the messages array structure used for CHATCOMPLETION type inputs. ```json [ { "role": "system", "content": "You are an expert assistant" }, { "role": "user", "content": "Hello, how are you?" } ] ``` -------------------------------- ### JSONL Export Format Example Source: https://docs.finetunedb.com/features/dataset-manager/export-datasets Shows the JSONL format used when exporting a dataset. Each line is a JSON object with a 'messages' array containing system, user, and assistant roles. This example includes two sample conversations. ```json {"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]} {"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]} ``` -------------------------------- ### OpenAI Embedding Input Example (String) Source: https://docs.finetunedb.com/logging-data/web-api Example of a single string input for EMBEDDING type logs. ```json "Hello world!" ``` -------------------------------- ### OpenAI Embedding Input Example (Array) Source: https://docs.finetunedb.com/logging-data/web-api Example of an array of strings input for EMBEDDING type logs. ```json ["Hello", "world!"] ``` -------------------------------- ### Initialize and Use FinetuneDB Client Source: https://docs.finetunedb.com/logging-data/node-js-sdk Initialize the OpenAI client with FinetuneDB logging enabled, create a chat completion, and update the log with custom tags. ```js // import OpenAI from 'openai' import OpenAI from "finetunedb/openai"; // Fully compatible with original OpenAI initialization const openai = new OpenAI({ apiKey: "your api key", // defaults to process.env["OPENAI_API_KEY"] // Optional: Step 1 - Initialize FinetuneDB to enable logging finetunedb: { apiKey: "your api key", // defaults to process.env["FINETUNEDB_API_KEY"] }, }); async function main() { // Allows optional finetunedb object const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: "Hello world!" }], model: "gpt-3.5-turbo", // Optional: Step 2 - Log a chat completion finetunedb: { // Define the project ID projectId: "cloio7t90000...", // Enable/disable data collection. Defaults to true. logRequest: true, // Optional: Add custom searchable tags tags: ["test-prompt"], }, }); // Optional: Update log await completion.finetunedb.updateLastLog({ tags: ["test-prompt", "new-tag"], }); } main(); ``` -------------------------------- ### POST /logs Source: https://docs.finetunedb.com/logging-data/web-api Creates a new log entry in FineTuneDB. Accepts parameters for project identification, model configuration, input/output data, and metadata. ```APIDOC ## POST /logs ### Description Creates a new log entry in FineTuneDB. ### Method POST ### Endpoint https://app.finetunedb.com/api/v1/logs ### Parameters #### Request Body - **projectId** (string) - Required - The project identifier. - **parentId** (string) - Optional - Parent log identifier. - **name** (string) - Optional - Name of the log. - **provider** (enum: openai) - Required - The provider. - **tags** (array of strings) - Optional - Tags for the log. - **model** (string) - Required - The model used. - **source** (string) - Required - The source of the log. - **modelParameters** (object) - Optional - Model configuration parameters. - **model** (string) - Required - The model name. - **provider** (string) - Optional - The provider. - **max_tokens** (number) - Optional - Maximum tokens. - **temperature** (number) - Optional - Sampling temperature. - **top_p** (number) - Optional - Top-p sampling. - **stop_sequences** (array of strings) - Optional - Stop sequences. - **presence_penalty** (number) - Optional - Presence penalty. - **frequency_penalty** (number) - Optional - Frequency penalty. - **other** (record of any type) - Optional - Additional parameters. - **input** (union of input types) - Optional - Input data (see Input Types). - **output** (union of output types) - Optional - Output data (see Output Types). - **metadata** (record of any type) - Optional - Metadata. - **type** (enum: CHATCOMPLETION, EMBEDDING) - Required - The type of log. - **error** (string) - Optional - Error message. - **latencyMs** (number) - Optional - Latency in milliseconds. ### Input Types #### OpenAI Completion (If type=CHATCOMPLETION) Pass the messages value used in openai.chat.completions.create. Example: ```json [ { "role": "system", "content": "You are an expert assistant" }, { "role": "user", "content": "Hello, how are you?" } ] ``` #### OpenAI Embedding (If type=EMBEDDING) Pass the input value sent to openai.embeddings.create. Example: ```json "Hello world!" ``` or ```json ["Hello", "world!"] ``` ### Output Types #### OpenAI Completion (If type=CHATCOMPLETION) Pass the response value from openai.chat.completions.create as an array. Example: ```javascript const response = await openai.chat.completions.create(...); const output = [response.choices[0].message]; ``` #### OpenAI Embedding (If type=EMBEDDING) Pass the response.data value from openai.embeddings.create. Example: ```javascript const response = await openai.embeddings.create(...); const output = response.data; ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.