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

Function call sample code 需要更新下 #177

Open
markshao opened this issue Aug 30, 2024 · 0 comments
Open

Function call sample code 需要更新下 #177

markshao opened this issue Aug 30, 2024 · 0 comments

Comments

@markshao
Copy link

当前的 function call 官方文档 https://platform.deepseek.com/api-docs/guides/function_calling

最新的 openai python sdk openai==1.42.0

messages = [{"role": "user", "content": "How's the weather in Hangzhou?"}]
message = send_messages(messages)
print(f"User>\t {messages[0]['content']}")

tool = message.tool_calls[0]
messages.append(message)

直接访问 message.tool_calls 会报错 AttributeError

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ilya/.cache/pypoetry/virtualenvs/buffett-4Wtakw1Y-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 828, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'ChatCompletion' object has no attribute 'tool_calls'

看了下 openai 的 doc https://platform.openai.com/docs/guides/function-calling , 协议有些变化, function call 是在 Choice 里

Choice(
    finish_reason='tool_calls', 
    index=0, 
    logprobs=None, 
    message=chat.completionsMessage(
        content=None, 
        role='assistant', 
        function_call=None, 
        tool_calls=[
            chat.completionsMessageToolCall(
                id='call_62136354', 
                function=Function(
                    arguments='{"order_id":"order_12345"}', 
                    name='get_delivery_date'), 
                type='function')
        ])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant