-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improvements to JSON handling for local LLMs #269
Conversation
} | ||
} | ||
""" | ||
raise NotImplementedError |
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.
Add this in a separate PR to address #245
|
||
|
||
def extract_first_json(string): | ||
"""Handles the case of two JSON objects back-to-back""" |
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.
This just counts opening vs closing brackets to try and pull the first JSON object out of a potential "run-on JSON object"
@@ -184,9 +185,9 @@ def output_to_chat_completion_response(self, raw_llm_output): | |||
raw_llm_output = "{" + raw_llm_output | |||
|
|||
try: | |||
function_json_output = json.loads(raw_llm_output) | |||
function_json_output = clean_json(raw_llm_output) |
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.
Actually this should be added to the other wrappers too
data = json.loads(raw_llm_output) | ||
except json.JSONDecodeError: | ||
try: | ||
data = json.loads(raw_llm_output + "}") |
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.
🤌
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.
LGTM 📜
* some extra json hacks * add 'smart' json loader to other wrapers * added chatml related stop tokens by default
"Closes" the double-JSON error mentioned in #177
Move to separate PR:
Example fixing the double-JSON problem
Example bad LLM output (from #177):
MemGPT output (without patch):
MemGPT output (with patch):
Example fixing the sep token (eg
<im_sep>
,FUNC RET
, ...) after JSON problemExample bad LLM output:
MemGPT output (without patch):
MemGPT output (with patch):