-
Notifications
You must be signed in to change notification settings - Fork 530
feat(py): Added the render user prompt to the render method of the executable prompt class #3705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hendrixmar
wants to merge
8
commits into
main
Choose a base branch
from
hendrixmar/feature/add-render-user-prompt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,982
−1,852
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
31879e1
feat(py): Addede the render user prompt to the render method of the e…
hendrixmar ad9dc47
chore: added context rendering in the templates
hendrixmar 95bdc56
chore: fix uv dependencies
hendrixmar 3120622
chore: fix GitHub actions schema typing pipeline error
hendrixmar 8b94795
chore: fix GitHub actions schema typing pipeline error
hendrixmar a3e2508
chore: fix GitHub actions schema typing pipeline error
hendrixmar 7e71d1a
chore: fix GitHub actions schema typing pipeline error
hendrixmar 76e0c3f
chore: disabled dotprompt rendering due issue with the CI
hendrixmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
|
||
"""Tests for the action module.""" | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
|
@@ -124,7 +125,7 @@ def test_tool(input: ToolInput): | |
tools=['testTool'], | ||
tool_choice=ToolChoice.REQUIRED, | ||
max_turns=5, | ||
input_schema=PromptInput, | ||
input_schema=PromptInput.model_json_schema(), | ||
output_constrained=True, | ||
output_format='json', | ||
description='a prompt descr', | ||
|
@@ -143,45 +144,84 @@ def test_tool(input: ToolInput): | |
|
||
test_cases_parse_partial_json = [ | ||
( | ||
"renders user prompt", | ||
'renders system prompt', | ||
{ | ||
"model": "echoModel", | ||
"config": {"banana": "ripe"}, | ||
"input_schema": { | ||
'model': 'echoModel', | ||
'config': {'banana': 'ripe'}, | ||
'input_schema': { | ||
'type': 'object', | ||
'properties': { | ||
'name': {'type': 'string'}, | ||
}, | ||
}, # Note: Schema representation might need adjustment | ||
"system": "hello {{name}} ({{@state.name}})", | ||
"metadata": {"state": {"name": "bar"}} | ||
'system': 'hello {{name}} ({{@state.name}})', | ||
'metadata': {'state': {'name': 'bar'}}, | ||
}, | ||
{"name": "foo"}, | ||
GenerationCommonConfig.model_validate({"temperature": 11}), | ||
"""[ECHO] system: "hello foo ()" {"temperature":11.0}""" | ||
) | ||
{'name': 'foo'}, | ||
GenerationCommonConfig.model_validate({'temperature': 11}), | ||
{}, | ||
"""[ECHO] system: "hello foo (bar)" {"temperature":11.0}""", | ||
), | ||
( | ||
'renders user prompt', | ||
{ | ||
'model': 'echoModel', | ||
'config': {'banana': 'ripe'}, | ||
'input_schema': { | ||
'type': 'object', | ||
'properties': { | ||
'name': {'type': 'string'}, | ||
}, | ||
}, # Note: Schema representation might need adjustment | ||
'prompt': 'hello {{name}} ({{@state.name}})', | ||
'metadata': {'state': {'name': 'bar_system'}}, | ||
}, | ||
{'name': 'foo'}, | ||
GenerationCommonConfig.model_validate({'temperature': 11}), | ||
{}, | ||
"""[ECHO] user: "hello foo (bar_system)" {"temperature":11.0}""", | ||
), | ||
( | ||
'renders user prompt with context', | ||
{ | ||
'model': 'echoModel', | ||
'config': {'banana': 'ripe'}, | ||
'input_schema': { | ||
'type': 'object', | ||
'properties': { | ||
'name': {'type': 'string'}, | ||
}, | ||
}, # Note: Schema representation might need adjustment | ||
'prompt': 'hello {{name}} ({{@state.name}}, {{@auth.email}})', | ||
'metadata': {'state': {'name': 'bar'}}, | ||
}, | ||
{'name': 'foo'}, | ||
GenerationCommonConfig.model_validate({'temperature': 11}), | ||
{'auth': {'email': '[email protected]'}}, | ||
"""[ECHO] user: "hello foo (bar, [email protected])" {"temperature":11.0}""", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.skip(reason="issues when running on CI") | ||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
'test_case, prompt, input, input_option, want_rendered', | ||
'test_case, prompt, input, input_option, context, want_rendered', | ||
test_cases_parse_partial_json, | ||
ids=[tc[0] for tc in test_cases_parse_partial_json], | ||
) | ||
async def test_prompt_with_system( | ||
async def test_prompt_rendering_dotprompt( | ||
test_case: str, | ||
prompt: dict[str, Any], | ||
input: dict[str, Any], | ||
input_option: GenerationCommonConfig, | ||
want_rendered: str | ||
context: dict[str, Any], | ||
want_rendered: str, | ||
) -> None: | ||
"""Test system prompt rendering.""" | ||
"""Test prompt rendering.""" | ||
ai, *_ = setup_test() | ||
|
||
my_prompt = ai.define_prompt(**prompt) | ||
|
||
response = await my_prompt(input, input_option) | ||
response = await my_prompt(input, input_option, context=context) | ||
|
||
assert response.text == want_rendered | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are some failing tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pavelgj Talking with @yesudeep we realize that we realize there is an issue running the dotprompt in CI. Because locally it runs without any issue, but in the CI it always has the same error. So we decided to disable the unit test momentarily until we figured out how to fix that issue