Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add created_at and updated_at to the cosmos users collection #88

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-lint-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ permissions:
contents: read

jobs:
checks-format:
check-format-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ permissions:
contents: read

jobs:
checks-format:
check-static-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions rag-azure-openai-cosmosdb-langchain-notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@
}
],
"source": [
"from pymongo import MongoClient\n",
"from urllib.parse import quote_plus\n",
"\n",
"from pymongo import MongoClient\n",
"\n",
"# Read and Store Environment variables\n",
"mongo_connection_string = os.getenv(\"AZURE_COSMOS_CONNECTION_STRING\", \"<YOUR-COSMOS-DB-CONNECTION-STRING>\")\n",
"mongo_username = quote_plus(os.getenv(\"AZURE_COSMOS_USERNAME\"))\n",
Expand Down Expand Up @@ -433,7 +434,6 @@
"source": [
"from langchain.prompts import ChatPromptTemplate\n",
"\n",
"\n",
"REPHRASE_PROMPT = \"\"\"\\\n",
"Given the following conversation and a follow up question, rephrase the follow up \\\n",
"question to be a standalone question.\n",
Expand Down
2 changes: 1 addition & 1 deletion src/quartapp/approaches/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from langchain_community.vectorstores import AzureCosmosDBVectorSearch
from langchain_openai import AzureChatOpenAI, AzureOpenAIEmbeddings
from pydantic.v1 import SecretStr
from pydantic.types import SecretStr
from pymongo.collection import Collection

from quartapp.approaches.keyword import KeyWord
Expand Down
2 changes: 1 addition & 1 deletion src/quartapp/approaches/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from langchain_community.vectorstores import AzureCosmosDBVectorSearch
from langchain_openai import AzureChatOpenAI, AzureOpenAIEmbeddings
from pydantic.v1 import SecretStr
from pydantic.types import SecretStr
from pymongo import MongoClient
from pymongo.collection import Collection
from pymongo.errors import ServerSelectionTimeoutError
Expand Down
16 changes: 12 additions & 4 deletions src/quartapp/config_base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
import os
from abc import ABC, abstractmethod
from datetime import datetime, timezone
from urllib.parse import quote_plus

from langchain_core.documents import Document
from pydantic.v1 import SecretStr
from pydantic.types import SecretStr
from pymongo.errors import (
ConfigurationError,
InvalidName,
Expand Down Expand Up @@ -63,7 +64,12 @@ async def add_to_cosmos(
raise IndexError
old_messages.append(new_message)
self.setup._database_setup._users_collection.insert_one(
{"_id": new_session_state, "messages": old_messages}
{
"_id": new_session_state,
"messages": old_messages,
"created_at": datetime.now(timezone.utc), # noqa: UP017
"updated_at": datetime.now(timezone.utc), # noqa: UP017
}
)
return True
except (AttributeError, ConfigurationError, InvalidName, InvalidOperation, OperationFailure, IndexError):
Expand All @@ -73,10 +79,12 @@ async def add_to_cosmos(
if len(old_messages) == 0 or len(new_message) == 0 or len(new_session_state) == 0:
raise IndexError
self.setup._database_setup._users_collection.update_one(
{"_id": new_session_state}, {"$push": {"messages": old_messages[-1]}}
{"_id": new_session_state},
{"$push": {"messages": {"$each": [old_messages[-1], new_message]}}}, # noqa: UP017
)
self.setup._database_setup._users_collection.update_one(
{"_id": new_session_state}, {"$push": {"messages": new_message}}
{"_id": new_session_state},
{"$set": {"updated_at": datetime.now(timezone.utc)}}, # noqa: UP017
)
return True
except (AttributeError, ConfigurationError, InvalidName, InvalidOperation, OperationFailure, IndexError):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Choice,
)
from openai.types.create_embedding_response import Usage
from pydantic.v1 import SecretStr
from pydantic.types import SecretStr

import quartapp
from quartapp.app import create_app
Expand Down