Spaces:
Sleeping
Sleeping
Update CosmosDBHandlers/cosmosChatHistoryHandler.py
Browse files
CosmosDBHandlers/cosmosChatHistoryHandler.py
CHANGED
|
@@ -51,12 +51,12 @@ class ChatMemoryHandler():
|
|
| 51 |
api_key=os.environ["AZURE_OPENAI_KEY"]
|
| 52 |
)
|
| 53 |
|
| 54 |
-
self.database = self.cosmos_client.create_database_if_not_exists("
|
| 55 |
|
| 56 |
# Container for chat history
|
| 57 |
self.chat_container = self.database.create_container_if_not_exists(
|
| 58 |
id="ChatHistory",
|
| 59 |
-
partition_key=PartitionKey(path="/
|
| 60 |
indexing_policy=self.indexing_policy,
|
| 61 |
vector_embedding_policy=self.vector_embedding_policy
|
| 62 |
)
|
|
@@ -64,7 +64,7 @@ class ChatMemoryHandler():
|
|
| 64 |
# Container for SQL queries
|
| 65 |
self.sql_container = self.database.create_container_if_not_exists(
|
| 66 |
id="GeneratedQueries",
|
| 67 |
-
partition_key=PartitionKey(path="/
|
| 68 |
)
|
| 69 |
|
| 70 |
async def _generate_embedding(self, query: str) -> List[float]:
|
|
@@ -91,14 +91,13 @@ class ChatMemoryHandler():
|
|
| 91 |
self.logger.error(f"Failed to log chat interaction: {str(e)}")
|
| 92 |
|
| 93 |
|
| 94 |
-
async def log_sql_query(self, original_question: str, generated_sql: str):
|
| 95 |
try:
|
| 96 |
sql_item = {
|
| 97 |
"id": str(uuid.uuid4()),
|
| 98 |
-
"queryType": "generated",
|
| 99 |
"originalQuestion": original_question,
|
| 100 |
"generatedSql": generated_sql,
|
| 101 |
-
"
|
| 102 |
"timestamp": datetime.now(timezone.utc).isoformat()
|
| 103 |
}
|
| 104 |
self.sql_container.create_item(body=sql_item)
|
|
|
|
| 51 |
api_key=os.environ["AZURE_OPENAI_KEY"]
|
| 52 |
)
|
| 53 |
|
| 54 |
+
self.database = self.cosmos_client.create_database_if_not_exists("TAL_ChatData")
|
| 55 |
|
| 56 |
# Container for chat history
|
| 57 |
self.chat_container = self.database.create_container_if_not_exists(
|
| 58 |
id="ChatHistory",
|
| 59 |
+
partition_key=PartitionKey(path="/functionUsed"),
|
| 60 |
indexing_policy=self.indexing_policy,
|
| 61 |
vector_embedding_policy=self.vector_embedding_policy
|
| 62 |
)
|
|
|
|
| 64 |
# Container for SQL queries
|
| 65 |
self.sql_container = self.database.create_container_if_not_exists(
|
| 66 |
id="GeneratedQueries",
|
| 67 |
+
partition_key=PartitionKey(path="/state")
|
| 68 |
)
|
| 69 |
|
| 70 |
async def _generate_embedding(self, query: str) -> List[float]:
|
|
|
|
| 91 |
self.logger.error(f"Failed to log chat interaction: {str(e)}")
|
| 92 |
|
| 93 |
|
| 94 |
+
async def log_sql_query(self, original_question: str, generated_sql: str, state: str="success"):
|
| 95 |
try:
|
| 96 |
sql_item = {
|
| 97 |
"id": str(uuid.uuid4()),
|
|
|
|
| 98 |
"originalQuestion": original_question,
|
| 99 |
"generatedSql": generated_sql,
|
| 100 |
+
"state": state,
|
| 101 |
"timestamp": datetime.now(timezone.utc).isoformat()
|
| 102 |
}
|
| 103 |
self.sql_container.create_item(body=sql_item)
|