41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { describe, it } from "vitest";
|
|
import { TensorZeroClient } from "../tensorzero/tensorzero";
|
|
import { createFilters } from "./client";
|
|
|
|
const gatewayUrl = process.env.TENSORZERO_GATEWAY_URL;
|
|
if (!gatewayUrl) {
|
|
throw new Error("TENSORZERO_GATEWAY_URL is not set");
|
|
}
|
|
const client = new TensorZeroClient(gatewayUrl);
|
|
|
|
describe("sft via HTTP client", () => {
|
|
// NOTE: This test hits a fake server so you can run it anytime without paying OpenAI
|
|
it("should launch a job and poll it", async () => {
|
|
const metric = "exact_match";
|
|
const threshold = 0.9; // irrelevant
|
|
const filters = await createFilters(metric, threshold);
|
|
const job = await client.experimentalLaunchOptimizationWorkflow({
|
|
function_name: "extract_entities",
|
|
template_variant_name: "baseline",
|
|
filters: filters,
|
|
output_source: "inference",
|
|
limit: 100,
|
|
offset: 0,
|
|
val_fraction: 0.1,
|
|
optimizer_config: {
|
|
type: "openai_sft",
|
|
model: "gpt-4o-mini",
|
|
batch_size: 1,
|
|
learning_rate_multiplier: 1,
|
|
n_epochs: 1,
|
|
},
|
|
});
|
|
|
|
let status = await client.experimentalPollOptimization(job);
|
|
while (status.status !== "completed") {
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
status = await client.experimentalPollOptimization(job);
|
|
}
|
|
}, 10000); // timeout in ms
|
|
});
|