Skip to content

chore(py): flatten prompt opts to kwargs#5062

Merged
huangjeff5 merged 4 commits intomainfrom
jh-flatten-prompt-opts
Apr 6, 2026
Merged

chore(py): flatten prompt opts to kwargs#5062
huangjeff5 merged 4 commits intomainfrom
jh-flatten-prompt-opts

Conversation

@huangjeff5
Copy link
Copy Markdown
Contributor

@huangjeff5 huangjeff5 commented Apr 3, 2026

Previously, callers had to bundle generation options into a single opts dict:

response = await prompt(input, opts={"model": "...", "config": {...}})

This PR flattens those options into keyword arguments using Unpack[PromptGenerateOptions]:

response = await prompt(input, model="...", config={...})

This way we still have a shared type for the stream/non-streaming path, but the syntax is more pythonic (using kwargs instead of an opts dict), and all the various prompt options should surface correctly inline in the IDE (as opposed to being hidden behind an opaque type where you have to further inspect to see the real fields).

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the ExecutablePrompt API to transition from a single opts dictionary to using keyword arguments for generation options, leveraging Unpack[PromptGenerateOptions] for type safety. The implementation introduces internal helper methods _call_impl and _render_impl to consolidate logic, along with a _coerce_prompt_opts utility that validates input and provides explicit error messages if the deprecated opts parameter is used. Corresponding test cases have been updated and expanded to verify the new keyword-based interface and the removal of the legacy parameter. I have no feedback to provide.

@huangjeff5 huangjeff5 requested review from apascal07 and pavelgj April 3, 2026 19:42
@huangjeff5 huangjeff5 merged commit 301db01 into main Apr 6, 2026
19 checks passed
@huangjeff5 huangjeff5 deleted the jh-flatten-prompt-opts branch April 6, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants