forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PromptLab templating (mlflow#10341)
Signed-off-by: Daniel Lok <[email protected]>
- Loading branch information
1 parent
4194122
commit 3e850ef
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from unittest import mock | ||
|
||
import pandas as pd | ||
|
||
from mlflow._promptlab import _PromptlabModel | ||
from mlflow.entities.param import Param | ||
|
||
|
||
def test_promptlab_prompt_replacement(): | ||
data = pd.DataFrame( | ||
data=[ | ||
{"thing": "books"}, | ||
{"thing": "coffee"}, | ||
{"thing": "nothing"}, | ||
] | ||
) | ||
|
||
prompt_parameters = [Param(key="thing", value="books")] | ||
model_parameters = [Param(key="temperature", value=0.5), Param(key="max_tokens", value=10)] | ||
prompt_template = "Write me a story about {{ thing }}." | ||
model_route = "completions" | ||
|
||
model = _PromptlabModel(prompt_template, prompt_parameters, model_parameters, model_route) | ||
with mock.patch("mlflow.gateway.query") as mock_query: | ||
model.predict(data) | ||
|
||
calls = [ | ||
mock.call( | ||
route="completions", | ||
data={ | ||
"prompt": f"Write me a story about {thing}.", | ||
"temperature": 0.5, | ||
"max_tokens": 10, | ||
}, | ||
) | ||
for thing in data["thing"] | ||
] | ||
|
||
mock_query.assert_has_calls(calls, any_order=True) |