-
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.
Add customization options to scenario
- Loading branch information
Showing
10 changed files
with
328 additions
and
197 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
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 |
---|---|---|
@@ -1,39 +1,43 @@ | ||
from os import environ | ||
from typing import Annotated | ||
from typing import Annotated, Callable | ||
|
||
import requests | ||
|
||
|
||
def send_msg_to_model( | ||
msg: Annotated[str, "The message content to be sent to the model."], | ||
) -> str: | ||
"""Sends a message to a model endpoint specified in the configuration. | ||
def create_send_msg_to_model( | ||
_url: str, | ||
_token: str, | ||
) -> Callable[[str], str]: | ||
def send_msg_to_model( | ||
msg: Annotated[str, "The message content to be sent to the model."], | ||
) -> str: | ||
"""Sends a message to a model endpoint specified in the configuration. | ||
Args: | ||
msg (str): The message content to be sent to the model. | ||
config (Config, optional): Configuration object containing 'url' and 'token'. Defaults to a global config. | ||
Args: | ||
msg (str): The message content to be sent to the model. | ||
config (Config, optional): Configuration object containing 'url' and 'token'. Defaults to a global config. | ||
Returns: | ||
str: The response content from the model. | ||
Returns: | ||
str: The response content from the model. | ||
Raises: | ||
ValueError: If the URL or token is not provided in the config. | ||
requests.exceptions.HTTPError: If the HTTP request returned an unsuccessful status code. | ||
""" | ||
url = environ.get("TESTED_MODEL_URL", "") | ||
token = environ.get("TESTED_MODEL_TOKEN", "") | ||
Raises: | ||
requests.exceptions.HTTPError: If the HTTP request returned an unsuccessful status code. | ||
""" | ||
url = _url | ||
token = _token | ||
|
||
if not url or not token: | ||
raise ValueError("URL and token must be in environment variables") | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
"Content-type": "application/json", | ||
} | ||
|
||
headers = {"Authorization": f"Bearer {token}", "Content-type": "application/json"} | ||
data = {"messages": [{"role": "user", "content": msg}]} | ||
|
||
data = {"messages": [{"role": "user", "content": msg}]} | ||
response = requests.post(url, headers=headers, json=data, timeout=30) | ||
response.raise_for_status() # Ensure we raise an error for bad responses | ||
model_response = response.json().get("content") | ||
if not model_response: | ||
raise ValueError("No 'content' field found in API response") | ||
|
||
response = requests.post(url, headers=headers, json=data, timeout=30) | ||
response.raise_for_status() # Ensure we raise an error for bad responses | ||
model_response = response.json().get("content") | ||
if not model_response: | ||
raise ValueError("No 'content' field found in API response") | ||
return model_response # type: ignore | ||
|
||
return model_response # type: ignore | ||
return send_msg_to_model |
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
Oops, something went wrong.