Skip to content

Commit

Permalink
Better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Jul 24, 2023
1 parent 83b1d33 commit 21d037d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions easycompletion/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def validate_functions(response, functions, function_call, debug=DEBUG):
"function_call", None
)
if response_function_call is None:
log("No function call in response", type="error", log=debug)
log(f"No function call in response\n{response}", type="error", log=debug)
return False

# If function_call is not "auto" and the name does not match with the response, return False
Expand All @@ -103,21 +103,31 @@ def validate_functions(response, functions, function_call, debug=DEBUG):

# Parse the arguments from the response
arguments = parse_arguments(response_function_call["arguments"])

# If arguments are None, return False
if arguments is None:
log("Arguments are None", type="error", log=debug)
return False


# Get the function that matches the function name from the list of functions
function = next(
(item for item in functions if item["name"] == function_call_name), None
)

# If no matching function is found, return False
if function is None:
log("No matching function found", type="error", log=debug)
log(
"No matching function found"
+ f"\nExpected function name:\n{str(function_call_name)}"
+ f"\n\nResponse:\n{str(response)}"
, type="error", log=debug)
return False

# If arguments are None, return False
if arguments is None:
log(
"Arguments are None"
+ f"\nExpected arguments:\n{str(function['parameters']['properties'].keys())}"
+ f"\n\nResponse function call:\n{str(response_function_call)}"
, type="error", log=debug)
#
return False


required_properties = function["parameters"].get("required", [])

Expand Down Expand Up @@ -441,7 +451,7 @@ def openai_function_call(

# If no function call in response, return an error
if function_call_response is None:
log("No function call in response", type="error", log=debug)
log(f"No function call in response\n{response}", type="error", log=debug)
return {"error": "No function call in response"}
function_name = function_call_response["name"]
arguments = parse_arguments(function_call_response["arguments"])
Expand Down

0 comments on commit 21d037d

Please sign in to comment.