mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 13:21:18 +00:00
Remove any markdown json codeblock in chat actors expecting json responses
Strip any json md codeblock wrapper if exists before processing response by output mode, extract questions chat actor. This is similar to what is already being done by other chat actors Useful for succesfully interpreting json output in chat actors when using non (json) schema enforceable models like o1 and gemma-2 Use conversation helper function to centralize the json md codeblock removal code
This commit is contained in:
@@ -14,6 +14,7 @@ from khoj.processor.conversation.openai.utils import (
|
||||
from khoj.processor.conversation.utils import (
|
||||
construct_structured_message,
|
||||
generate_chatml_messages_with_context,
|
||||
remove_json_codeblock,
|
||||
)
|
||||
from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
||||
from khoj.utils.rawconfig import LocationData
|
||||
@@ -85,6 +86,7 @@ def extract_questions(
|
||||
# Extract, Clean Message from GPT's Response
|
||||
try:
|
||||
response = response.strip()
|
||||
response = remove_json_codeblock(response)
|
||||
response = json.loads(response)
|
||||
response = [q.strip() for q in response["queries"] if q.strip()]
|
||||
if not isinstance(response, list) or not response:
|
||||
|
||||
Reference in New Issue
Block a user