-
Notifications
You must be signed in to change notification settings - Fork 507
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
OpenAI agent cannot properly parse various complex function argument types #1208
Comments
fixed in #1211 |
Unfortunately the above change does not completely fix the original issue. The build_oai_function_description function remains the same and is still unable to parse optional type definitions. It would be great to have an actual unit test that verifies parsing of above cases and confirms the actual fix. |
I’m unable to reproduce this issue. Could you please share the parameters you're passing or a screenshot of the error you're encountering?
I believe these cases are already handled in this function: agents/livekit-agents/livekit/agents/llm/function_context.py Lines 291 to 307 in 6b4e903
cc: @theomonnom |
thanks for your reply @jayeshp19 I expect the below unit tests to pass (currently some of them fail): import pytest
from typing import Union, Optional
from inspect import _empty
from livekit.agents.llm import FunctionInfo, FunctionArgInfo
from livekit.agents.llm.function_context import _is_optional_type
from livekit.agents import llm
def test_typing():
assert _is_optional_type(Optional[int]) == (True, int)
assert _is_optional_type(Union[str, None]) == (True, str)
assert _is_optional_type(None | float) == (True, float)
assert _is_optional_type(Union[str, int]) == (False, None)
@pytest.mark.parametrize(
("arg_typ", "oai_type"),
[
(int, "number"),
(Optional[int], ["number", "null"]),
(None | int, ["number", "null"]),
(Union[None, int], ["number", "null"]),
(Union[str, None], ["string", "null"]),
]
)
def test_description_building(arg_typ: type, oai_type: str | list[str]):
fi = FunctionInfo(
name='foo',
description='foo',
auto_retry=False,
callable=lambda: None,
arguments={
'arg': FunctionArgInfo(
name='foo',
description='foo',
type=arg_typ,
default=_empty,
choices=(),
),
}
)
assert llm._oai_api.build_oai_function_description(
fi
)['function']['parameters']['properties']['foo']['type'] == oai_type |
Steps to reproduce:
agents/examples/multimodal_agent.py
Line 29 in c5897c1
Optional[str]
orUnion[int, type(None)]
orfloat | None
Actual result:
An exception stack trace is raised because the build_oai_function_description type support is limited to only (str, int, float, bool), even though the FunctionContext class is capable of recognizing the above nullable types.
Expected result:
The
build_oai_function_description
mentioned above should be able to properly parse nullable types like ones above.For example, we expect
Optional[str]
to be transformed into["string", "null"]
OpenAI type definition.The text was updated successfully, but these errors were encountered: