Skip to content

Commit 067b558

Browse files
forever-lydandansamaxlightaime
authored
Improve function call (camel-ai#279) (camel-ai#393)
Co-authored-by: Tianqi Xu <[email protected]> Co-authored-by: Guohao Li <[email protected]> Co-authored-by: lig <[email protected]>
1 parent b95288b commit 067b558

17 files changed

+1132
-617
lines changed

camel/agents/chat_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(
122122
self.func_dict: Dict[str, Callable] = {}
123123
if function_list is not None:
124124
for func in function_list:
125-
self.func_dict[func.name] = func.func
125+
self.func_dict[func.get_function_name()] = func.func
126126
self.model_config = model_config or ChatGPTConfig()
127127

128128
self.model_backend: BaseModelBackend = ModelFactory.create(

camel/configs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ def from_openai_function_list(
128128
:obj:`function_call` argument.
129129
"""
130130
return cls(
131-
functions=[func.as_dict() for func in function_list],
131+
functions=[
132+
func.get_openai_function_schema() for func in function_list
133+
],
132134
function_call=function_call,
133135
**(kwargs or {}),
134136
)

camel/functions/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
# limitations under the License.
1313
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
1414

15+
from .openai_function import (
16+
OpenAIFunction,
17+
get_openai_tool_schema,
18+
get_openai_function_schema,
19+
)
1520
from .math_functions import MATH_FUNCS
16-
from .openai_function import OpenAIFunction
1721
from .search_functions import SEARCH_FUNCS
1822
from .weather_functions import WEATHER_FUNCS
1923
from .unstructured_io_fuctions import UnstructuredModules
2024

2125
__all__ = [
2226
'OpenAIFunction',
27+
'get_openai_tool_schema',
28+
'get_openai_function_schema',
2329
'MATH_FUNCS',
2430
'SEARCH_FUNCS',
2531
'WEATHER_FUNCS',

camel/functions/math_functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def add(a: int, b: int) -> int:
2121
r"""Adds two numbers.
2222
2323
Args:
24-
a (integer): The first number to be added.
25-
b (integer): The second number to be added.
24+
a (int): The first number to be added.
25+
b (int): The second number to be added.
2626
2727
Returns:
2828
integer: The sum of the two numbers.
@@ -34,8 +34,8 @@ def sub(a: int, b: int) -> int:
3434
r"""Do subtraction between two numbers.
3535
3636
Args:
37-
a (integer): The minuend in subtraction.
38-
b (integer): The subtrahend in subtraction.
37+
a (int): The minuend in subtraction.
38+
b (int): The subtrahend in subtraction.
3939
4040
Returns:
4141
integer: The result of subtracting :obj:`b` from :obj:`a`.
@@ -47,8 +47,8 @@ def mul(a: int, b: int) -> int:
4747
r"""Multiplies two integers.
4848
4949
Args:
50-
a (integer): The multiplier in the multiplication.
51-
b (integer): The multiplicand in the multiplication.
50+
a (int): The multiplier in the multiplication.
51+
b (int): The multiplicand in the multiplication.
5252
5353
Returns:
5454
integer: The product of the two numbers.

0 commit comments

Comments
 (0)