-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
feat: implemented use of OpenAI's tools
API
#219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested. Reviewed everything up to 6bb676b in 40 seconds
More details
- Looked at
312
lines of code in4
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. gptme/chat.py:206
- Draft comment:
Thetoolsapi
variable is hardcoded toTrue
. Consider making this configurable or based on a condition to allow flexibility in enabling/disabling the tools API. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable:
The comment is about a change made in the diff, specifically the introduction of thetoolsapi
variable set toTrue
. Making it configurable could be a valid suggestion for improving code flexibility. The comment is actionable and clear, suggesting a potential improvement in code quality.
The comment assumes that configurability is necessary without knowing the broader context of the application. It might be that the tools API is always intended to be enabled, making the suggestion unnecessary.
Even if the tools API is always intended to be enabled, making it configurable could still be beneficial for future-proofing or testing purposes.
The comment is valid as it suggests an actionable improvement to make thetoolsapi
variable configurable, enhancing flexibility.
2. gptme/llm_anthropic.py:37
- Draft comment:
Thetools
parameter in thechat
andstream
functions is not type-annotated. Consider adding a type annotation for clarity and to ensure correct usage. - Reason this comment was not posted:
Confidence changes required:50%
Thetools
parameter in thechat
andstream
functions is not type-annotated, which can lead to confusion about the expected input type.
3. gptme/llm_openai.py:73
- Draft comment:
Thetools
parameter in thechat
andstream
functions is not type-annotated. Consider adding a type annotation for clarity and to ensure correct usage. - Reason this comment was not posted:
Confidence changes required:50%
Thetools
parameter in thechat
andstream
functions is not type-annotated, which can lead to confusion about the expected input type.
Workflow ID: wflow_ub07SS78hNJ2a08Z
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
gptme/chat.py
Outdated
if toolsapi: | ||
toolcall_re = re.compile(r"@(\w+): (\{.*?\})") | ||
# if matches exactly | ||
if match := toolcall_re.match(msg_response.content): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regular expression toolcall_re.match(msg_response.content)
only matches if the entire content is a tool call. Consider using toolcall_re.search(msg_response.content)
to find tool calls within a larger response.
if match := toolcall_re.match(msg_response.content): | |
if match := toolcall_re.search(msg_response.content): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellipsis-dev That's as intended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes were made to the regular expression usage in the code, as the reviewer confirmed that the current behavior is intended and correct. If there are any other concerns or areas that need attention, please let me know!
Responding to this comment by @ErikBjare. For more information about Ellipsis, check the documentation.
gptme/llm.py
Outdated
description = spec.desc | ||
|
||
if spec.functions: | ||
logger.warn("functions not supported yet") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec2tool
function logs a warning for unsupported spec.functions
but does not handle them. Consider implementing support or explicitly ignoring them to avoid incomplete tool specifications.
logger.warn("functions not supported yet") | |
logger.warn("functions not supported yet, ignoring them") |
❌ 7 Tests Failed:
View the top 3 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 0598b0d in 19 seconds
More details
- Looked at
83
lines of code in3
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. gptme/chat.py:215
- Draft comment:
The regex pattern for tool calls is duplicated inchat.py
andbase.py
. Consider centralizing this pattern to avoid inconsistencies and improve maintainability. - Reason this comment was not posted:
Confidence changes required:50%
The regex pattern for tool calls is duplicated in bothchat.py
andbase.py
. This should be centralized to avoid inconsistencies and improve maintainability.
2. gptme/llm.py:50
- Draft comment:
Theparameters
field inspec2tool
is set toNone
. Ensure this is properly set to reflect the tool's parameters. - Reason this comment was not posted:
Confidence changes required:50%
Thespec2tool
function inllm.py
has a placeholder for setting parameters, which is currently set toNone
. This should be addressed to ensure proper functionality.
3. gptme/tools/base.py:24
- Draft comment:
The regex pattern for tool calls is duplicated inchat.py
andbase.py
. Consider centralizing this pattern to avoid inconsistencies and improve maintainability. - Reason this comment was not posted:
Confidence changes required:50%
Thetoolcall_re
regex pattern is duplicated in bothchat.py
andbase.py
. This should be centralized to avoid inconsistencies and improve maintainability.
Workflow ID: wflow_6Qy6YUKNRCML0QLB
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 496bbfd in 18 seconds
More details
- Looked at
22
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
1
drafted comments based on config settings.
1. README.md:318
- Draft comment:
Duplicate link reference for[docs-server]
. Consider removing one of them to avoid confusion. - Reason this comment was not posted:
Confidence changes required:50%
The link reference for [docs-server] is duplicated, which can cause confusion and maintenance issues.
Workflow ID: wflow_xXtOlQyIAZwosRkj
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
4b13443
to
28fa60a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 4b13443 in 40 seconds
More details
- Looked at
85
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
4
drafted comments based on config settings.
1. gptme/llm.py:76
- Draft comment:
Ensure_client_to_provider()
is defined or imported, as it is used multiple times but not shown in this snippet. - Reason this comment was not posted:
Comment did not seem useful.
2. gptme/llm.py:54
- Draft comment:
Consider improving the construction ofparam_schema
with more detailed descriptions for arguments, as noted in the TODO comment. - Reason this comment was not posted:
Confidence changes required:50%
Thespec2tool
function has a TODO comment about constructing the parameter schema intelligently. This is a potential area for improvement, but not a critical issue for functionality.
3. gptme/llm.py:75
- Draft comment:
Clarify whetherinput_schema
andparameters
are equivalent, as noted in the TODO comment, to ensure correct schema usage. - Reason this comment was not posted:
Comment did not seem useful.
4. gptme/llm.py:94
- Draft comment:
Consider providing more details in theValueError
message to indicate which provider was unsupported. - Reason this comment was not posted:
Confidence changes required:20%
Thespec2tool
function raises aValueError
if the provider doesn't support the tools API. This is a good practice to handle unsupported cases, but the error message could be more informative.
Workflow ID: wflow_UBXx4A8I6MylIv9l
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 28fa60a in 41 seconds
More details
- Looked at
85
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
4
drafted comments based on config settings.
1. gptme/llm.py:76
- Draft comment:
Ensure_client_to_provider()
is defined or imported, as it is used multiple times but not defined in this snippet. - Reason this comment was not posted:
Comment did not seem useful.
2. gptme/llm.py:54
- Draft comment:
Address the TODO comment regarding constructing the parameter schema intelligently. This is crucial for ensuring the function's robustness and correctness. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable:
The comment is pointing out a TODO that is already in the code, which the author is likely aware of. The comment does not provide any new information or actionable steps beyond what the TODO already indicates. It seems to be reiterating the importance of the TODO rather than suggesting a specific code change.
The comment might be emphasizing the importance of the TODO, which could be useful if the author overlooked it. However, it doesn't add any new information or actionable advice beyond the existing TODO.
The presence of the TODO already indicates that the author is aware of the need for improvement, making the comment redundant. The comment does not provide additional actionable insights.
The comment should be deleted as it does not provide new information or actionable steps beyond the existing TODO. It is redundant and not necessary for a code change.
3. gptme/llm.py:75
- Draft comment:
Clarify whetherinput_schema
andparameters
are the same for different providers to ensure correct implementation. - Reason this comment was not posted:
Comment did not seem useful.
4. gptme/llm.py:94
- Draft comment:
Include the provider name in theValueError
message for better debugging when a provider doesn't support the tools API. - Reason this comment was not posted:
Confidence changes required:50%
Thespec2tool
function raises aValueError
if the provider doesn't support the tools API. This is a good practice to handle unexpected cases, but it might be helpful to include the provider name in the error message for better debugging.
Workflow ID: wflow_wNbR3bXGrQCWH7fW
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 4a11c8b in 22 seconds
More details
- Looked at
65
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. gptme/llm_openai.py:124
- Draft comment:
Thecast
toChatCompletionChunk
is unnecessary if the API guarantees the type. Consider removing it to avoid potential runtime errors if the type is incorrect. - Reason this comment was not posted:
Confidence changes required:50%
The code uses a cast to ensure the type ofchunk
isChatCompletionChunk
. However, this cast is not necessary if the type is already guaranteed by the API. Additionally, the cast is not checked at runtime, so it could lead to errors if the type is incorrect.
2. gptme/llm_openai.py:140
- Draft comment:
Theisinstance
checks forChoiceDeltaToolCall
andChoiceDeltaToolCallFunction
are redundant if the API guarantees these types. Consider removing them to simplify the code. This applies to line 142 as well. - Reason this comment was not posted:
Confidence changes required:50%
The code usesisinstance
checks forChoiceDeltaToolCall
andChoiceDeltaToolCallFunction
. These checks are redundant if the types are already guaranteed by the API. Removing them can simplify the code.
Workflow ID: wflow_w0dUwI9WI4JYxwPx
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
tools
API
Hey @ErikBjare, are you planning to continue this soon? If not, would you be okay with me picking it up (on top of your changes obviously)? I believe this MR could significantly improve model performance, especially for smaller ones and prevent some random small bugs. 🙏 |
@jrmi I'm kinda working on other stuff right now. No immediate plans to pick this up. Feel free to give it a shot! |
Made an attempt at #218, was pretty easy to get this minimal thing working.
should we register ipython-functions too?leave it to the ipython toolWould improve system prompt adherence, fixing issues like:
Important
Adds support for OpenAI's Tools API, integrating tool usage into chat flow with tool execution and response handling.
step()
inchat.py
andreply()
inllm.py
.step()
using regex to extract tool name and arguments.build_tools_dict()
andspec2tool()
inllm.py
to construct tool specifications.reply()
,_chat_complete()
, and_stream()
inllm.py
to accept and handle tools.chat()
andstream()
inllm_openai.py
andllm_anthropic.py
to pass tools to API calls.tools
parameter tochat()
andstream()
functions inllm_openai.py
andllm_anthropic.py
.toolcall_re
regex intools/base.py
to parse tool calls.This description was created by for 4a11c8b. It will automatically update as commits are pushed.