Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/check_license
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ $HOME/go/bin/addlicense \
-ignore '**/pnpm-lock.yaml' \
-ignore '.nx/**/*' \
-ignore '.trunk/**/*' \
-ignore '**/*.toml' \
-ignore '**/*.nix' \
"$TOP_DIR"

uv run --directory "${PY_DIR}" liccheck
2 changes: 2 additions & 0 deletions genkit-tools/common/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,7 @@ export const GenerateActionOptionsSchema = z.object({
returnToolRequests: z.boolean().optional(),
/** Maximum number of tool call iterations that can be performed in a single generate call (default 5). */
maxTurns: z.number().optional(),
/** Custom step name for this generate call to display in trace views. Defaults to "generate". */
stepName: z.string().optional(),
});
export type GenerateActionOptions = z.infer<typeof GenerateActionOptionsSchema>;
3 changes: 3 additions & 0 deletions genkit-tools/genkit-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@
},
"maxTurns": {
"type": "number"
},
"stepName": {
"type": "string"
}
},
"required": [
Expand Down
3 changes: 3 additions & 0 deletions js/ai/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export interface GenerateOptions<
context?: ActionContext;
/** Abort signal for the generate request. */
abortSignal?: AbortSignal;
/** Custom step name for this generate call to display in trace views. Defaults to "generate". */
stepName?: string;
/**
* Additional metadata describing the GenerateOptions, used by tooling. If
* this is an instance of a rendered dotprompt, will contain any prompt
Expand Down Expand Up @@ -500,6 +502,7 @@ export async function toGenerateActionOptions<
},
returnToolRequests: options.returnToolRequests,
maxTurns: options.maxTurns,
stepName: options.stepName,
};
// if config is empty and it was not explicitly passed in, we delete it, don't want {}
if (Object.keys(params.config).length === 0 && !options.config) {
Expand Down
4 changes: 2 additions & 2 deletions js/ai/src/generate/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ export async function generateHelper(
registry,
{
metadata: {
name: 'generate',
name: options.rawRequest.stepName || 'generate',
},
labels: {
[SPAN_TYPE_ATTR]: 'util',
},
},
async (metadata) => {
metadata.name = 'generate';
metadata.name = options.rawRequest.stepName || 'generate';
metadata.input = options.rawRequest;
const output = await generate(registry, {
rawRequest: options.rawRequest,
Expand Down
2 changes: 2 additions & 0 deletions js/ai/src/model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,5 +406,7 @@ export const GenerateActionOptionsSchema = z.object({
returnToolRequests: z.boolean().optional(),
/** Maximum number of tool call iterations that can be performed in a single generate call (default 5). */
maxTurns: z.number().optional(),
/** Custom step name for this generate call to display in trace views. Defaults to "generate". */
stepName: z.string().optional(),
});
export type GenerateActionOptions = z.infer<typeof GenerateActionOptionsSchema>;
23 changes: 23 additions & 0 deletions js/ai/tests/generate/generate_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,27 @@ describe('generate', () => {
);
});
});

it('should use custom stepName parameter in tracing', async () => {
const response = await generate(registry, {
model: 'echo',
prompt: 'Testing custom step name',
stepName: 'test-generate-custom',
});
assert.deepEqual(
response.messages.map((m) => m.content[0].text),
['Testing custom step name', 'Testing custom step name']
);
});

it('should default to "generate" name when no stepName is provided', async () => {
const response = await generate(registry, {
model: 'echo',
prompt: 'Testing default step name',
});
assert.deepEqual(
response.messages.map((m) => m.content[0].text),
['Testing default step name', 'Testing default step name']
);
});
});
1 change: 1 addition & 0 deletions js/testapps/basic-gemini/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const jokeFlow = ai.defineFlow(
},
async () => {
const llmResponse = await ai.generate({
stepName: 'joke-creator',
model: gemini15Flash,
config: {
temperature: 2,
Expand Down
1 change: 1 addition & 0 deletions py/packages/genkit/src/genkit/core/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ class GenerateActionOptions(BaseModel):
resume: Resume | None = None
return_tool_requests: bool | None = Field(None, alias='returnToolRequests')
max_turns: float | None = Field(None, alias='maxTurns')
step_name: str | None = Field(None, alias='stepName')


class GenerateRequest(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


"""OpenAI OpenAI API Compatible Plugin for Genkit."""

from functools import cached_property
from typing import Any, Callable

Expand Down Expand Up @@ -172,17 +173,17 @@ def _define_openai_model(self, ai: GenkitRegistry, name: str) -> None:
def list_actions(self) -> list[ActionMetadata]:
"""Generate a list of available actions or models.

Returns:
list[ActionMetadata]: A list of ActionMetadata objects, each with the following attributes:
- name (str): The name of the action or model.
- kind (ActionKind): The type or category of the action.
- info (dict): The metadata dictionary describing the model configuration and properties.
- config_schema (type): The schema class used for validating the model's configuration.
Returns:
list[ActionMetadata]: A list of ActionMetadata objects, each with the following attributes:
- name (str): The name of the action or model.
- kind (ActionKind): The type or category of the action.
- info (dict): The metadata dictionary describing the model configuration and properties.
- config_schema (type): The schema class used for validating the model's configuration.
"""

actions = []
models_ = self._openai_client.models.list()
models: list[Model] = models_.data
models: list[Model] = models_.data
# Print each model
for model in models:
_name = model.id
Expand Down Expand Up @@ -216,8 +217,6 @@ def list_actions(self) -> list[ActionMetadata]:
return actions




def openai_model(name: str) -> str:
"""Returns a string representing the OpenAI model name to use with Genkit.

Expand Down
4 changes: 2 additions & 2 deletions py/plugins/compat-oai/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_openai_plugin_list_actions() -> None:
Model(id='gpt-3.5-turbo', created=1677610602, object='model', owned_by='openai'),
Model(id='o4-mini-deep-research-2025-06-26', created=1750866121, object='model', owned_by='system'),
Model(id='codex-mini-latest', created=1746673257, object='model', owned_by='system'),
Model(id='text-embedding-ada-002', created=1671217299, object='model', owned_by='openai-internal')
Model(id='text-embedding-ada-002', created=1671217299, object='model', owned_by='openai-internal'),
]
plugin = OpenAI(api_key='test-key')
mock_client = MagicMock()
Expand All @@ -94,7 +94,7 @@ def test_openai_plugin_list_actions() -> None:

plugin._openai_client = mock_client

actions: list[ActionMetadata ] = plugin.list_actions
actions: list[ActionMetadata] = plugin.list_actions
mock_client.models.list.assert_called_once()
_ = plugin.list_actions
mock_client.models.list.assert_called_once()
Expand Down
Loading