PipelineRun class - measure()
- TypeScript
- Python
The PipelineRun
class captures the generative output for a unique invocation of a generative pipeline. measure()
is a method under this class.
measure()
measure()
tracks the inputs, outputs and duration it takes to run a step in a generative pipeline.
Arguments
func
The asynchronous function to measure. The function can take any number of parameters.
inputs
The parameters to the function. The inputs are passed to the function as arguments.
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.
Return value
The return value of the function passed to measure()
.
Examples
typescript
import {Pipeline } from '@gentrace/core';import {User } from "../models";constpipeline = newPipeline ({slug : "example-pipeline",});construnner =pipeline .start ();constuserId = "550e8400-e29b-41d4-a716-446655440000";constgentraceOrgId = "c9a646d3-9c61-4cb7-bfcd-ee2522c8f633";constname = awaitrunner .measure (async (userId ,gentraceOrgId ) => {// Custom application logicconstuser = awaitUser .findOne ({where : {id :userId ,orgId :gentraceOrgId ,}})returnuser .name },// Inputs must be passed via a dependency array, so Gentrace// can properly trace the data.[userId ,gentraceOrgId ],);
python
import gentraceimport os# TODO: replace with your own function that you want to measurefrom db_utils import get_organization_usernamespipeline = gentrace.Pipeline(slug="example-pipeline",openai_config={"api_key": os.environ["OPENAI_API_KEY"],})runner = pipeline.start()usernames = runner.measure(get_organization_usernames,org_id=organization_id,)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]