Skip to content

Commit

Permalink
Fix issue with runserver.sh not starting the fastapi backend
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomarin committed Jan 2, 2025
1 parent c1b4c49 commit b70ee69
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 190 deletions.
74 changes: 8 additions & 66 deletions 08-SQLDB_QA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 19,
"id": "ae80c022-415e-40d1-b205-1744a3164d70",
"metadata": {
"tags": []
Expand All @@ -665,7 +665,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 20,
"id": "405e143c-4af5-40ec-8e61-7a7a8082d6bb",
"metadata": {
"tags": []
Expand All @@ -678,22 +678,21 @@
"================================\u001b[1m Human Message \u001b[0m=================================\n",
"\n",
"\n",
"How may patients were hospitalized during July 2020 in Texas. \n",
"And nationwide as the total of all states? \n",
"what is the country with the most deaths in 2020?\n",
"\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" sql_db_list_tables (call_fzzhjGUcFROemmaPpaEpTo7W)\n",
" Call ID: call_fzzhjGUcFROemmaPpaEpTo7W\n",
" sql_db_list_tables (call_YeuH23OeP957TH7Smsws4T3F)\n",
" Call ID: call_YeuH23OeP957TH7Smsws4T3F\n",
" Args:\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
"Name: sql_db_list_tables\n",
"\n",
"covidtracking\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" sql_db_schema (call_anU28AvtoySfkJy0LpDrbqUY)\n",
" Call ID: call_anU28AvtoySfkJy0LpDrbqUY\n",
" sql_db_schema (call_Qy9jK1zbne5a1bpMI1jnpz61)\n",
" Call ID: call_Qy9jK1zbne5a1bpMI1jnpz61\n",
" Args:\n",
" table_names: covidtracking\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
Expand Down Expand Up @@ -752,65 +751,8 @@
"2021-03-07\tAR\t5319.0\t4308.0\t22\t1011.0\t14926.0\t14926.0\t335.0\t11\t0.0\t141.0\t2480716.0\t3267\t0.0\t0.0\t2480716.0\t1533.0\t65.0\t324818.0\t255726.0\t165\t0\t0.0\t0.0\t0.0\t81803.0\t0.0\t315517.0\t0.0\t0\t2736442.0\t3380\t0.0\t0.0\t0.0\t481311.0\t0.0\t0\t2736442.0\t3380\n",
"*/\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" sql_db_query_checker (call_g15qBiPg1fVo1cmxJV8et93w)\n",
" Call ID: call_g15qBiPg1fVo1cmxJV8et93w\n",
" Args:\n",
" query: SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE state = 'TX' AND date LIKE '2020-07%'\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
"Name: sql_db_query_checker\n",
"\n",
"```sql\n",
"SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE state = 'TX' AND date LIKE '2020-07%'\n",
"```\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" sql_db_query (call_HXscAkg5WYokupm0wqOSrUft)\n",
" Call ID: call_HXscAkg5WYokupm0wqOSrUft\n",
" Args:\n",
" query: SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE state = 'TX' AND date LIKE '2020-07%'\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
"Name: sql_db_query\n",
"\n",
"[(0,)]\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" sql_db_query_checker (call_vCIhJWRuprNUfugeLQmzZDeH)\n",
" Call ID: call_vCIhJWRuprNUfugeLQmzZDeH\n",
" Args:\n",
" query: SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE date LIKE '2020-07%'\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
"Name: sql_db_query_checker\n",
"\n",
"```sql\n",
"SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE date LIKE '2020-07%'\n",
"```\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" sql_db_query (call_ZnEiLBqfExDZVBvwIkEXQv76)\n",
" Call ID: call_ZnEiLBqfExDZVBvwIkEXQv76\n",
" Args:\n",
" query: SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE date LIKE '2020-07%'\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
"Name: sql_db_query\n",
"\n",
"[(63105,)]\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
"Final Answer: During July 2020, there were no new hospitalizations reported in Texas, while nationwide, the total number of new hospitalizations was 63,105.\n",
"\n",
"Explanation:\n",
"I queried the `covidtracking` table to find the sum of the `hospitalizedIncrease` column for the state of Texas and for all states during July 2020. The query for Texas returned a sum of 0, indicating no new hospitalizations were reported. The nationwide query returned a sum of 63,105, representing the total new hospitalizations across all states. The SQL queries used were:\n",
"\n",
"For Texas:\n",
"```sql\n",
"SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE state = 'TX' AND date LIKE '2020-07%'\n",
"```\n",
"\n",
"For nationwide:\n",
"```sql\n",
"SELECT SUM(hospitalizedIncrease) FROM covidtracking WHERE date LIKE '2020-07%'\n",
"```\n"
"The `covidtracking` table contains data by state, not by country. Therefore, I cannot determine the country with the most deaths in 2020 from this database. If you have any other questions related to the data available, feel free to ask!\n"
]
}
],
Expand Down
102 changes: 22 additions & 80 deletions 12-Smart_Agent.ipynb

