mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Move construct chat history back to it's original position in file
Keep function where it original was allows tracking diffs and change history more easily
This commit is contained in:
parent
8805e731fd
commit
fd15fc1e59
1 changed files with 29 additions and 29 deletions
|
@ -140,6 +140,35 @@ def construct_iteration_history(
|
|||
return previous_iterations_history
|
||||
|
||||
|
||||
def construct_chat_history(conversation_history: dict, n: int = 4, agent_name="AI") -> str:
|
||||
chat_history = ""
|
||||
for chat in conversation_history.get("chat", [])[-n:]:
|
||||
if chat["by"] == "khoj" and chat["intent"].get("type") in ["remember", "reminder", "summarize"]:
|
||||
chat_history += f"User: {chat['intent']['query']}\n"
|
||||
|
||||
if chat["intent"].get("inferred-queries"):
|
||||
chat_history += f'{agent_name}: {{"queries": {chat["intent"].get("inferred-queries")}}}\n'
|
||||
|
||||
chat_history += f"{agent_name}: {chat['message']}\n\n"
|
||||
elif chat["by"] == "khoj" and ("text-to-image" in chat["intent"].get("type")):
|
||||
chat_history += f"User: {chat['intent']['query']}\n"
|
||||
chat_history += f"{agent_name}: [generated image redacted for space]\n"
|
||||
elif chat["by"] == "khoj" and ("excalidraw" in chat["intent"].get("type")):
|
||||
chat_history += f"User: {chat['intent']['query']}\n"
|
||||
chat_history += f"{agent_name}: {chat['intent']['inferred-queries'][0]}\n"
|
||||
elif chat["by"] == "you":
|
||||
raw_attached_files = chat.get("attachedFiles")
|
||||
if raw_attached_files:
|
||||
attached_files: Dict[str, str] = {}
|
||||
for file in raw_attached_files:
|
||||
attached_files[file["name"]] = file["content"]
|
||||
|
||||
attached_file_context = gather_raw_attached_files(attached_files)
|
||||
chat_history += f"User: {attached_file_context}\n"
|
||||
|
||||
return chat_history
|
||||
|
||||
|
||||
def construct_tool_chat_history(
|
||||
previous_iterations: List[InformationCollectionIteration], tool: ConversationCommand = None
|
||||
) -> Dict[str, list]:
|
||||
|
@ -540,35 +569,6 @@ def get_image_from_url(image_url: str, type="pil"):
|
|||
return ImageWithType(content=None, type=None)
|
||||
|
||||
|
||||
def construct_chat_history(conversation_history: dict, n: int = 4, agent_name="AI") -> str:
|
||||
chat_history = ""
|
||||
for chat in conversation_history.get("chat", [])[-n:]:
|
||||
if chat["by"] == "khoj" and chat["intent"].get("type") in ["remember", "reminder", "summarize"]:
|
||||
chat_history += f"User: {chat['intent']['query']}\n"
|
||||
|
||||
if chat["intent"].get("inferred-queries"):
|
||||
chat_history += f'{agent_name}: {{"queries": {chat["intent"].get("inferred-queries")}}}\n'
|
||||
|
||||
chat_history += f"{agent_name}: {chat['message']}\n\n"
|
||||
elif chat["by"] == "khoj" and ("text-to-image" in chat["intent"].get("type")):
|
||||
chat_history += f"User: {chat['intent']['query']}\n"
|
||||
chat_history += f"{agent_name}: [generated image redacted for space]\n"
|
||||
elif chat["by"] == "khoj" and ("excalidraw" in chat["intent"].get("type")):
|
||||
chat_history += f"User: {chat['intent']['query']}\n"
|
||||
chat_history += f"{agent_name}: {chat['intent']['inferred-queries'][0]}\n"
|
||||
elif chat["by"] == "you":
|
||||
raw_attached_files = chat.get("attachedFiles")
|
||||
if raw_attached_files:
|
||||
attached_files: Dict[str, str] = {}
|
||||
for file in raw_attached_files:
|
||||
attached_files[file["name"]] = file["content"]
|
||||
|
||||
attached_file_context = gather_raw_attached_files(attached_files)
|
||||
chat_history += f"User: {attached_file_context}\n"
|
||||
|
||||
return chat_history
|
||||
|
||||
|
||||
def commit_conversation_trace(
|
||||
session: list[ChatMessage],
|
||||
response: str | list[dict],
|
||||
|
|
Loading…
Reference in a new issue