From ff63e6a73af6096f9920f934d5c4a8e0a97d79bf Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 20 Mar 2025 02:24:33 -0700 Subject: [PATCH 01/24] Bump Python version to --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 9d6be0d..307274b 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trainloop-sdk" -version = "0.1.6" +version = "0.1.7" description = "A Data Collection SDK for TrainLoop" authors = [{ name = "TrainLoop", email = "hello@trainloop.ai" }] dependencies = ["requests>=2.32.3"] From c2454ba822e302f2e47cc61538100e30089d19dd Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 20 Mar 2025 02:24:34 -0700 Subject: [PATCH 02/24] Bump TypeScript version to --- typescript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/package.json b/typescript/package.json index 3a6f8e6..fb43010 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@trainloop/sdk", - "version": "0.1.3", + "version": "0.1.4", "description": "TypeScript SDK for TrainLoop API", "main": "dist/index.js", "types": "dist/index.d.ts", From 135c5e139613edc96f085f6fc058482e56602231 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 14:37:21 -0700 Subject: [PATCH 03/24] make new version not local in release script --- release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.sh b/release.sh index ffc9c38..def947d 100644 --- a/release.sh +++ b/release.sh @@ -37,7 +37,7 @@ bump_version_in_file() { fi IFS='.' read -r -a version_parts <<< "$current_version" - local new_version=$(bump_version_parts "${version_parts[@]}" "$bump_type") + new_version=$(bump_version_parts "${version_parts[@]}" "$bump_type") # Replace the old version with the new version sed -i.bak -E "s/$current_version/$new_version/" "$file" From 3acf68ddd902cc1eace288279031967da43eabc7 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 14:44:04 -0700 Subject: [PATCH 04/24] Allow passing in baseurl to every language --- go/trainloop.go | 13 ++++++++++--- python/trainloop/trainloop.py | 4 ++-- typescript/src/client.ts | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/go/trainloop.go b/go/trainloop.go index d0f5326..950d829 100644 --- a/go/trainloop.go +++ b/go/trainloop.go @@ -12,11 +12,17 @@ import ( // Client represents the configuration needed to authenticate and send data type Client struct { APIKey string + BaseURL string HTTPClient *http.Client } // NewClient initializes a new TrainLoop client with an API key -func NewClient(apiKey string) *Client { +func NewClient(apiKey string, baseURL ...string) *Client { + url := "https://app.trainloop.ai" + if len(baseURL) > 0 { + url = baseURL[0] + } + transport := &http.Transport{ MaxIdleConns: 100, MaxIdleConnsPerHost: 100, @@ -25,7 +31,8 @@ func NewClient(apiKey string) *Client { } return &Client{ - APIKey: apiKey, + APIKey: apiKey, + BaseURL: url, HTTPClient: &http.Client{ Timeout: 10 * time.Second, Transport: transport, @@ -71,7 +78,7 @@ func (t *Client) SendData(messages []Message, sampleFeedback SampleFeedbackType, } // Create the request - req, err := http.NewRequest("POST", "https://app.trainloop.ai/api/datasets/collect", bytes.NewBuffer(body)) + req, err := http.NewRequest("POST", t.BaseURL+"/api/datasets/collect", bytes.NewBuffer(body)) if err != nil { return err } diff --git a/python/trainloop/trainloop.py b/python/trainloop/trainloop.py index 00e46bf..a914ceb 100644 --- a/python/trainloop/trainloop.py +++ b/python/trainloop/trainloop.py @@ -18,7 +18,7 @@ class Client: A client for sending message data to TrainLoop. """ - def __init__(self, api_key: str): + def __init__(self, api_key: str, base_url: str = "https://app.trainloop.ai"): """ Initialize a new TrainLoop client with an API key @@ -28,7 +28,7 @@ def __init__(self, api_key: str): raise ValueError("API key is required") self.api_key = api_key - self.base_url = "https://app.trainloop.ai" + self.base_url = base_url self.headers = { "Content-Type": "application/json", "Authorization": f"Bearer {self.api_key}", diff --git a/typescript/src/client.ts b/typescript/src/client.ts index 9f7d828..aaf579a 100644 --- a/typescript/src/client.ts +++ b/typescript/src/client.ts @@ -29,9 +29,9 @@ export class Client { * * @param apiKey Authentication API key for TrainLoop */ - constructor(apiKey: string) { + constructor(apiKey: string, baseUrl: string = 'https://app.trainloop.ai') { this.apiKey = apiKey; - this.baseUrl = 'https://app.trainloop.ai'; + this.baseUrl = baseUrl; // Create an axios instance with detailed configuration to match other SDKs const config: AxiosRequestConfig = { From 3bd1fa13def1a56650323e59f239725b84bfd6f6 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 15:31:14 -0700 Subject: [PATCH 05/24] update release script to show version in commit message --- release.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/release.sh b/release.sh index def947d..6283df7 100644 --- a/release.sh +++ b/release.sh @@ -32,16 +32,19 @@ bump_version_in_file() { local current_version=$(echo "$version_line" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') if [ -z "$current_version" ]; then - echo "No version found in $file" + echo "No version found in $file" >&2 return fi IFS='.' read -r -a version_parts <<< "$current_version" - new_version=$(bump_version_parts "${version_parts[@]}" "$bump_type") + local new_version=$(bump_version_parts "${version_parts[@]}" "$bump_type") # Replace the old version with the new version sed -i.bak -E "s/$current_version/$new_version/" "$file" - echo "Updated $file from $current_version to $new_version" + echo "Updated $file from $current_version to $new_version" >&2 + + # Return the new version so it can be captured + echo "$new_version" } # Ask the user for the type of version bump @@ -61,13 +64,18 @@ sdk_choice=${sdk_choice:-all} # Default to all if no input if [[ "$sdk_choice" == "python" || "$sdk_choice" == "all" ]]; then python_setup_file="python/pyproject.toml" python_version_regex="version = \"[0-9]+\.[0-9]+\.[0-9]+\"" - bump_version_in_file "$python_setup_file" "$python_version_regex" "$bump_type" + new_version=$(bump_version_in_file "$python_setup_file" "$python_version_regex" "$bump_type") git add python/pyproject.toml git commit -m "Bump Python version to $new_version" cd python || exit + # clean up dist folder rm -rf dist + + # source the venv + source venv/bin/activate + # build the package python -m build @@ -85,7 +93,7 @@ fi if [[ "$sdk_choice" == "typescript" || "$sdk_choice" == "all" ]]; then typescript_package_file="typescript/package.json" typescript_version_regex="\"version\": \"[0-9]+\.[0-9]+\.[0-9]+\"" - bump_version_in_file "$typescript_package_file" "$typescript_version_regex" "$bump_type" + new_version=$(bump_version_in_file "$typescript_package_file" "$typescript_version_regex" "$bump_type") git add typescript/package.json git commit -m "Bump TypeScript version to $new_version" From 121c0d9cf927f5a652533005336c650a1516a6f2 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 15:18:37 -0700 Subject: [PATCH 06/24] add build to pyproject --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 307274b..c84eae2 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -7,5 +7,5 @@ dependencies = ["requests>=2.32.3"] urls = { "Homepage" = "https://github.com/trainloop/sdk" } [build-system] -requires = ["setuptools>=42", "wheel"] +requires = ["setuptools>=42", "wheel", "build>=0.10.0"] build-backend = "setuptools.build_meta" From 7420c4dd57092163f52b56c24d1538659bcb335d Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 15:37:21 -0700 Subject: [PATCH 07/24] Bump Python version to 0.1.8 --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index c84eae2..93d114c 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trainloop-sdk" -version = "0.1.7" +version = "0.1.8" description = "A Data Collection SDK for TrainLoop" authors = [{ name = "TrainLoop", email = "hello@trainloop.ai" }] dependencies = ["requests>=2.32.3"] From 718c702a1e084d5603911ea19a143b962e2b8c05 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 15:37:24 -0700 Subject: [PATCH 08/24] Bump TypeScript version to 0.1.5 --- typescript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/package.json b/typescript/package.json index fb43010..49de7d8 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@trainloop/sdk", - "version": "0.1.4", + "version": "0.1.5", "description": "TypeScript SDK for TrainLoop API", "main": "dist/index.js", "types": "dist/index.d.ts", From a327a49b1a750fa00eb3b1074b2515445b1f9de0 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 15:47:21 -0700 Subject: [PATCH 09/24] fix bug in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ecde68..c4e9fe5 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ if success { ### TypeScript ```typescript -import { Client, SampleFeedbackType } from 'trainloop-sdk'; +import { Client, SampleFeedbackType } from '@trainloop/sdk'; import * as dotenv from 'dotenv'; async function main() { From 2d77fd1a807c7b5997d7946a0ce88da74a394ef6 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 18:57:55 -0700 Subject: [PATCH 10/24] Create examples folder --- examples/.env.example | 2 + examples/.gitignore | 2 + examples/README.md | 60 ++++ examples/go/go.mod | 5 + examples/go/go.sum | 2 + examples/go/main.go | 40 +++ examples/package-lock.json | 496 +++++++++++++++++++++++++++ examples/package.json | 23 ++ examples/python/basic_example.py | 29 ++ examples/python/requirements.txt | 2 + examples/setup.sh | 41 +++ examples/typescript/basic_example.ts | 35 ++ 12 files changed, 737 insertions(+) create mode 100644 examples/.env.example create mode 100644 examples/.gitignore create mode 100644 examples/README.md create mode 100644 examples/go/go.mod create mode 100644 examples/go/go.sum create mode 100644 examples/go/main.go create mode 100644 examples/package-lock.json create mode 100644 examples/package.json create mode 100644 examples/python/basic_example.py create mode 100644 examples/python/requirements.txt create mode 100644 examples/setup.sh create mode 100644 examples/typescript/basic_example.ts diff --git a/examples/.env.example b/examples/.env.example new file mode 100644 index 0000000..3462a5f --- /dev/null +++ b/examples/.env.example @@ -0,0 +1,2 @@ +# Your TrainLoop API key +TRAINLOOP_API_KEY=your_api_key_here diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..b792e47 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,2 @@ +venv +node_modules \ No newline at end of file diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..3aea90c --- /dev/null +++ b/examples/README.md @@ -0,0 +1,60 @@ +# TrainLoop SDK Examples + +This directory contains examples for using the TrainLoop SDK in different languages: +- Go +- Python +- TypeScript + +## Prerequisites + +To run these data colletion examples, you'll need: +- Node.js and npm (for TypeScript examples) +- Python 3.7+ (for Python examples) +- Go 1.18+ (for Go examples) +- A TrainLoop API key + +## Quickstart + +Run `bash setup.sh` to setup the environment and install dependencies. You can then run `npm run ts:basic`, `npm run py:basic`, or `npm run go:basic` to run the examples. + +## Manual Setup + +1. Clone the repository +2. Create a `.env` file in the root of this directory with your TrainLoop API key: + ``` + TRAINLOOP_API_KEY=your_api_key_here + ``` + +3. Install dependencies for all languages: + ``` + npm run install:all + ``` + + Or install for a specific language: + ``` + npm run install:ts # TypeScript + npm run install:py # Python + npm run install:go # Go + ``` + +## Running Examples + +### TypeScript +``` +npm run ts:basic +``` + +### Python +``` +npm run py:basic +``` + +### Go +``` +npm run go:basic +``` + +## Examples + +Each language directory contains the following examples: +- Basic usage: Shows how to initialize the client and send data to TrainLoop diff --git a/examples/go/go.mod b/examples/go/go.mod new file mode 100644 index 0000000..79baeaa --- /dev/null +++ b/examples/go/go.mod @@ -0,0 +1,5 @@ +module github.com/TrainLoop/sdk/examples/go + +go 1.18 + +require github.com/TrainLoop/sdk/go v0.0.0-20250327224721-a327a49b1a75 diff --git a/examples/go/go.sum b/examples/go/go.sum new file mode 100644 index 0000000..c7899e8 --- /dev/null +++ b/examples/go/go.sum @@ -0,0 +1,2 @@ +github.com/TrainLoop/sdk/go v0.0.0-20250327224721-a327a49b1a75 h1:0jK5+E2Nrs03qwyTsTRZV1iISrCUKC1p+LlvdNtokOs= +github.com/TrainLoop/sdk/go v0.0.0-20250327224721-a327a49b1a75/go.mod h1:j/vm7eohmMWfKLXybU0sBFmBR1NmOcq/kahXCsReLxE= diff --git a/examples/go/main.go b/examples/go/main.go new file mode 100644 index 0000000..98c7f69 --- /dev/null +++ b/examples/go/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "os" + + trainloop "github.com/TrainLoop/sdk/go" +) + +func main() { + // Get the API key from the environment variable + apiKey := os.Getenv("TRAINLOOP_API_KEY") + + if apiKey == "" { + fmt.Println("TRAINLOOP_API_KEY environment variable is not set") + return + } + + // Initialize the client with the API key + client := trainloop.NewClient(apiKey) + + // Define the messages to send (via inference or other means) + messages := []trainloop.Message{ + {Role: "user", Content: "Hello, from the user"}, + {Role: "assistant", Content: "Hello, from the assistant"}, + } + + // Send the data to TrainLoop + // The dataset ID is the ID of the dataset you want to send the data to + // The sample feedback is the feedback you want to give to the sample + // The feedback can be either good or bad. + err := client.SendData(messages, trainloop.GoodFeedback, "example-dataset-id") + + // If the data errored, the above function will return an error + if err == nil { + fmt.Println("Data sent successfully!") + } else { + fmt.Println("Data was not sent.") + } +} diff --git a/examples/package-lock.json b/examples/package-lock.json new file mode 100644 index 0000000..f8ce880 --- /dev/null +++ b/examples/package-lock.json @@ -0,0 +1,496 @@ +{ + "name": "trainloop-sdk-examples", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "trainloop-sdk-examples", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@trainloop/sdk": "^0.1.5", + "dotenv": "^16.0.3" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^4.9.5" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@trainloop/sdk": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@trainloop/sdk/-/sdk-0.1.5.tgz", + "integrity": "sha512-6ich5fpud6mNngiOuSnvn3m41oPYin7Vpn1ueucC64DOEWvtVmD3AMX6dNuOPjWwE0ERxpWebsE3fWL5EDVnXQ==", + "dependencies": { + "axios": "^1.6.0", + "dotenv": "^16.4.1" + } + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, + "node_modules/@types/node": { + "version": "22.13.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.14.tgz", + "integrity": "sha512-Zs/Ollc1SJ8nKUAgc7ivOEdIBM8JAKgrqqUYi2J997JuKO7/tpQC+WCetQ1sypiKCQWHdvdg9wBNpUPEWZae7w==", + "dev": true, + "peer": true, + "dependencies": { + "undici-types": "~6.20.0" + } + }, + "node_modules/acorn": { + "version": "8.14.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz", + "integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", + "dev": true, + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.8.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz", + "integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", + "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "peer": true + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "engines": { + "node": ">=6" + } + } + } +} diff --git a/examples/package.json b/examples/package.json new file mode 100644 index 0000000..a73db8a --- /dev/null +++ b/examples/package.json @@ -0,0 +1,23 @@ +{ + "name": "trainloop-sdk-examples", + "version": "1.0.0", + "description": "Examples for using TrainLoop SDK in Go, Python, and TypeScript", + "scripts": { + "install:all": "npm install && npm run install:py && npm run install:go", + "install:py": "python3 -m venv venv && source venv/bin/activate && pip install -r python/requirements.txt && deactivate", + "install:go": "cd go && go get github.com/TrainLoop/sdk@v0.0.7 && go mod tidy", + "ts:basic": "npx ts-node typescript/basic_example.ts", + "py:basic": "source venv/bin/activate && python python/basic_example.py && deactivate", + "go:basic": "cd go && go run main.go" + }, + "dependencies": { + "@trainloop/sdk": "^0.1.5", + "dotenv": "^16.0.3" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^4.9.5" + }, + "author": "", + "license": "ISC" +} \ No newline at end of file diff --git a/examples/python/basic_example.py b/examples/python/basic_example.py new file mode 100644 index 0000000..cdff203 --- /dev/null +++ b/examples/python/basic_example.py @@ -0,0 +1,29 @@ +import os +from trainloop import Client, SampleFeedbackType +from dotenv import load_dotenv + +load_dotenv() + + +def main(): + # Initialize the TrainLoop client with your api key + client = Client(api_key=os.getenv("TRAINLOOP_API_KEY")) + + # Example messages + messages = [ + {"role": "system", "content": "System message here"}, + {"role": "user", "content": "Hello from the user!"}, + ] + + # Send data + success = client.send_data( + messages, sample_feedback=SampleFeedbackType.GOOD, dataset_id="test-dataset" + ) + if success: + print("Data sent successfully!") + else: + print("Data was not sent. Check logs for details.") + + +if __name__ == "__main__": + main() diff --git a/examples/python/requirements.txt b/examples/python/requirements.txt new file mode 100644 index 0000000..642994e --- /dev/null +++ b/examples/python/requirements.txt @@ -0,0 +1,2 @@ +python-dotenv>=0.21.0 +trainloop-sdk diff --git a/examples/setup.sh b/examples/setup.sh new file mode 100644 index 0000000..5f1ee35 --- /dev/null +++ b/examples/setup.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# TrainLoop SDK Examples Setup Script +echo "Setting up TrainLoop SDK Examples..." + +# Copy .env.example to .env if .env doesn't exist +if [ ! -f .env ]; then + echo "Creating .env file from template..." + cp .env.example .env + echo "Please update the .env file with your actual TrainLoop API key" +fi + +# Install all dependencies with npm (TypeScript + dev dependencies) +echo "Installing npm dependencies..." +npm install + +# Install Python dependencies +echo "Installing Python dependencies..." +# Create Python virtual environment if it doesn't exist +if [ ! -d "venv" ]; then + echo "Creating Python virtual environment..." + python3 -m venv venv +fi +# Activate virtual environment and install dependencies +echo "Activating virtual environment and installing dependencies..." +source venv/bin/activate +pip install -r python/requirements.txt +# Deactivate virtual environment +deactivate + +# Install Go dependencies +echo "Setting up Go dependencies..." +cd go +go get github.com/TrainLoop/sdk@v0.0.7 +go mod tidy +cd .. + +echo "Setup complete! You can now run examples using the following commands:" +echo " npm run run:ts # Run TypeScript example" +echo " npm run run:py # Run Python example" +echo " npm run run:go # Run Go example" diff --git a/examples/typescript/basic_example.ts b/examples/typescript/basic_example.ts new file mode 100644 index 0000000..363caaf --- /dev/null +++ b/examples/typescript/basic_example.ts @@ -0,0 +1,35 @@ +import { Client, SampleFeedbackType } from '@trainloop/sdk'; +import * as dotenv from 'dotenv'; + +// Load environment variables +dotenv.config(); + +async function main() { + + // Initialize the TrainLoop client with your api key + const client = new Client(process.env.TRAINLOOP_API_KEY || ''); + + // Example messages + const messages = [ + { role: 'system', content: 'System message here' }, + { role: 'user', content: 'Hello from the user!' }, + ]; + + // Send data + const success = await client.sendData( + messages, + SampleFeedbackType.GOOD, + 'test-dataset' + ); + + if (success) { + console.log('Data sent successfully!'); + } else { + console.log('Data was not sent. Check logs for details.'); + } +} + +// Execute the main function +main().catch(error => { + console.error('Unexpected error:', error); +}); From 490ca408a9ae7796ff6862b2f1bc246a4f2001ef Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 18:58:49 -0700 Subject: [PATCH 11/24] Delete examples since they are now in a seperate folder --- go/examples/basic/main.go | 40 ---------------------------- python/examples/basic_example.py | 29 -------------------- typescript/examples/basic_example.ts | 35 ------------------------ 3 files changed, 104 deletions(-) delete mode 100644 go/examples/basic/main.go delete mode 100644 python/examples/basic_example.py delete mode 100644 typescript/examples/basic_example.ts diff --git a/go/examples/basic/main.go b/go/examples/basic/main.go deleted file mode 100644 index 98c7f69..0000000 --- a/go/examples/basic/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "os" - - trainloop "github.com/TrainLoop/sdk/go" -) - -func main() { - // Get the API key from the environment variable - apiKey := os.Getenv("TRAINLOOP_API_KEY") - - if apiKey == "" { - fmt.Println("TRAINLOOP_API_KEY environment variable is not set") - return - } - - // Initialize the client with the API key - client := trainloop.NewClient(apiKey) - - // Define the messages to send (via inference or other means) - messages := []trainloop.Message{ - {Role: "user", Content: "Hello, from the user"}, - {Role: "assistant", Content: "Hello, from the assistant"}, - } - - // Send the data to TrainLoop - // The dataset ID is the ID of the dataset you want to send the data to - // The sample feedback is the feedback you want to give to the sample - // The feedback can be either good or bad. - err := client.SendData(messages, trainloop.GoodFeedback, "example-dataset-id") - - // If the data errored, the above function will return an error - if err == nil { - fmt.Println("Data sent successfully!") - } else { - fmt.Println("Data was not sent.") - } -} diff --git a/python/examples/basic_example.py b/python/examples/basic_example.py deleted file mode 100644 index cdff203..0000000 --- a/python/examples/basic_example.py +++ /dev/null @@ -1,29 +0,0 @@ -import os -from trainloop import Client, SampleFeedbackType -from dotenv import load_dotenv - -load_dotenv() - - -def main(): - # Initialize the TrainLoop client with your api key - client = Client(api_key=os.getenv("TRAINLOOP_API_KEY")) - - # Example messages - messages = [ - {"role": "system", "content": "System message here"}, - {"role": "user", "content": "Hello from the user!"}, - ] - - # Send data - success = client.send_data( - messages, sample_feedback=SampleFeedbackType.GOOD, dataset_id="test-dataset" - ) - if success: - print("Data sent successfully!") - else: - print("Data was not sent. Check logs for details.") - - -if __name__ == "__main__": - main() diff --git a/typescript/examples/basic_example.ts b/typescript/examples/basic_example.ts deleted file mode 100644 index 6fcdb17..0000000 --- a/typescript/examples/basic_example.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Client, SampleFeedbackType } from '../src'; -import * as dotenv from 'dotenv'; - -// Load environment variables -dotenv.config(); - -async function main() { - - // Initialize the TrainLoop client with your api key - const client = new Client(process.env.TRAINLOOP_API_KEY || ''); - - // Example messages - const messages = [ - { role: 'system', content: 'System message here' }, - { role: 'user', content: 'Hello from the user!' }, - ]; - - // Send data - const success = await client.sendData( - messages, - SampleFeedbackType.GOOD, - 'test-dataset' - ); - - if (success) { - console.log('Data sent successfully!'); - } else { - console.log('Data was not sent. Check logs for details.'); - } -} - -// Execute the main function -main().catch(error => { - console.error('Unexpected error:', error); -}); From 6020572a670155b599fb5a2891111d0d6c60f4eb Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 19:03:18 -0700 Subject: [PATCH 12/24] ignore .env file --- examples/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/.gitignore b/examples/.gitignore index b792e47..01b03f9 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,2 +1,3 @@ venv -node_modules \ No newline at end of file +node_modules +.env \ No newline at end of file From cf51f0db4e273dfabd745ee4e3907655475e397d Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 19:03:30 -0700 Subject: [PATCH 13/24] fix help text --- examples/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/setup.sh b/examples/setup.sh index 5f1ee35..36cb004 100644 --- a/examples/setup.sh +++ b/examples/setup.sh @@ -36,6 +36,6 @@ go mod tidy cd .. echo "Setup complete! You can now run examples using the following commands:" -echo " npm run run:ts # Run TypeScript example" -echo " npm run run:py # Run Python example" -echo " npm run run:go # Run Go example" +echo " npm run ts:basic # Run TypeScript example" +echo " npm run py:basic # Run Python example" +echo " npm run go:basic # Run Go example" From 438edd271debd32b11996ca4343d01c249884834 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 19:28:50 -0700 Subject: [PATCH 14/24] Bump Python version to 0.1.9 --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 93d114c..2c00a9b 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trainloop-sdk" -version = "0.1.8" +version = "0.1.9" description = "A Data Collection SDK for TrainLoop" authors = [{ name = "TrainLoop", email = "hello@trainloop.ai" }] dependencies = ["requests>=2.32.3"] From cfaa55407e487110ba74b6641b00185061b2d224 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 19:30:32 -0700 Subject: [PATCH 15/24] Bump Python version to 0.1.10 --- python/pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 2c00a9b..69d14d0 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,11 +1,11 @@ [project] name = "trainloop-sdk" -version = "0.1.9" +version = "0.1.10" description = "A Data Collection SDK for TrainLoop" authors = [{ name = "TrainLoop", email = "hello@trainloop.ai" }] dependencies = ["requests>=2.32.3"] urls = { "Homepage" = "https://github.com/trainloop/sdk" } [build-system] -requires = ["setuptools>=42", "wheel", "build>=0.10.0"] +requires = ["setuptools>=42", "wheel", "build>=0.10.0", "twine"] build-backend = "setuptools.build_meta" From 3bd7cc52f34e2accc1bacda7931e3fa9309ad456 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 19:31:28 -0700 Subject: [PATCH 16/24] Add twine to virtual environment for python --- python/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/requirements.txt b/python/requirements.txt index ebc3d31..02b6701 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -17,3 +17,5 @@ tqdm==4.67.1 typing_extensions==4.12.2 urllib3==2.3.0 python-dotenv==1.0.1 +twine +build From 5602acd477ced79f0c19ea7b768fce9080409060 Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Thu, 27 Mar 2025 19:33:08 -0700 Subject: [PATCH 17/24] actually deploy new python version to pypi --- examples/python/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/python/requirements.txt b/examples/python/requirements.txt index 642994e..7a15f9e 100644 --- a/examples/python/requirements.txt +++ b/examples/python/requirements.txt @@ -1,2 +1,2 @@ python-dotenv>=0.21.0 -trainloop-sdk +trainloop-sdk>=0.1.10 From 003a7e0c97e2f202b6b467b19a31b858fcfe792e Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Fri, 4 Apr 2025 17:59:44 -0700 Subject: [PATCH 18/24] loosen definition of messages in all 3 languages --- go/trainloop.go | 8 ++------ python/trainloop/trainloop.py | 2 +- typescript/src/client.ts | 16 ++-------------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/go/trainloop.go b/go/trainloop.go index 950d829..ebbda92 100644 --- a/go/trainloop.go +++ b/go/trainloop.go @@ -40,12 +40,8 @@ func NewClient(apiKey string, baseURL ...string) *Client { } } -// Message represents the messages you’re sending to TrainLoop. -// Adjust fields as required by your system. -type Message struct { - Role string `json:"role"` - Content interface{} `json:"content"` -} +// Message represents a message with string keys and string values. +type Message map[string]string type SampleFeedbackType string diff --git a/python/trainloop/trainloop.py b/python/trainloop/trainloop.py index a914ceb..afd4200 100644 --- a/python/trainloop/trainloop.py +++ b/python/trainloop/trainloop.py @@ -48,7 +48,7 @@ def __init__(self, api_key: str, base_url: str = "https://app.trainloop.ai"): def send_data( self, - messages: List[Dict[str, Union[str, dict]]], + messages: List[Dict[str, str]], sample_feedback: Literal[SampleFeedbackType.BAD, SampleFeedbackType.GOOD], dataset_id: str, ) -> bool: diff --git a/typescript/src/client.ts b/typescript/src/client.ts index aaf579a..2082bc4 100644 --- a/typescript/src/client.ts +++ b/typescript/src/client.ts @@ -8,14 +8,6 @@ export class SampleFeedbackType { static readonly BAD: string = 'bad'; } -/** - * Type for message structure - */ -export interface Message { - role: string; - content: string | object; -} - /** * A client for sending message data to TrainLoop. */ @@ -49,17 +41,13 @@ export class Client { /** * Sends messages and sample feedback to the TrainLoop API. * - * @param messages A list of objects containing role and content, e.g.: - * [ - * { role: "system", content: "..." }, - * { role: "user", content: "..." } - * ] + * @param messages A list of objects containing * @param sampleFeedback A feedback type string, either SampleFeedbackType.GOOD or SampleFeedbackType.BAD * @param datasetId The ID of the dataset to send the data to * @returns A Promise that resolves to true if successful, false otherwise */ async sendData( - messages: Message[], + messages: Record[], sampleFeedback: typeof SampleFeedbackType.GOOD | typeof SampleFeedbackType.BAD, datasetId: string ): Promise { From 498bdec7cf9c8ebb57860f128cc0e71999bbeb5f Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Fri, 4 Apr 2025 18:00:06 -0700 Subject: [PATCH 19/24] Bump Python version to 0.1.11 --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 69d14d0..f794590 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trainloop-sdk" -version = "0.1.10" +version = "0.1.11" description = "A Data Collection SDK for TrainLoop" authors = [{ name = "TrainLoop", email = "hello@trainloop.ai" }] dependencies = ["requests>=2.32.3"] From 1845bcfe644f19567f38035087e66c564dfc3aeb Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Fri, 4 Apr 2025 18:00:14 -0700 Subject: [PATCH 20/24] Bump TypeScript version to 0.1.6 --- typescript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/package.json b/typescript/package.json index 49de7d8..0fab90c 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@trainloop/sdk", - "version": "0.1.5", + "version": "0.1.6", "description": "TypeScript SDK for TrainLoop API", "main": "dist/index.js", "types": "dist/index.d.ts", From 5712d61871716c33d0094b146c4f9be357c0868f Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Fri, 4 Apr 2025 18:00:39 -0700 Subject: [PATCH 21/24] Fix typescript error --- typescript/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/src/index.ts b/typescript/src/index.ts index 6546535..e1bb071 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -1 +1 @@ -export { Client, SampleFeedbackType, Message } from './client'; +export { Client, SampleFeedbackType } from './client'; From a496bdc61aa56907e39269f4af598d339f8c616b Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Fri, 4 Apr 2025 18:01:01 -0700 Subject: [PATCH 22/24] Bump TypeScript version to 0.1.7 --- typescript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/package.json b/typescript/package.json index 0fab90c..b0a846c 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@trainloop/sdk", - "version": "0.1.6", + "version": "0.1.7", "description": "TypeScript SDK for TrainLoop API", "main": "dist/index.js", "types": "dist/index.d.ts", From 74ade3e066430735fbab3eec7d30317c69aea14b Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Fri, 4 Apr 2025 18:03:00 -0700 Subject: [PATCH 23/24] Update sample feedback type --- typescript/src/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/typescript/src/client.ts b/typescript/src/client.ts index 2082bc4..193336f 100644 --- a/typescript/src/client.ts +++ b/typescript/src/client.ts @@ -3,9 +3,9 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; /** * Constants for sample feedback type. */ -export class SampleFeedbackType { - static readonly GOOD: string = 'good'; - static readonly BAD: string = 'bad'; +export enum SampleFeedbackType { + GOOD = 'good', + BAD = 'bad' } /** @@ -48,7 +48,7 @@ export class Client { */ async sendData( messages: Record[], - sampleFeedback: typeof SampleFeedbackType.GOOD | typeof SampleFeedbackType.BAD, + sampleFeedback: SampleFeedbackType, datasetId: string ): Promise { const url = `${this.baseUrl}/api/datasets/collect`; From 5f435eb01141a9ed6ee9d2f954e69b338cd0588d Mon Sep 17 00:00:00 2001 From: mlpierce22 Date: Fri, 4 Apr 2025 18:08:53 -0700 Subject: [PATCH 24/24] Bump TypeScript version to 0.1.8 --- typescript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/package.json b/typescript/package.json index b0a846c..84c518d 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@trainloop/sdk", - "version": "0.1.7", + "version": "0.1.8", "description": "TypeScript SDK for TrainLoop API", "main": "dist/index.js", "types": "dist/index.d.ts",