diff --git a/notebooks/chat_with_SQL_3_ways.ipynb b/notebooks/chat_with_SQL_3_ways.ipynb index 43e8948..d8949ce 100644 --- a/notebooks/chat_with_SQL_3_ways.ipynb +++ b/notebooks/chat_with_SQL_3_ways.ipynb @@ -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", @@ -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}" ] }, { @@ -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",