PipelineRun class - checkpoint()
- TypeScript
- Python
The PipelineRun
class captures the generative output for a unique invocation of a generative pipeline. checkpoint()
is a method under this class.
checkpoint()
checkpoint()
tracks the inputs, outputs, and duration it takes to run a step in a generative pipeline relative to
the last time checkpoint()
was called.
Arguments
inputs
Rather than passing inputs to a measured function, with checkpoint()
you must directly specify the inputs to the step.
outputs
The outputs that you want to track for that checkpoint.
An object containing additional information about the step. The most important key/value pair in the stepInfo
is
the context
key, which attaches more metadata to the step.
Read about the typing for the context
key here.
Examples
typescript
import {init ,Pipeline } from "@gentrace/core";import {initPlugin asinitOpenAIPlugin } from "@gentrace/openai";import {User } from "../models";// This function globally initializes Gentrace with the appropriate// credentials. Constructors like Pipeline() will transparently use// these credentials to authenticate with Gentrace.init ({apiKey :process .env .GENTRACE_API_KEY });constopenaiPlugin = awaitinitOpenAIPlugin ({apiKey :process .env .OPENAI_KEY ,});constpipeline = newPipeline ({slug : "create-embedding",plugins : {openai :openaiPlugin ,pinecone :pineconePlugin },});construnner =pipeline .start ()constopenai =runner .openai ;constuserId = "550e8400-e29b-41d4-a716-446655440000";constgentraceOrgId = "c9a646d3-9c61-4cb7-bfcd-ee2522c8f633";// Custom application logicconstuser = awaitUser .findOne ({where : {id :userId ,orgId :gentraceOrgId ,}});constname =user .name ;runner .checkpoint ({inputs : {userId ,orgId :gentraceOrgId },outputs : {name },});constembeddingResponse = awaitopenai .embeddings .create ({model : 'text-embedding-ada-002',input : `Human, software engineer, Gentrace: ${name }!`,});awaitrunner .submit ();
python
import gentraceimport os# TODO: replace with your own function that you want to benchmark with checkpoint()from db_utils import get_organization_usernamespipeline = gentrace.Pipeline(slug="example-pipeline",openai_config={"api_key": os.environ["OPENAI_API_KEY"],})runner = pipeline.start()usernames = get_organization_usernames(organization_id),runner.checkpoint({"inputs": {"organization_id": organization_id,},"outputs": {"usernames": usernames,},})openai = runner.get_openai()initial_draft_response = openai.ChatCompletion.create(messages=[{"role": "system","content": f"Write an email on behalf of {sender} to the members of organization {organization_name}. These are the names of the members: {usernames.join(", ")}"},],model="gpt-3.5-turbo")initial_draft = initial_draft_response.choices[0].message.contentrunner.submit()return [initial_draft, runner]