-
-
Notifications
You must be signed in to change notification settings - Fork 732
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
Azure support multitask.py #136
Conversation
Azure support for Multiple Extractions
WalkthroughThe recent changes focus on enhancing error handling in the Changes
Poem
TipsChat with CodeRabbit Bot (
|
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.
@staticmethod | ||
def extract_json(completion): | ||
for chunk in completion: | ||
delta = chunk["choices"][0]["delta"] | ||
if "function_call" in delta: | ||
yield delta["function_call"]["arguments"] | ||
if chunk["choices"]: | ||
delta = chunk["choices"][0]["delta"] | ||
if "function_call" in delta: | ||
if "arguments" in delta["function_call"]: | ||
yield delta["function_call"]["arguments"] | ||
|
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 code assumes that the choices
key will always be present in the chunk
dictionary. This could lead to a KeyError if choices
is not present. It would be safer to check for the existence of choices
before accessing it. Also, it's a good practice to check if choices
is not empty before accessing its first element. Here is the improved code:
- if chunk["choices"]:
+ if "choices" in chunk and chunk["choices"]:
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
@staticmethod | |
def extract_json(completion): | |
for chunk in completion: | |
delta = chunk["choices"][0]["delta"] | |
if "function_call" in delta: | |
yield delta["function_call"]["arguments"] | |
if chunk["choices"]: | |
delta = chunk["choices"][0]["delta"] | |
if "function_call" in delta: | |
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] | |
@staticmethod | |
def extract_json(completion): | |
for chunk in completion: | |
- if chunk["choices"]: | |
+ if "choices" in chunk and chunk["choices"]: | |
delta = chunk["choices"][0]["delta"] | |
if "function_call" in delta: | |
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] |
if chunk["choices"]: | ||
delta = chunk["choices"][0]["delta"] | ||
if "function_call" in delta: | ||
if "arguments" in delta["function_call"]: | ||
yield delta["function_call"]["arguments"] |
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 code assumes that the delta
key will always be present in the choices[0]
dictionary. This could lead to a KeyError if delta
is not present. It would be safer to check for the existence of delta
before accessing it. Here is the improved code:
- delta = chunk["choices"][0]["delta"]
+ delta = chunk["choices"][0].get("delta")
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
if chunk["choices"]: | |
delta = chunk["choices"][0]["delta"] | |
if "function_call" in delta: | |
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] | |
if chunk["choices"]: | |
delta = chunk["choices"][0].get("delta") | |
if "function_call" in delta: | |
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] |
if "function_call" in delta: | ||
if "arguments" in delta["function_call"]: | ||
yield delta["function_call"]["arguments"] |
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 code assumes that the function_call
key will always be present in the delta
dictionary. This could lead to a KeyError if function_call
is not present. It would be safer to check for the existence of function_call
before accessing it. Here is the improved code:
- if "function_call" in delta:
+ if delta and "function_call" in delta:
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
if "function_call" in delta: | |
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] | |
if delta and "function_call" in delta: | |
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] |
if "arguments" in delta["function_call"]: | ||
yield delta["function_call"]["arguments"] |
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 code assumes that the arguments
key will always be present in the function_call
dictionary. This could lead to a KeyError if arguments
is not present. It would be safer to check for the existence of arguments
before accessing it. Here is the improved code:
- if "arguments" in delta["function_call"]:
+ if "arguments" in delta.get("function_call", {}):
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
if "arguments" in delta["function_call"]: | |
yield delta["function_call"]["arguments"] | |
if "arguments" in delta.get("function_call", {}): | |
yield delta["function_call"]["arguments"] |
it's now in 0.2.10 |
Azure support for Multiple Extractions
Azure support for Multiple Extractions
Without validation, Azure use breaks with some chunks not containing any
choices
and the firstfunction_call
chunk not containingarguments
.As of API version "2023-07-01-preview", most chunks related to a function call seem to spit out all at once. So be aware the experience won't match OpenAI until it's addressed in a future API update.
Summary by CodeRabbit