Julia Ostheimer commited on
Commit ·
546b27b
1
Parent(s): cf824b9
Add util functions to renamed chat_source_history.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ from langgraph.graph import MessagesState, StateGraph, END
|
|
| 10 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 11 |
|
| 12 |
import structlog
|
| 13 |
-
import uuid
|
| 14 |
|
| 15 |
from qdrant_client import QdrantClient
|
| 16 |
from qdrant_client.http.models import Distance, VectorParams, SparseVectorParams
|
|
@@ -18,7 +17,7 @@ from qdrant_client.http.models import Distance, VectorParams, SparseVectorParams
|
|
| 18 |
import logging_config as _
|
| 19 |
# from conversation.main import graph
|
| 20 |
from conversation.generate import generate, trigger_ai_message_with_tool_call
|
| 21 |
-
from conversation.
|
| 22 |
from ingestion.main import ingest_document
|
| 23 |
from tools.langfuse_client import get_langfuse_handler
|
| 24 |
|
|
@@ -124,19 +123,6 @@ def bot(message, history, source_history, chat_hash) -> list[Any]:
|
|
| 124 |
|
| 125 |
return [response["messages"][-1].content], source_history, chat_hash
|
| 126 |
|
| 127 |
-
def clear_chat_and_source_history(source_history, chat_hash):
|
| 128 |
-
# Clear the source history
|
| 129 |
-
source_history = []
|
| 130 |
-
|
| 131 |
-
# Return a new chat hash
|
| 132 |
-
chat_hash = create_chat_hash()
|
| 133 |
-
|
| 134 |
-
return source_history, chat_hash
|
| 135 |
-
|
| 136 |
-
def create_chat_hash():
|
| 137 |
-
chat_hash = str(uuid.uuid4())
|
| 138 |
-
logger.info("This is the chat_hash when it is called", chat_hash=chat_hash)
|
| 139 |
-
return chat_hash
|
| 140 |
|
| 141 |
with gr.Blocks() as demo:
|
| 142 |
# Initialize source history as session state variable
|
|
|
|
| 10 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 11 |
|
| 12 |
import structlog
|
|
|
|
| 13 |
|
| 14 |
from qdrant_client import QdrantClient
|
| 15 |
from qdrant_client.http.models import Distance, VectorParams, SparseVectorParams
|
|
|
|
| 17 |
import logging_config as _
|
| 18 |
# from conversation.main import graph
|
| 19 |
from conversation.generate import generate, trigger_ai_message_with_tool_call
|
| 20 |
+
from conversation.chat_source_history import prettify_source_history, build_source_history_object, clear_chat_and_source_history, create_chat_hash
|
| 21 |
from ingestion.main import ingest_document
|
| 22 |
from tools.langfuse_client import get_langfuse_handler
|
| 23 |
|
|
|
|
| 123 |
|
| 124 |
return [response["messages"][-1].content], source_history, chat_hash
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
with gr.Blocks() as demo:
|
| 128 |
# Initialize source history as session state variable
|
conversation/{source_history.py → chat_source_history.py}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import structlog
|
| 3 |
from langchain_core.messages import ToolMessage
|
| 4 |
|
|
@@ -109,4 +110,18 @@ def build_source_history_object(response, source_history: list, user_input_promp
|
|
| 109 |
"source_text_chunk": [doc["source_text_chunk"] for doc in dictionary_document_data]
|
| 110 |
})
|
| 111 |
|
| 112 |
-
return source_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import uuid
|
| 3 |
import structlog
|
| 4 |
from langchain_core.messages import ToolMessage
|
| 5 |
|
|
|
|
| 110 |
"source_text_chunk": [doc["source_text_chunk"] for doc in dictionary_document_data]
|
| 111 |
})
|
| 112 |
|
| 113 |
+
return source_history
|
| 114 |
+
|
| 115 |
+
def clear_chat_and_source_history(source_history, chat_hash):
|
| 116 |
+
# Clear the source history
|
| 117 |
+
source_history = []
|
| 118 |
+
|
| 119 |
+
# Return a new chat hash
|
| 120 |
+
chat_hash = create_chat_hash()
|
| 121 |
+
|
| 122 |
+
return source_history, chat_hash
|
| 123 |
+
|
| 124 |
+
def create_chat_hash():
|
| 125 |
+
chat_hash = str(uuid.uuid4())
|
| 126 |
+
logger.info("This is the chat_hash when it is called", chat_hash=chat_hash)
|
| 127 |
+
return chat_hash
|