Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions notebooks/chat_with_SQL_3_ways.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@
},
"outputs": [],
"source": [
"from typing import List\n",
"from typing import List, Union\n",
"from haystack import component\n",
"from haystack.dataclasses import ChatMessage\n",
"\n",
"@component\n",
"class SQLQuery:\n",
Expand All @@ -242,12 +243,15 @@
" self.connection = sqlite3.connect(sql_database, check_same_thread=False)\n",
"\n",
" @component.output_types(results=List[str], queries=List[str])\n",
" def run(self, queries: List[str]):\n",
" def run(self, queries: List[Union[str, ChatMessage]]):\n",
" results = []\n",
" processed_queries = []\n",
" for query in queries:\n",
" result = pd.read_sql(query, self.connection)\n",
" sql_query = query.text if isinstance(query, ChatMessage) else query\n",
" result = pd.read_sql(sql_query, self.connection)\n",
" results.append(f\"{result}\")\n",
" return {\"results\": results, \"queries\": queries}"
" processed_queries.append(sql_query)\n",
" return {\"results\": results, \"queries\": processed_queries}"
]
},
{
Expand Down Expand Up @@ -484,13 +488,13 @@
"\n",
"routes = [\n",
" {\n",
" \"condition\": \"{{'no_answer' not in replies[0]}}\",\n",
" \"condition\": \"{{'no_answer' not in replies[0].text}}\",\n",
" \"output\": \"{{replies}}\",\n",
" \"output_name\": \"sql\",\n",
" \"output_type\": List[str],\n",
" \"output_type\": List[ChatMessage],\n",
" },\n",
" {\n",
" \"condition\": \"{{'no_answer' in replies[0]}}\",\n",
" \"condition\": \"{{'no_answer' in replies[0].text}}\",\n",
" \"output\": \"{{question}}\",\n",
" \"output_name\": \"go_to_fallback\",\n",
" \"output_type\": str,\n",
Expand Down