Large diffs are not rendered by default.

76 changes: 44 additions & 32 deletions 14-BotService-API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Converstion id: 9Z6Nvynf2Pz6zqk0kpprug-us\n",
"CPU times: user 29.7 ms, sys: 7.71 ms, total: 37.4 ms\n",
"Wall time: 14.8 s\n"
"Converstion id: JRo8PNzwVQc7aVGfRb9y8J-us\n",
"CPU times: user 37.6 ms, sys: 379 μs, total: 38 ms\n",
"Wall time: 13 s\n"
]
}
],
Expand Down Expand Up @@ -129,28 +129,28 @@
"data": {
"text/plain": [
"[{'type': 'message',\n",
" 'id': '9Z6Nvynf2Pz6zqk0kpprug-us|0000000',\n",
" 'timestamp': '2024-12-26T21:46:06.7020125Z',\n",
" 'id': 'JRo8PNzwVQc7aVGfRb9y8J-us|0000000',\n",
" 'timestamp': '2025-01-02T07:00:12.4051897Z',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'BotId-ykymrki2enoa6', 'name': 'BotId-ykymrki2enoa6'},\n",
" 'conversation': {'id': '9Z6Nvynf2Pz6zqk0kpprug-us'},\n",
" 'from': {'id': 'BotId-ixqo5iaqmpzwc', 'name': 'BotId-ixqo5iaqmpzwc'},\n",
" 'conversation': {'id': 'JRo8PNzwVQc7aVGfRb9y8J-us'},\n",
" 'text': \"\\nHello and welcome! 👋\\n\\nMy name is Jarvis, a smart virtual assistant designed to assist you.\\nHere's how you can interact with me:\\n\\nI have various plugins and tools at my disposal to answer your questions effectively. Here are the available options:\\n\\n1. 🌐 **websearch**: This tool allows me to access the internet and provide current information from the web.\\n\\n2. 🔍 **docsearch**: This tool allows me to search a specialized search engine index. It includes the dialogues from all the Episodes of the TV Show: Friends, and 90,000 Covid research articles for 2020-2021.\\n\\n3. 📊 **sqlsearch**: By utilizing this tool, I can access a SQL database containing information about Covid cases, deaths, and hospitalizations in 2020-2021.\\n\\n4. 📊 **apisearch**: By utilizing this tool, I can access the KRAKEN API and give you information about Crypto Spot pricing as well as currency pricing.\\n\\nFrom all of my sources, I will provide the necessary information and also mention the sources I used to derive the answer. This way, you can have transparency about the origins of the information and understand how I arrived at the response.\\n\\nTo make the most of my capabilities, please mention the specific tool you'd like me to use when asking your question. Here's an example:\\n\\n```\\n@websearch, who is the daughter of the President of India?\\n@docsearch, Does chloroquine really works against covid?\\n@sqlsearch, what state had more deaths from COVID in 2020?\\n@apisearch, What is the latest price of Bitcoin and USD/EURO?\\n```\\n\\nFeel free to ask any question and specify the tool you'd like me to utilize. I'm here to assist you!\\n\\n---\\n\",\n",
" 'inputHint': 'acceptingInput'},\n",
" {'type': 'message',\n",
" 'id': '9Z6Nvynf2Pz6zqk0kpprug-us|0000001',\n",
" 'timestamp': '2024-12-26T21:46:05.7925414Z',\n",
" 'id': 'JRo8PNzwVQc7aVGfRb9y8J-us|0000001',\n",
" 'timestamp': '2025-01-02T07:00:11.9475003Z',\n",
" 'serviceUrl': 'https://directline.botframework.com/',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'user'},\n",
" 'conversation': {'id': '9Z6Nvynf2Pz6zqk0kpprug-us'},\n",
" 'conversation': {'id': 'JRo8PNzwVQc7aVGfRb9y8J-us'},\n",
" 'text': 'what is CLP?'},\n",
" {'type': 'message',\n",
" 'id': '9Z6Nvynf2Pz6zqk0kpprug-us|0000002',\n",
" 'timestamp': '2024-12-26T21:46:14.7980039Z',\n",
" 'id': 'JRo8PNzwVQc7aVGfRb9y8J-us|0000002',\n",
" 'timestamp': '2025-01-02T07:00:19.6273655Z',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'BotId-ykymrki2enoa6', 'name': 'BotId-ykymrki2enoa6'},\n",
" 'conversation': {'id': '9Z6Nvynf2Pz6zqk0kpprug-us'},\n",
" 'text': 'CLP stands for \"Cleaner, Lubricant, and Protectant.\" It is a type of gun oil designed to perform three main functions: cleaning, lubricating, and protecting firearms. CLP is typically made from a blend of solvents, oils, and other additives that help dissolve dirt and grime, lubricate moving parts, and protect metal surfaces from corrosion and wear [[1](https://www.buffalorifles.org/blog/what-is-clp-for-guns/)].\\n\\n### Key Functions of CLP:\\n1. **Cleaning**: CLP helps remove dirt, grime, and carbon buildup from the metal surfaces of firearms.\\n2. **Lubrication**: It provides a protective layer of lubrication that reduces friction between moving parts, which can enhance the performance and longevity of the firearm.\\n3. **Protection**: CLP forms a protective barrier on metal surfaces to prevent rust and corrosion [[2](https://www.pewpewtactical.com/best-gun-oil-grease/)].\\n\\n### Usage:\\nTo use CLP, you typically apply a small amount to a clean cloth and wipe down the firearm, paying special attention to moving parts. It\\'s important to follow the manufacturer\\'s instructions for best results [[1](https://www.buffalorifles.org/blog/what-is-clp-for-guns/)].\\n\\n### Benefits:\\n- Improves firearm performance by keeping it clean and lubricated.\\n- Protects against rust and corrosion.\\n- Reduces wear on moving parts, which can improve accuracy and reliability [[2](https://www.pewpewtactical.com/best-gun-oil-grease/)].\\n\\nFor more detailed information, you can refer to the sources: [Buffalo Rifles](https://www.buffalorifles.org/blog/what-is-clp-for-guns/) and [Pew Pew Tactical](https://www.pewpewtactical.com/best-gun-oil-grease/).',\n",
" 'from': {'id': 'BotId-ixqo5iaqmpzwc', 'name': 'BotId-ixqo5iaqmpzwc'},\n",
" 'conversation': {'id': 'JRo8PNzwVQc7aVGfRb9y8J-us'},\n",
" 'text': 'The acronym \"CLP\" can stand for a variety of meanings depending on the context. Some of the common definitions include:\\n\\n1. **Chilean Peso** - The currency of Chile.\\n2. **Classification, Labelling & Packaging** - An EU regulation for the safe handling of hazardous chemicals.\\n3. **Certified Linux Professional** - A certification for Linux professionals.\\n4. **Constraint Logic Programming** - A form of programming in computer science.\\n5. **Cleaner, Lubricant, and Preservative** - Often used in the context of maintenance products.\\n6. **Constituency Labour Party** - A local organization of the UK Labour Party.\\n\\nThese are just a few examples, and there are many other possible meanings for CLP depending on the specific field or industry [[1]](https://www.acronymfinder.com/CLP.html) [[2]](https://acronyms.thefreedictionary.com/CLP).',\n",
" 'inputHint': 'acceptingInput'}]"
]
},
Expand Down Expand Up @@ -297,7 +297,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"id": "c50b5ae7-65df-4c92-9f10-edf5536a4b42",
"metadata": {
"tags": []
Expand All @@ -307,7 +307,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Converstion id: JGjbJcBaMR1Cq1ktrXQ2VV-us\n"
"Converstion id: 11CeetoQ0lZLQbFmYo53M3-us\n"
]
}
],
Expand All @@ -331,19 +331,19 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 11,
"id": "8fd36878-03e5-468f-b4cc-d04a720b5bff",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"QUESTION = \"@sqlsearch, what is the country with the most deaths in 2020?\""
"QUESTION = \"@sqlsearch, what is the state with the most deaths in 2020?\""
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 12,
"id": "3367361f-3372-47a5-a156-45fb7d6cfd8f",
"metadata": {
"tags": []
Expand All @@ -355,15 +355,21 @@
"text": [
"Message sent status code: 200\n",
"Response text: {\n",
" \"id\": \"JGjbJcBaMR1Cq1ktrXQ2VV-us|0000001\"\n",
" \"id\": \"11CeetoQ0lZLQbFmYo53M3-us|0000004\"\n",
"}\n",
"Final Answer: The country with the most deaths in 2020 is New York, with a total of 6,530,995 deaths.\n",
"Final Answer: The state with the most deaths in 2020 was New York, with a total of 6,530,995 deaths.\n",
"\n",
"Explanation: I queried the `covidtracking` table to sum the `death` column for each state where the date is in the year 2020. The results were grouped by state and ordered by the total number of deaths in descending order. The query returned New York as the state with the highest total deaths, amounting to 6,530,995. The SQL query used is:\n",
"Explanation:\n",
"I queried the `covidtracking` table to sum the `death` column for each state where the date starts with '2020'. The query grouped the results by state and ordered them in descending order of total deaths. The query used is:\n",
"\n",
"```sql\n",
"SELECT state, SUM(death) AS total_deaths FROM covidtracking WHERE date LIKE '2020%' GROUP BY state ORDER BY total_deaths DESC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY\n",
"SELECT TOP 1 state, SUM(death) AS total_deaths \n",
"FROM covidtracking \n",
"WHERE date LIKE '2020%' \n",
"GROUP BY state \n",
"ORDER BY total_deaths DESC\n",
"```\n",
"This query returned New York as the state with the highest number of deaths in 2020.\n",
"25 seconds have elapsed without new messages. Exiting...\n"
]
}
Expand All @@ -382,7 +388,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 13,
"id": "17dc446f-0bff-4704-93a3-857c4b294930",
"metadata": {
"tags": []
Expand All @@ -394,7 +400,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 14,
"id": "e6143c06-0cf0-4f0a-9077-36a5604d40c3",
"metadata": {
"tags": []
Expand All @@ -406,15 +412,21 @@
"text": [
"Message sent status code: 200\n",
"Response text: {\n",
" \"id\": \"JGjbJcBaMR1Cq1ktrXQ2VV-us|0000003\"\n",
" \"id\": \"11CeetoQ0lZLQbFmYo53M3-us|0000006\"\n",
"}\n",
"Final Answer: The state with the least deaths in 2020 is AS, with a total of 0 deaths.\n",
"Final Answer: The state with the least deaths in 2020 was American Samoa, with a total of 0 deaths.\n",
"\n",
"Explanation: I queried the `covidtracking` table to sum the `death` column for each state where the date is in the year 2020. The results were grouped by state and ordered by the total number of deaths in ascending order. The query returned AS as the state with the least total deaths, amounting to 0. The SQL query used is:\n",
"Explanation:\n",
"I queried the `covidtracking` table to sum the `death` column for each state where the date starts with '2020'. The query grouped the results by state and ordered them in ascending order of total deaths. The query used is:\n",
"\n",
"```sql\n",
"SELECT state, SUM(death) AS total_deaths FROM covidtracking WHERE date LIKE '2020%' GROUP BY state ORDER BY total_deaths ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY\n",
"SELECT TOP 1 state, SUM(death) AS total_deaths \n",
"FROM covidtracking \n",
"WHERE date LIKE '2020%' \n",
"GROUP BY state \n",
"ORDER BY total_deaths ASC\n",
"```\n",
"This query returned American Samoa as the state with the lowest number of deaths in 2020, with a total of 0 deaths.\n",
"25 seconds have elapsed without new messages. Exiting...\n"
]
}
Expand Down Expand Up @@ -472,9 +484,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "GPTSearch2 (Python 3.12)",
"display_name": "GPTSearch3 (Python 3.12)",
"language": "python",
"name": "gptsearch2"
"name": "gptsearch3"
},
"language_info": {
"codemirror_mode": {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The repo is made to teach you step-by-step on how to build a OpenAI-based RAG-ba
---
## Demo

(COMING SOON)
[https://gptsmartsearch-frontend.azurewebsites.net](https://gptsmartsearch-frontend.azurewebsites.net)


---
Expand Down
16 changes: 8 additions & 8 deletions apps/backend/fastapi/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

##########################################################
## Uncomment this section to run locally
# current_file = Path(__file__).resolve()
# library_path = current_file.parents[4]
# data_path = library_path / "data"
# sys.path.append(str(library_path)) # ensure we can import "common" etc.
# load_dotenv(str(library_path) + "/credentials.env")
# csv_file_path = data_path / "all-states-history.csv"
# api_file_path = data_path / "openapi_kraken.json"
current_file = Path(__file__).resolve()
library_path = current_file.parents[4]
data_path = library_path / "data"
sys.path.append(str(library_path)) # ensure we can import "common" etc.
load_dotenv(str(library_path) + "/credentials.env")
csv_file_path = data_path / "all-states-history.csv"
api_file_path = data_path / "openapi_kraken.json"
##########################################################

# from the graph module
Expand Down Expand Up @@ -90,7 +90,7 @@ async def lifespan(app: FastAPI):
app = FastAPI(
title="Multi-Agent GPT Assistant (FastAPI)",
version="1.0",
description="Demonstration with logging at each step.",
description="GPT Smart Search Engine - FastAPI Backend",
lifespan=lifespan,
)

Expand Down
Binary file modified apps/backend/fastapi/backend.zip
Binary file not shown.
Binary file modified apps/frontend/frontend.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions common/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fastapi
sse_starlette
sseclient-py
uvicorn
gunicorn




3 changes: 0 additions & 3 deletions credentials.env
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@ AZURE_SPEECH_VOICE_NAME="en-US-AriaNeural"
BOT_ID="ENTER YOUR VALUE HERE" # This is the name of your bot service created in Notebook 12
BOT_SERVICE_DIRECT_LINE_SECRET="ENTER YOUR VALUE HERE" # Find this in Azure Bot Service -> Channels -> Direct Line




0 comments on commit b70ee69

Please sign in to comment.