Make your DSPy optimizers multi-lingual.
Project description
Optiglot
optiglot is a language-agnostic interface for prompt optimization engines (like DSPy). It allows you to use powerful optimization algorithms implemented in Python with your language/framework of choice via a standardized RPC protocol. By separating the optimization logic from the execution environment, optiglot makes prompt optimizers "polyglots" hence the name.
Installation
TypeScript/JavaScript
Install the harness in your project:
npm install optiglot
# or
bun add optiglot
CLI Engine
Install the optimization engine via uv:
uv tool install optiglot
Core Concepts
- Harnesses: The "glue" that connects your framework (e.g., Vercel AI SDK) to the optimization engine. They handle tracing, evaluation, and communication.
- Predictors: Wrappers around LLM calls that record inputs/outputs for the optimizer.
- Module: A collection of predictors that define your AI system's logic.
- Teleprompt: The optimizer that runs the optimization loop.
Defining an Optimizer
In Optiglot, an optimizer is defined using the Teleprompt class. You specify which algorithm to use and its configuration.
import { Teleprompt } from "optiglot";
const optimizer = new Teleprompt("bootstrap", {
numThreads: 4, // Number of concurrent evaluations
maxIterations: 10, // Maximum optimization cycles
// ... other algorithm-specific options
});
Common optimizers include:
vanilla: Basic few-shot prompting.bootstrap: Bootstraps few-shot examples from your training data.teleprompt: Advanced multi-stage optimization.
The Purpose of Harnesses
Harnesses are essential because they bridge the gap between your application code and the optimization engine. They abstract away three critical tasks:
- Tracing: Automatically recording LLM inputs and outputs during a run so the optimizer can "see" what happened.
- Execution Control: Allowing the optimizer to swap out prompts and re-run your code during evaluation.
- Communication: Handling the RPC handshake between your application and the Python-based optimization engine.
By using a harness, you can optimize your prompts without rewriting your existing application logic in Python.
Usage: AI SDK Harness
Here's how to use the Vercel AI SDK harness to optimize a support ticket classifier.
1. Define Your System (Module)
Create a Module with your predictors. A Predict component wraps your LLM call and manages its instructions.
import { Module, Predict } from "optiglot";
import { openai } from "@ai-sdk/openai";
// Define the system structure
const classifier = new Module({
judge: new Predict(
"Classify the ticket into: Billing, Technical, or General."
),
});
// Define the execution logic
classifier.setForward(async (inputs: { ticket: string }) => {
const { text } = await classifier.judge.generateText({
model: openai("gpt-4o-mini"),
prompt: `Ticket: ${inputs.ticket}`,
});
return text;
});
2. Define Your Metric
The metric scores performance on a specific example. It can return a simple score (0 to 1) or rich feedback.
import { type MetricFunction } from "optiglot";
const metric: MetricFunction = (example, prediction) => {
const isCorrect = example.label === prediction.output;
return {
score: isCorrect ? 1.0 : 0.0,
feedback: isCorrect
? "Correctly labeled."
: `Expected ${example.label} but got ${prediction.output}`,
};
};
3. Run Optimization
Use Teleprompt to optimize the instructions in your module.
import { Teleprompt, Dataset } from "optiglot";
// Load training data
const trainset = new Dataset(
[
{ ticket: "I can't log into my account.", label: "Technical" },
{ ticket: "Where is my order #123?", label: "Billing" },
],
["ticket"] // Fields to pass to the forward function
);
const teleprompter = new Teleprompt("bootstrap");
// Compile: This spawns the optimization engine and finds the best prompts
const optimizedModule = await teleprompter.compile(
classifier,
metric,
trainset
);
console.log("Optimized Instructions:", optimizedModule.judge.instructions);
// Save the optimized state
optimizedModule.save("./optimized_prompts.json");
Appendix
Persistence
You can load optimized prompts back into your module for production use:
const productionModule = new Module({
judge: new Predict(""), // Initial instructions don't matter if we're loading
});
productionModule.load("./optimized_prompts.json");
Development
If you are developing optiglot locally, you can use the OPTIGLOT_DEV=true environment variable to run the engine from source.
OPTIGLOT_DEV=true bun run your_optimization_script.ts
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optiglot-0.1.2.tar.gz.
File metadata
- Download URL: optiglot-0.1.2.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e5fef52012154e873dfa270692a8b9d2033efa5f2f2d35fad70514c7bbceca6
|
|
| MD5 |
6bad1f1ac2a082a80152758321d57ea3
|
|
| BLAKE2b-256 |
746d7277b389c24a6dc0a7f33e0036bdd1b051430e323daf093722d373b94269
|
Provenance
The following attestation bundles were made for optiglot-0.1.2.tar.gz:
Publisher:
publish.yml on modaic-ai/optiglot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optiglot-0.1.2.tar.gz -
Subject digest:
8e5fef52012154e873dfa270692a8b9d2033efa5f2f2d35fad70514c7bbceca6 - Sigstore transparency entry: 820659176
- Sigstore integration time:
-
Permalink:
modaic-ai/optiglot@339df6c5f262e8992d4f31d0ac27495ddbd93f66 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/modaic-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@339df6c5f262e8992d4f31d0ac27495ddbd93f66 -
Trigger Event:
release
-
Statement type:
File details
Details for the file optiglot-0.1.2-py3-none-any.whl.
File metadata
- Download URL: optiglot-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6cb02945afc58d8b3eaa13d80c13d68c35232a77943993869b1f251a125505b
|
|
| MD5 |
e94b0ce5420551c3e46a1a0b4bc2ceeb
|
|
| BLAKE2b-256 |
8ba5c8bcc6116bdcf59324d6ec5d9e2673bcf476ebe391687108cfc44d6af985
|
Provenance
The following attestation bundles were made for optiglot-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on modaic-ai/optiglot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optiglot-0.1.2-py3-none-any.whl -
Subject digest:
a6cb02945afc58d8b3eaa13d80c13d68c35232a77943993869b1f251a125505b - Sigstore transparency entry: 820659178
- Sigstore integration time:
-
Permalink:
modaic-ai/optiglot@339df6c5f262e8992d4f31d0ac27495ddbd93f66 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/modaic-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@339df6c5f262e8992d4f31d0ac27495ddbd93f66 -
Trigger Event:
release
-
Statement type: