mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2025-12-30 08:03:32 +01:00
Improved JSON prompting for GPT-4 and recover incomplete JSON responses from Code Llama
This commit is contained in:
@@ -70,8 +70,7 @@ def parse_agent_response(response, function_calls: FunctionCallSet | None):
|
||||
"""
|
||||
|
||||
if function_calls:
|
||||
text = re.sub(r'^.*```json\s*', '', response['text'], flags=re.DOTALL)
|
||||
text = text.strip('` \n')
|
||||
text = response['text']
|
||||
values = list(json.loads(text).values())
|
||||
if len(values) == 1:
|
||||
return values[0]
|
||||
@@ -140,7 +139,7 @@ class JsonPrompter:
|
||||
return "\n".join(
|
||||
self.function_descriptions(functions, function_to_call)
|
||||
+ [
|
||||
"The response MUST be a JSON object matching this schema:",
|
||||
"Here is the schema for the expected JSON object:",
|
||||
"```json",
|
||||
self.function_parameters(functions, function_to_call),
|
||||
"```",
|
||||
@@ -194,7 +193,7 @@ class JsonPrompter:
|
||||
system = (
|
||||
"Help choose the appropriate function to call to answer the user's question."
|
||||
if function_to_call is None
|
||||
else f"Define the arguments for {function_to_call} to answer the user's question."
|
||||
else f"Please provide a JSON object that defines the arguments for the `{function_to_call}` function to answer the user's question."
|
||||
) + "\nThe response must contain ONLY the JSON object, with NO additional text or explanation."
|
||||
|
||||
data = (
|
||||
@@ -202,11 +201,6 @@ class JsonPrompter:
|
||||
if function_to_call
|
||||
else self.functions_summary(functions)
|
||||
)
|
||||
response_start = (
|
||||
f"Here are the arguments for the `{function_to_call}` function: ```json\n"
|
||||
if function_to_call
|
||||
else "Here's the function the user should call: "
|
||||
)
|
||||
|
||||
if self.is_instruct:
|
||||
return f"[INST] <<SYS>>\n{system}\n\n{data}\n<</SYS>>\n\n{prompt} [/INST]"
|
||||
|
||||
Reference in New Issue
Block a user