mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Simplify code to remove json codeblock from AI response string
This commit is contained in:
@@ -291,8 +291,6 @@ def reciprocal_conversation_to_chatml(message_pair):
|
||||
return [ChatMessage(content=message, role=role) for message, role in zip(message_pair, ["user", "assistant"])]
|
||||
|
||||
|
||||
def remove_json_codeblock(response):
|
||||
def remove_json_codeblock(response: str):
|
||||
"""Remove any markdown json codeblock formatting if present. Useful for non schema enforceable models"""
|
||||
if response.startswith("```json") and response.endswith("```"):
|
||||
response = response[7:-3]
|
||||
return response
|
||||
return response.removeprefix("```json").removesuffix("```")
|
||||
|
||||
Reference in New Issue
Block a user