ValueError: too many values to unpack (expected 2)
llm = OpenAI(model='gpt-3.5-turbo', temperature = 0.0) s_sql_retriever = SQLRetriever(sql_database) # Needed to make function to output str def s_sql_retriever_fn(task: Task, state: Dict[str, Any], sql_query: str) -> str: """Function to run the retriever.""" node_with_score = s_sql_retriever.retrieve(sql_query) metadata = node_with_score[0].node.metadata output = {"result": metadata['result'], "col_keys": metadata['col_keys']} output_str = f"Retrieved columns: {output.get('col_keys', [])}\n SQL Response: {output.get('result', [])}" return output_str s_sql_retriever_component = AgentFnComponent(fn=s_sql_retriever_fn) s_response_synthesis_prompt_str = ( [instructions redacted] "Query: {query_str}\n" "SQL: {sql_query}\n" "{sql_result_and_col_keys_str}\n" # "Retrieved columns: {retrieved_cols}\n" # "SQL Response: {sql_response}\n" "Response: " ) s_response_synthesis_prompt = PromptTemplate( s_response_synthesis_prompt_str ) s_agent_qp = QP( modules={ "input": s_agent_input_component, "table_retriever": s_obj_retriever_component, "table_output_parser": s_table_parser_component, "retry_prompt": s_prompt, "llm": llm, "sql_output_parser": s_parser_component, "sql_retriever": s_sql_retriever_component, "response_synthesis_prompt": s_response_synthesis_prompt, "response_synthesis_llm": llm, # "output_component": s_agent_output_component, }, verbose=True, )
s_agent_qp.add_link("input", "table_retriever", src_key="input", dest_key="query") s_agent_qp.add_link("table_retriever", "table_output_parser", src_key="output", dest_key="table_schema_objs") s_agent_qp.add_link("input", "retry_prompt", src_key="input", dest_key="query_str") s_agent_qp.add_link( "input", "retry_prompt", src_key="convo_history", dest_key="convo_history") s_agent_qp.add_link("table_output_parser", "retry_prompt", dest_key="schema") s_agent_qp.add_chain(["retry_prompt", "llm", "sql_output_parser"]) s_agent_qp.add_link("sql_output_parser", "sql_retriever", src_key="output", dest_key="sql_query") s_agent_qp.add_link("sql_output_parser", "response_synthesis_prompt", dest_key="sql_query") s_agent_qp.add_link("sql_retriever", "response_synthesis_prompt", dest_key="sql_result_and_col_keys_str") s_agent_qp.add_chain(["response_synthesis_prompt", "response_synthesis_llm"]) # Wrap query pipeline into an agent s_agent_worker = QueryPipelineAgentWorker(s_agent_qp) s_agent = s_agent_worker.as_agent(callback_manager=CallbackManager([]), verbose=True) # Now, use this agent as a tool for another agent s_agent_tool = QueryEngineTool.from_defaults( query_engine=s_agent, name="agent_tool", description="A tool that wraps an advanced text-to-SQL agent", ) answer = s_agent_tool.call("Who does Kevin Martinez report to?")
ValueError Traceback (most recent call last) Cell In[161], line 1 ----> 1 test_answer = s_agent_tool.call("Who does Kevin Martinez report to?") File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/core/instrumentation/dispatcher.py:230, in Dispatcher.span.<locals>.wrapper(func, instance, args, kwargs) 226 self.span_enter( 227 id_=id_, bound_args=bound_args, instance=instance, parent_id=parent_id 228 ) 229 try: --> 230 result = func(*args, **kwargs) 231 except BaseException as e: 232 self.event(SpanDropEvent(span_id=id_, err_str=str(e))) File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/core/tools/query_engine.py:68, in QueryEngineTool.call(self, *args, **kwargs) 66 def call(self, *args: Any, **kwargs: Any) -> ToolOutput: 67 query_str = self._get_query_str(*args, **kwargs) ---> 68 response = self._query_engine.query(query_str) 69 return ToolOutput( 70 content=str(response), 71 tool_name=self.metadata.name, 72 raw_input={"input": query_str}, 73 raw_output=response, 74 ) ... 201 ) 202 else: 203 agent_response, is_done = self.pipeline.run() ValueError: too many values to unpack (expected 2)