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

Azure support multitask.py #136

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions instructor/dsl/multitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def tasks_from_chunks(cls, json_chunks):
@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"]
Comment on lines +34 to +38
Copy link
Contributor

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.

Suggested change
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"]

Comment on lines +36 to +38
Copy link
Contributor

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.

Suggested change
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"]

Comment on lines +37 to +38
Copy link
Contributor

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.

Suggested change
if "arguments" in delta["function_call"]:
yield delta["function_call"]["arguments"]
if "arguments" in delta.get("function_call", {}):
yield delta["function_call"]["arguments"]


Comment on lines 31 to 39
Copy link
Contributor

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.

Suggested change
@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"]

@staticmethod
def get_object(str, stack):
Expand Down