Skip to content
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

Optional values in @llm.ai_callable cause ValueError #1185

Closed
FiddlersCode opened this issue Dec 6, 2024 · 1 comment
Closed

Optional values in @llm.ai_callable cause ValueError #1185

FiddlersCode opened this issue Dec 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@FiddlersCode
Copy link

How to replicate

  1. Set tool call params as below:
  2. LLM sets this parameter to None
@llm.ai_callable(
    description="""
    "Returns a list of transactions during a specified period and filters...blah blah
    """
)
async def a_tool_call(
    self,
    start_date: Annotated[
        Optional[str],
        llm.TypeInfo(
            description="""
                The start date in the format %Y-%m-%d, 
                for example, 2020-09-01 for 1st September 2020.
                If you don't think this field is relevant for the question then set this parameter to None.
                """
        ),
    ] = None,
...more parameters

Expected behaviour
Tool call proceeds as usual with None set as a parameter

Actual behaviour
We receive the following error message and the tool call is now able to proceed

2024-11-29 17:34:13,600 - ERROR livekit.plugins.openai.realtime - failed to handle OpenAI S2S message
Traceback (most recent call last):
  File "/Users/paula.muldoon/dev/ai/ai-livekit-agent/.venv/lib/python3.11/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1038, in _recv_task
    self._handle_response_output_item_done(data)
  File "/Users/paula.muldoon/dev/ai/ai-livekit-agent/.venv/lib/python3.11/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1341, in _handle_response_output_item_done
    fnc_call_info = _oai_api.create_ai_function_info(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/paula.muldoon/dev/ai/ai-livekit-agent/.venv/lib/python3.11/site-packages/livekit/agents/llm/_oai_api.py", line 72, in create_ai_function_info
    sanitized_value = _sanitize_primitive(
                      ^^^^^^^^^^^^^^^^^^^^
  File "/Users/paula.muldoon/dev/ai/ai-livekit-agent/.venv/lib/python3.11/site-packages/livekit/agents/llm/_oai_api.py", line 148, in _sanitize_primitive
    raise ValueError(f"expected str, got {type(value)}")

ValueError: expected str, got <class 'NoneType'>

I've managed to print out these lines from livekit/agents/llm/_oai_api.py
line 50:


         arg_value = parsed_arguments[arg_info.name]
        print(f"arg info: {arg_info.name}")
        print(f"arg value: {arg_value}")
        print(f"arg type: {arg_info.type}")

and the result is:

arg info: start_date
arg value: None
arg type: <class 'str'>

Versions
livekit = "0.18.1"
livekit-agents = "0.11.3"
livekit-plugins-openai = "0.10.7"
livekit-protocol = "0.7.0"

@davidzhao
Copy link
Member

fixed in #1211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants