Skip to content

Commit

Permalink
fix: schema fixed and irrelevant fields removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kannav02 committed Jan 21, 2025
1 parent 25a6ebc commit 311993d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
62 changes: 33 additions & 29 deletions common/mongoClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# HARDCODED collection names
feedback_collection_name = "feedback"
context_collection_name = "context"
source_collection_name = "source"

def get_mongo_db_client() -> Database:
"""
Expand Down Expand Up @@ -57,81 +57,85 @@ def submit_feedback(
'bsonType': 'object',
'required': ['question', 'answer', 'sources', 'context', 'issue', 'version', 'timestamp'],
'properties': {
'question': {
'question':
{
'bsonType': 'string',
'description': 'must be a string and is required'
},
'answer': {
'answer':
{
'bsonType': 'string',
'description': 'must be a string and is required'
},
'sources': {
'sources':
{
'bsonType': 'array',
'items': {
'bsonType': 'objectId'
},
'description': 'must be an array of ObjectIds referencing the sources and is required'
},
'context': {
'context':
{
'bsonType': 'array',
'items': {
'bsonType': 'string'
},
'description': 'must be an array of strings and is required'
},
'issue': {
'issue':
{
'bsonType': 'string',
'description': 'must be a string and is required'
},
'version': {
'version':
{
'bsonType': 'string',
'description': 'must be a string and is required'
},
'timestamp': {
'timestamp':
{
'bsonType': 'date',
'description': 'must be a date and is required'
},
'status': {
'status':
{
'enum': ['new', 'processing', 'resolved'],
'description': 'can only be one of the enum values'
}
}
}
})
if not check_collection_exists(context_collection_name,feedback_db_client):
create_collection(context_collection_name, feedback_db_client, {
if not check_collection_exists(source_collection_name,feedback_db_client):
create_collection(source_collection_name, feedback_db_client, {
'$jsonSchema': {
'bsonType': 'object',
'required': ['source', 'timestamp'],
'required': ['source'],
'properties': {
'source': {
'bsonType': 'string',
'description': 'must be a string and is required'
},
'metadata': {
'bsonType': 'object',
'description': 'additional metadata for the context'
},
'timestamp': {
'bsonType': 'date',
'description': 'must be a date and is required'
}
}
}
})
# inserting the records

sources_ids = []
for source in sources:
print(source)
sources_ids.append(feedback_db_client[context_collection_name].insert_one({
'source': str(source),
'metadata': {
'url': str(source)
},
'timestamp': datetime.now()
}).inserted_id)


existing_source = feedback_db_client[source_collection_name].find_one({
'source': str(source)
})

if existing_source:
sources_ids.append(existing_source['_id'])
else:
new_source = feedback_db_client[source_collection_name].insert_one({
'source': str(source),
})
sources_ids.append(new_source.inserted_id)

feedback_db_client[feedback_collection_name].insert_one({
'question': question,
'answer': answer,
Expand Down
2 changes: 2 additions & 0 deletions frontend/utils/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dotenv import load_dotenv
import os
from typing import Optional, Any


import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
from common.mongoClient import submit_feedback
Expand Down

0 comments on commit 311993d

Please sign in to comment.