File tree Expand file tree Collapse file tree 9 files changed +39
-2
lines changed
testapps/basic-gemini/src
py/packages/genkit/src/genkit/core Expand file tree Collapse file tree 9 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ $HOME/go/bin/addlicense \
6161 -ignore ' **/pnpm-lock.yaml' \
6262 -ignore ' .nx/**/*' \
6363 -ignore ' .trunk/**/*' \
64+ -ignore ' **/*.toml' \
65+ -ignore ' **/*.nix' \
6466 " $TOP_DIR "
6567
6668uv run --directory " ${PY_DIR} " liccheck
Original file line number Diff line number Diff line change @@ -403,5 +403,7 @@ export const GenerateActionOptionsSchema = z.object({
403403 returnToolRequests : z . boolean ( ) . optional ( ) ,
404404 /** Maximum number of tool call iterations that can be performed in a single generate call (default 5). */
405405 maxTurns : z . number ( ) . optional ( ) ,
406+ /** Custom step name for this generate call to display in trace views. Defaults to "generate". */
407+ stepName : z . string ( ) . optional ( ) ,
406408} ) ;
407409export type GenerateActionOptions = z . infer < typeof GenerateActionOptionsSchema > ;
Original file line number Diff line number Diff line change 735735 },
736736 "maxTurns" : {
737737 "type" : " number"
738+ },
739+ "stepName" : {
740+ "type" : " string"
738741 }
739742 },
740743 "required" : [
Original file line number Diff line number Diff line change @@ -169,6 +169,8 @@ export interface GenerateOptions<
169169 context ?: ActionContext ;
170170 /** Abort signal for the generate request. */
171171 abortSignal ?: AbortSignal ;
172+ /** Custom step name for this generate call to display in trace views. Defaults to "generate". */
173+ stepName ?: string ;
172174 /**
173175 * Additional metadata describing the GenerateOptions, used by tooling. If
174176 * this is an instance of a rendered dotprompt, will contain any prompt
@@ -495,6 +497,7 @@ export async function toGenerateActionOptions<
495497 } ,
496498 returnToolRequests : options . returnToolRequests ,
497499 maxTurns : options . maxTurns ,
500+ stepName : options . stepName ,
498501 } ;
499502 // if config is empty and it was not explicitly passed in, we delete it, don't want {}
500503 if ( Object . keys ( params . config ) . length === 0 && ! options . config ) {
Original file line number Diff line number Diff line change @@ -123,14 +123,14 @@ export async function generateHelper(
123123 registry ,
124124 {
125125 metadata : {
126- name : 'generate' ,
126+ name : options . rawRequest . stepName || 'generate' ,
127127 } ,
128128 labels : {
129129 [ SPAN_TYPE_ATTR ] : 'util' ,
130130 } ,
131131 } ,
132132 async ( metadata ) => {
133- metadata . name = 'generate' ;
133+ metadata . name = options . rawRequest . stepName || 'generate' ;
134134 metadata . input = options . rawRequest ;
135135 const output = await generate ( registry , {
136136 rawRequest : options . rawRequest ,
Original file line number Diff line number Diff line change @@ -406,5 +406,7 @@ export const GenerateActionOptionsSchema = z.object({
406406 returnToolRequests : z . boolean ( ) . optional ( ) ,
407407 /** Maximum number of tool call iterations that can be performed in a single generate call (default 5). */
408408 maxTurns : z . number ( ) . optional ( ) ,
409+ /** Custom step name for this generate call to display in trace views. Defaults to "generate". */
410+ stepName : z . string ( ) . optional ( ) ,
409411} ) ;
410412export type GenerateActionOptions = z . infer < typeof GenerateActionOptionsSchema > ;
Original file line number Diff line number Diff line change @@ -571,4 +571,27 @@ describe('generate', () => {
571571 ) ;
572572 } ) ;
573573 } ) ;
574+
575+ it ( 'should use custom stepName parameter in tracing' , async ( ) => {
576+ const response = await generate ( registry , {
577+ model : 'echo' ,
578+ prompt : 'Testing custom step name' ,
579+ stepName : 'test-generate-custom' ,
580+ } ) ;
581+ assert . deepEqual (
582+ response . messages . map ( ( m ) => m . content [ 0 ] . text ) ,
583+ [ 'Testing custom step name' , 'Testing custom step name' ]
584+ ) ;
585+ } ) ;
586+
587+ it ( 'should default to "generate" name when no stepName is provided' , async ( ) => {
588+ const response = await generate ( registry , {
589+ model : 'echo' ,
590+ prompt : 'Testing default step name' ,
591+ } ) ;
592+ assert . deepEqual (
593+ response . messages . map ( ( m ) => m . content [ 0 ] . text ) ,
594+ [ 'Testing default step name' , 'Testing default step name' ]
595+ ) ;
596+ } ) ;
574597} ) ;
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ export const jokeFlow = ai.defineFlow(
4040 } ,
4141 async ( ) => {
4242 const llmResponse = await ai . generate ( {
43+ stepName : 'joke-creator' ,
4344 model : gemini15Flash ,
4445 config : {
4546 temperature : 2 ,
Original file line number Diff line number Diff line change @@ -920,6 +920,7 @@ class GenerateActionOptions(BaseModel):
920920 resume : Resume | None = None
921921 return_tool_requests : bool | None = Field (None , alias = 'returnToolRequests' )
922922 max_turns : float | None = Field (None , alias = 'maxTurns' )
923+ step_name : str | None = Field (None , alias = 'stepName' )
923924
924925
925926class GenerateRequest (BaseModel ):
You can’t perform that action at this time.
0 commit comments