mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39: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"])]
|
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"""
|
"""Remove any markdown json codeblock formatting if present. Useful for non schema enforceable models"""
|
||||||
if response.startswith("```json") and response.endswith("```"):
|
return response.removeprefix("```json").removesuffix("```")
|
||||||
response = response[7:-3]
|
|
||||||
return response
|
|
||||||
|
|||||||
Reference in New Issue
Block a user