You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromdotenvimportload_dotenvfrommirascope.openaiimportOpenAICall, OpenAICallParamsload_dotenv()
deflist_design_option_values_sorted_by_sales_metric(
design_option: str,
time_range_start: str,
time_range_end: str,
sales_metric: str="TotalUnitsSold",
asc: bool=False,
):
""" Lists pattern design option values sorted by their sales metric in ascending or descending order. Top 5 design option values fetched from the Postgres database will be returned along with their sales metric. Less than 5 design option values will be returned if there are less than 5 values. Do not call this function again with the same arguments if you receive less than 5 values. Args: design_option: The design option to query. MUST be one of the following values: - "shoulderSeam" - "necklineStyle" - "necklineStyle.crewNeck.crewNeckWidth" - "necklineStyle.crewNeck.neckFinish" - "productLength" - "productLength.hip.level" - "frontHem" - "frontHem.straight.hemFoldBack" - "backHem" - "backHem.straight.hemFoldBack" - "slitDepth" - "pocket" - "sleeveLength" - "sleeveFabric" - "sleeveHem" - "sleeveHem.regular.sleeveHemFoldBack" - "bodyFit" - "shoulderFit" - "silhouette" - "sleeveFit" time_range_start: The start of the time range to filter sales by e.g., "2023-01-01 00:00:00+00". time_range_end: The end of the time range to filter sales by e.g., "2024-01-01 00:00:00+00". sales_metric: Sales metric to sort by. Can be "UnitsSoldFullPrice", "RevenueFullPrice", "UnitsSoldDiscounted", "RevenueDiscounted", "TotalUnitsSold", or "TotalRevenue". Default is "TotalUnitsSold". asc: Whether to sort the results in ascending order. Default is False (descending order). Raises: ValueError: If invalid design_option or sales_metric is provided. """print(
"The values are:",
design_option,
time_range_start,
time_range_end,
sales_metric,
asc,
)
classLLM(OpenAICall):
prompt: strprompt_template="{prompt}"call_params=OpenAICallParams(
model="gpt-4o",
tools=[list_design_option_values_sorted_by_sales_metric],
temperature=0.0,
)
llm=LLM(prompt="call the list tool with random parameter values. don't ask me anything.")
response=llm.call()
iftool:=response.tool:
print(tool.args)
tool.call()
else:
print(response.content)
You will notice that the code runs successfully. Here's the output:
fromdotenvimportload_dotenvfrommirascope.coreimportopenaiload_dotenv()
deflist_design_option_values_sorted_by_sales_metric(
design_option: str,
time_range_start: str,
time_range_end: str,
sales_metric: str="TotalUnitsSold",
asc: bool=False,
):
""" Lists pattern design option values sorted by their sales metric in ascending or descending order. Top 5 design option values fetched from the Postgres database will be returned along with their sales metric. Less than 5 design option values will be returned if there are less than 5 values. Do not call this function again with the same arguments if you receive less than 5 values. Args: design_option: The design option to query. MUST be one of the following values: - "shoulderSeam" - "necklineStyle" - "necklineStyle.crewNeck.crewNeckWidth" - "necklineStyle.crewNeck.neckFinish" - "productLength" - "productLength.hip.level" - "frontHem" - "frontHem.straight.hemFoldBack" - "backHem" - "backHem.straight.hemFoldBack" - "slitDepth" - "pocket" - "sleeveLength" - "sleeveFabric" - "sleeveHem" - "sleeveHem.regular.sleeveHemFoldBack" - "bodyFit" - "shoulderFit" - "silhouette" - "sleeveFit" time_range_start: The start of the time range to filter sales by e.g., "2023-01-01 00:00:00+00". time_range_end: The end of the time range to filter sales by e.g., "2024-01-01 00:00:00+00". sales_metric: Sales metric to sort by. Can be "UnitsSoldFullPrice", "RevenueFullPrice", "UnitsSoldDiscounted", "RevenueDiscounted", "TotalUnitsSold", or "TotalRevenue". Default is "TotalUnitsSold". asc: Whether to sort the results in ascending order. Default is False (descending order). Raises: ValueError: If invalid design_option or sales_metric is provided. """print(
"The values are:",
design_option,
time_range_start,
time_range_end,
sales_metric,
asc,
)
@openai.call("gpt-4o",tools=[list_design_option_values_sorted_by_sales_metric],call_params={"temperature": 0},)defllm(prompt: str):
returnpromptresponse=llm("call the tool with random parameter values. don't ask me anything.")
iftool:=response.tool:
print(tool.args)
tool.call()
else:
print(response.content)
Running the code will result in this error:
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'tools[0].function.description': string too long. Expected a string with maximum length 1024, but got a string with length 1628 instead.", 'type': 'invalid_request_error', 'param': 'tools[0].function.description', 'code': 'string_above_max_length'}}
Python, Mirascope & OS Versions, related packages (not required)
The 1024 limit is imposed by OpenAI. The reason this worked in v0 and doesn't work in v1 is that in v0 we only used the short/long description and dropped everything else (but in v1 we just use the original docstring).
I've implemented a fix for this that drops args/examples from the tool description so that they don't count against that limit.
Description
This is the code for Mirascope v0:
You will notice that the code runs successfully. Here's the output:
This is the code for Mirascope v1:
Running the code will result in this error:
Python, Mirascope & OS Versions, related packages (not required)
Requirements for v0:
Requirements for v1:
The text was updated successfully, but these errors were encountered: