Add headers to file chat function (#35)
Browse files- Add headers to file chat function (07ada2b07523cf88293b6e3667bb8a10808639d8)
- functions/chat_functions.py +13 -3
functions/chat_functions.py
CHANGED
@@ -3,11 +3,12 @@ from utils import TEMP_DIR, message_dict
|
|
3 |
from haystack.dataclasses import ChatMessage
|
4 |
from haystack.components.generators.chat import OpenAIChatGenerator
|
5 |
|
|
|
|
|
6 |
chat_generator = OpenAIChatGenerator(model="gpt-4o")
|
7 |
response = None
|
8 |
|
9 |
def example_question_generator(session_hash):
|
10 |
-
import sqlite3
|
11 |
example_response = None
|
12 |
example_messages = [
|
13 |
ChatMessage.from_system(
|
@@ -64,7 +65,7 @@ def doc_db_example_question_generator(session_hash, db_collections, db_name, db_
|
|
64 |
f"You are a helpful and knowledgeable agent who has access to an MongoDB NoSQL document database called {db_name}."
|
65 |
)
|
66 |
]
|
67 |
-
|
68 |
example_messages.append(ChatMessage.from_user(text=f"""We have a MongoDB NoSQL document database with the following collections: {db_collections}.
|
69 |
The schema of these collections is: {db_schema}.
|
70 |
We also have an AI agent with access to the same database that will be performing data analysis.
|
@@ -87,13 +88,22 @@ def chatbot_with_fc(message, history, session_hash):
|
|
87 |
"scatter_chart_generation_func":scatter_chart_generation_func, "pie_chart_generation_func":pie_chart_generation_func,
|
88 |
"histogram_generation_func":histogram_generation_func,
|
89 |
"regression_func":regression_func }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
if message_dict[session_hash]['file_upload'] != None:
|
92 |
message_dict[session_hash]['file_upload'].append(ChatMessage.from_user(message))
|
93 |
else:
|
94 |
messages = [
|
95 |
ChatMessage.from_system(
|
96 |
-
"""You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'.
|
97 |
You also have access to a function, called table_generation_func, that can take a query.csv file generated from our sql query and returns an iframe that we should display in our chat window.
|
98 |
You also have access to a scatter plot function, called scatter_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a scatter plot and returns an iframe that we should display in our chat window.
|
99 |
You also have access to a line chart function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a line chart and returns an iframe that we should display in our chat window.
|
|
|
3 |
from haystack.dataclasses import ChatMessage
|
4 |
from haystack.components.generators.chat import OpenAIChatGenerator
|
5 |
|
6 |
+
import sqlite3
|
7 |
+
|
8 |
chat_generator = OpenAIChatGenerator(model="gpt-4o")
|
9 |
response = None
|
10 |
|
11 |
def example_question_generator(session_hash):
|
|
|
12 |
example_response = None
|
13 |
example_messages = [
|
14 |
ChatMessage.from_system(
|
|
|
65 |
f"You are a helpful and knowledgeable agent who has access to an MongoDB NoSQL document database called {db_name}."
|
66 |
)
|
67 |
]
|
68 |
+
|
69 |
example_messages.append(ChatMessage.from_user(text=f"""We have a MongoDB NoSQL document database with the following collections: {db_collections}.
|
70 |
The schema of these collections is: {db_schema}.
|
71 |
We also have an AI agent with access to the same database that will be performing data analysis.
|
|
|
88 |
"scatter_chart_generation_func":scatter_chart_generation_func, "pie_chart_generation_func":pie_chart_generation_func,
|
89 |
"histogram_generation_func":histogram_generation_func,
|
90 |
"regression_func":regression_func }
|
91 |
+
|
92 |
+
session_path = 'file_upload'
|
93 |
+
|
94 |
+
dir_path = TEMP_DIR / str(session_hash) / str(session_path)
|
95 |
+
connection = sqlite3.connect(f'{dir_path}/data_source.db')
|
96 |
+
cur=connection.execute('select * from data_source')
|
97 |
+
columns = [i[0] for i in cur.description]
|
98 |
+
cur.close()
|
99 |
+
connection.close()
|
100 |
|
101 |
if message_dict[session_hash]['file_upload'] != None:
|
102 |
message_dict[session_hash]['file_upload'].append(ChatMessage.from_user(message))
|
103 |
else:
|
104 |
messages = [
|
105 |
ChatMessage.from_system(
|
106 |
+
f"""You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source' that contains the following columns: {columns}.
|
107 |
You also have access to a function, called table_generation_func, that can take a query.csv file generated from our sql query and returns an iframe that we should display in our chat window.
|
108 |
You also have access to a scatter plot function, called scatter_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a scatter plot and returns an iframe that we should display in our chat window.
|
109 |
You also have access to a line chart function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a line chart and returns an iframe that we should display in our chat window.
|