Open Haste171 opened 8 months ago
b7d98b7361
)Here are the sandbox execution logs prior to making any changes:
5f913d0
Checking README.md for syntax errors... ✅ README.md has no syntax errors!
1/1 ✓Checking README.md for syntax errors... ✅ README.md has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
app/main.py
✓ https://github.com/Haste171/langchain-chatbot/commit/b7ea58b44f72e2997d52f5957d223c80301d9903 Edit
Create app/main.py with contents:
• Create a new FastAPI application in the `app/main.py` file.
• Import the necessary modules, including FastAPI from the fastapi module, and the `llm_query` function from the `utils/llm_query.py` file.
• Define the FastAPI app with `app = FastAPI()`.
• Set up the necessary routes for the API. This will include a POST route for ingesting data, a GET route for querying data, and a GET route for retrieving the chat history.
• Within each route, call the appropriate functions from the `deprecated/chatbot.py` file to perform the necessary actions. For example, in the POST route for ingesting data, call the `ingest` function.
• Ensure that each route returns a JSON response with the appropriate data.
app/main.py
✓ Edit
Check app/main.py with contents:
Ran GitHub Actions for b7ea58b44f72e2997d52f5957d223c80301d9903:
README.md
✓ https://github.com/Haste171/langchain-chatbot/commit/58e5d481032dce6466df6b14bef20ac93cf48f41 Edit
Modify README.md with contents:
• Update the Installation section to include instructions on how to run the new FastAPI application. This should include instructions on how to install FastAPI and any other necessary dependencies, as well as how to start the application.
• Update the Key Features section to reflect the new features of the application, including the new API endpoints.
• Add a new section on how to use the API, including examples of how to make requests to each endpoint and what data to expect in the response.
--- +++ @@ -39,7 +39,15 @@ ### Setup ``` git clone https://github.com/Haste171/langchain-chatbot.git +cd langchain-chatbot +pip install -r requirements.txt ``` +### Run the FastAPI Application +Ensure you have installed FastAPI and Uvicorn, then run the following commands: +``` +uvicorn app.main:app --reload +``` +This will start the FastAPI server, making the Langchain Chatbot API available at `http://localhost:8000` where you can send request to the endpoints specified. Reference [example.env](https://github.com/Haste171/langchain-chatbot/blob/main/example.env) to create `.env` file ```python @@ -56,7 +64,10 @@ docker run -d langchain-chatbot ``` -# 🔧 Key Features +# + +✅ FastAPI based Web API Integration +✅ Ingest and Query through RESTful Endpoints🔧 Key Features ✅ Credential Manager (OpenAI Keys) @@ -92,4 +103,35 @@ ![fixed-prev](https://cdn.discordapp.com/attachments/1114412425115086888/1114420571833376768/image.png) ![fixed-prev](https://cdn.discordapp.com/attachments/1114412425115086888/1114421482429354065/image.png) -Maintained by Developers of [legalyze.ai](https://legalyze.ai)+Maintained by Developers of [legalyze.ai](https://legalyze.ai) + +# 📄 API Usage +Here's how you can interact with the API: + +### Ingest Data +Send a POST request to `/ingest` to ingest data: +```python +import requests +response = requests.post('http://localhost:8000/ingest') +print(response.json()) +``` +Expect a confirmation response that the data has been ingested. + +### Query Data +Send a GET request to `/query/{question}` with your question: +```python +import requests +question = 'What is the answer to my question?' +response = requests.get(f'http://localhost:8000/query/{question}') +print(response.json()) +``` + +### Chat History +Retrieve the chat history by sending a GET request to `/chat_history`: +```python +import requests +response = requests.get('http://localhost:8000/chat_history') +print(response.json()) +``` + +These endpoints will allow you to ingest, query, and view the history of interactions with the Langchain Chatbot API.
README.md
✓ Edit
Check README.md with contents:
Ran GitHub Actions for 58e5d481032dce6466df6b14bef20ac93cf48f41:
deprecated/chatbot.py
✓ https://github.com/Haste171/langchain-chatbot/commit/241f9d3a4eb32a6b0f09f99d8c05d670b3de0e97 Edit
Modify deprecated/chatbot.py with contents:
• Refactor the code in the `deprecated/chatbot.py` file to be used as functions in the new FastAPI application.
• Remove any code related to the Discord bot, as this will no longer be used.
• Update the `ingest` and `query` functions to accept parameters from the API requests and return data in a format that can be returned as a JSON response.
--- +++ @@ -1,13 +1,9 @@ # Import necessary modules -from colorama import init, Fore, Style import os import json from utils.ingest import ingest from utils.query import query from dotenv import load_dotenv - -# Initialize colorama module -init() # Load environment variables load_dotenv() @@ -21,53 +17,8 @@ temperature = 0.7 source_amount = 4 -# Print the startup display -print(f"""{Fore.WHITE}Using the following credentials:{Fore.WHITE} -OpenAI API Key: {Fore.RED}{openai_api_key}{Fore.WHITE} -Pinecone API Key: {Fore.BLUE}{pinecone_api_key}{Fore.WHITE} -Pinecone Environment: {Fore.BLUE}{pinecone_environment}{Fore.WHITE} -Pinecone Index: {Fore.BLUE}{pinecone_index}{Fore.WHITE} -Pinecone Namespace: {Fore.GREEN}{pinecone_namespace}{Fore.WHITE} - -{Fore.WHITE}Using the following settings:{Fore.WHITE} -Temperature (Creativity): {Fore.MAGENTA}{temperature}{Fore.WHITE} -Sources (Cites): {Fore.MAGENTA}{source_amount}{Fore.WHITE} -""") - # Check whether the user wants to use Pinecone -r = input('Do you want to use Pinecone? (Y/N): ') -if r == 'Y' and pinecone_api_key != '': - use_pinecone = True -else: - print('Not using Pinecone or empty Pinecone API key provided. Using Chroma instead') - use_pinecone = False - -# Check whether the user wants to ingest -r = input('Do you want to ingest? (Y/N): ') - -# If the user wants to ingest, call the ingest function -if r == 'Y': - ingest_response = ingest(openai_api_key=openai_api_key, pinecone_api_key=pinecone_api_key, - pinecone_environment=pinecone_environment, pinecone_index=pinecone_index, - pinecone_namespace=pinecone_namespace, use_pinecone=use_pinecone) - print(ingest_response) - -# If the user doesn't want to ingest, check whether to use Pinecone or Chroma -elif r == 'N': - if use_pinecone: - print('Using already ingested namespace at Pinecone.') - else: - print('Using already ingested vectors at ./vectorstore.') - -# If no method provided, skip -else: - print('No method given, passing') - pass - -# Call the query function and set up a chat loop -process = query(openai_api_key=openai_api_key, pinecone_api_key=pinecone_api_key, - pinecone_environment=pinecone_environment, pinecone_index=pinecone_index, - pinecone_namespace=pinecone_namespace, temperature=temperature, sources=source_amount, use_pinecone=use_pinecone) +use_pinecone = True if pinecone_api_key else False def chat_loop(): # Set up chat history list
deprecated/chatbot.py
✓ Edit
Check deprecated/chatbot.py with contents:
Ran GitHub Actions for 241f9d3a4eb32a6b0f09f99d8c05d670b3de0e97:
I have finished reviewing the code for completeness. I did not find errors for sweep/convert_langchain_chatbot_to_an_api
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord
Instead of using a Discord bot to allow connection to the langchain chatbot, rewrite the code to use FastAPI to do so.
Checklist
- [X] Create `app/main.py` ✓ https://github.com/Haste171/langchain-chatbot/commit/b7ea58b44f72e2997d52f5957d223c80301d9903 [Edit](https://github.com/Haste171/langchain-chatbot/edit/sweep/convert_langchain_chatbot_to_an_api/app/main.py) - [X] Running GitHub Actions for `app/main.py` ✓ [Edit](https://github.com/Haste171/langchain-chatbot/edit/sweep/convert_langchain_chatbot_to_an_api/app/main.py) - [X] Modify `README.md` ✓ https://github.com/Haste171/langchain-chatbot/commit/58e5d481032dce6466df6b14bef20ac93cf48f41 [Edit](https://github.com/Haste171/langchain-chatbot/edit/sweep/convert_langchain_chatbot_to_an_api/README.md#L23-L59) - [X] Running GitHub Actions for `README.md` ✓ [Edit](https://github.com/Haste171/langchain-chatbot/edit/sweep/convert_langchain_chatbot_to_an_api/README.md#L23-L59) - [X] Modify `deprecated/chatbot.py` ✓ https://github.com/Haste171/langchain-chatbot/commit/241f9d3a4eb32a6b0f09f99d8c05d670b3de0e97 [Edit](https://github.com/Haste171/langchain-chatbot/edit/sweep/convert_langchain_chatbot_to_an_api/deprecated/chatbot.py) - [X] Running GitHub Actions for `deprecated/chatbot.py` ✓ [Edit](https://github.com/Haste171/langchain-chatbot/edit/sweep/convert_langchain_chatbot_to_an_api/deprecated/chatbot.py)