From 0ac173d5d218f196e6b10b1907f1c5ce2c57538e Mon Sep 17 00:00:00 2001 From: Ryan Eggleston <40816745+ryaneggz@users.noreply.github.com> Date: Sun, 31 Dec 2023 17:20:20 -0600 Subject: [PATCH] MERGE feature/76-updates-params-for-ability-to-fetch-from-other-properties INTO development (#77) * MERGE development INTO master (#74) * MERGE feature/50-adds-settings-and-updates-history-endpoints INTO development (#51) * Endpoints reconfigurged for settings and history * Update changelog * MERGE Feature/rag chat fixed to not be agent INTO development (#53) * Rag chat fixed * Remove body from create for now, may change how this works later * Works for saas, may stop workign on vercel * MERGE feature/55-update-ollama-rag-chat INTO development (#56) * Contains updates for ollama rag but is a bit more custom than intended, doesn't include return docs atm. * Rag working for both openai and ollama * MERGE feature/55-update-ollama-rag-chat INTO development (#57) * Contains updates for ollama rag but is a bit more custom than intended, doesn't include return docs atm. * Rag working for both openai and ollama * Update changelog * Update changlog * fixing the retrieval routes * Update changelog * Update retrieval controller with file upload * Adds better error handling for tools in agent * Changes made (#62) * MERGE feature/64-retricts-what-can-be-passed-to-settings-and-history INTO development (#65) * Updates to restrict the keys that can be saved * Adds the keys as args so could be altered * adds some type hinting * Small fix in history controller * Need to account for tags and title on history and settings * Switch to a set to be more efficient (#71) * A couple adjustments * Had to update the PINECONE_KEY to PINECONE_API_KEY * Had to do some updates * update HistoryController with user_id for webhook * Update changelog * Made, may need to take a second look edit mode is not working in the other repo * Updates changelog --- Changelog.md | 5 +- .../fastapi/controllers/history.py | 21 +++++--- promptengineers/fastapi/history.py | 52 ++++++++++--------- promptengineers/fastapi/settings.py | 2 +- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/Changelog.md b/Changelog.md index 451d24b..2943553 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.1.11 +### Added + - feature/76-updates-params-for-ability-to-fetch-from-other-properties (2023-12-31) + ## 1.1.10 ### Added - Updates HistoryController constructor to include a user_id as request alternative. (2023-12-30) @@ -35,7 +39,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 1.1.2 ### Added - - feature/55-update-ollama-rag-chat (2023-12-17) ## 1.1.1 diff --git a/promptengineers/fastapi/controllers/history.py b/promptengineers/fastapi/controllers/history.py index 465c53a..886dacc 100644 --- a/promptengineers/fastapi/controllers/history.py +++ b/promptengineers/fastapi/controllers/history.py @@ -26,12 +26,21 @@ def __init__( ############################################################## ### Create Chat History ############################################################## - async def index(self, page: int = 1, limit: int = 10): - result = await self.history_service.list_docs( - {'user_id': ObjectId(self.user_id)}, - limit, - page - ) + async def index(self, page: int = 1, limit: int = 10, **kwargs): + # Base query with user_id + query = {'user_id': ObjectId(self.user_id)} + + # Add additional filters passed as keyword arguments + for key, value in kwargs.items(): + if value is not None: # Ensure that a value is provided for the filter + # Convert to ObjectId if necessary, for example, if key ends with "_id" + if key in {'setting'}: + query[key] = ObjectId(value) + else: + query[key] = value + + # Get the result from the history_service + result = await self.history_service.list_docs(query, limit, page) return result ############################################################## diff --git a/promptengineers/fastapi/history.py b/promptengineers/fastapi/history.py index 195e2d9..50d125e 100644 --- a/promptengineers/fastapi/history.py +++ b/promptengineers/fastapi/history.py @@ -25,32 +25,34 @@ def get_controller(request: Request) -> HistoryController: response_model=ResponseHistoryIndex ) async def list_chat_histories( - page: int = 1, - limit: int = 50, - controller: HistoryController = Depends(get_controller), + page: int = 1, + limit: int = 50, + setting: str = None, + controller: HistoryController = Depends(get_controller), ): - """List histories""" - try: - result = await controller.index(page, limit) - # Format Response - data = json.dumps({ - 'histories': result - }, cls=JSONEncoder) - return Response( - content=data, - media_type='application/json', - status_code=200 - ) - except HTTPException as err: - logger.error(err.detail) - raise - except BaseException as err: - tb = traceback.format_exc() - logger.error("[list_chat_histories]: %s\n%s", err, tb) - raise HTTPException( - status_code=500, - detail=f"An unexpected error occurred. {str(err)}" - ) from err + """List histories""" + try: + # Forward the setting_id and any additional parameters to the controller's index method + result = await controller.index(page, limit, setting=setting) + # Format Response + data = json.dumps({ + 'histories': result + }, cls=JSONEncoder) + return Response( + content=data, + media_type='application/json', + status_code=200 + ) + except HTTPException as err: + logger.error(err.detail) + raise + except BaseException as err: + tb = traceback.format_exc() + logger.error("[list_chat_histories]: %s\n%s", err, tb) + raise HTTPException( + status_code=500, + detail=f"An unexpected error occurred. {str(err)}" + ) from err ################################################# # Create Chat History diff --git a/promptengineers/fastapi/settings.py b/promptengineers/fastapi/settings.py index 14a58c1..1dd9d29 100644 --- a/promptengineers/fastapi/settings.py +++ b/promptengineers/fastapi/settings.py @@ -106,7 +106,7 @@ async def show( # Format Response data = json.dumps({ - **result + 'setting': result }, cls=JSONEncoder) return Response( content=data,