sample-app-aoai-chatGPT icon indicating copy to clipboard operation
sample-app-aoai-chatGPT copied to clipboard

Add user_name field to Cosmos DB entries.

Open bsonnek opened this issue 1 year ago • 1 comments

When looking through the ComosDB service at the conversation history entries, would it be possible to add the user_name to database entries to make them easier to track?

Similar to something like this: app.py -

@bp.route("/history/update", methods=["POST"]) async def update_conversation(): authenticated_user = get_authenticated_user_details(request_headers=request.headers) user_id = authenticated_user['user_principal_id'] user_name = authenticated_user['user_name']

#############

messages = request_json["messages"] if len(messages) > 0 and messages[-1]['role'] == "assistant": if len(messages) > 1 and messages[-2].get('role', None) == "tool": # write the tool message first await cosmos_conversation_client.create_message( uuid=str(uuid.uuid4()), conversation_id=conversation_id, user_id=user_id, user_name=user_name, input_message=messages[-2] )

############## backend/history/cosmosdbservice.py

async def create_conversation(self, user_id, user_name, title = ''):
    conversation = {
        'id': str(uuid.uuid4()),  
        'type': 'conversation',
        'createdAt': datetime.utcnow().isoformat(),  
        'updatedAt': datetime.utcnow().isoformat(),  
        'userId': user_id,
        **'userName': user_name,**
        'title': title
    }


async def create_message(self, uuid, conversation_id, user_id, user_name, input_message: dict):
    message = {
        'id': uuid,
        'type': 'message',
        'userId' : user_id,
        **'userName' : user_name,**
        'createdAt': datetime.utcnow().isoformat(),
        'updatedAt': datetime.utcnow().isoformat(),
        'conversationId' : conversation_id,
        'role': input_message['role'],
        'content': input_message['content']
    


async def create_conversation(self, user_id, user_name, title = ''):
    conversation = {
        'id': str(uuid.uuid4()),  
        'type': 'conversation',
        'createdAt': datetime.utcnow().isoformat(),  
        'updatedAt': datetime.utcnow().isoformat(),  
        'userId': user_id,
        **'userName': user_name,**
        'title': title
    }

bsonnek avatar Feb 26 '24 23:02 bsonnek