Find answers from the community

Updated 10 months ago

guys, qp = QP(

guys, qp = QP(
modules={
"input": InputComponent(),
"table_retriever": obj_retriever,
"table_output_parser": table_parser_component,
"text2sql_prompt": text2sql_prompt,
"text2sql_llm": llm,
"sql_output_parser": sql_parser_component,
"sql_retriever": sql_retriever,
"response_synthesis_prompt": response_synthesis_prompt,
"response_synthesis_llm": llm,
},
verbose=True,
)

how do i get to do a print of the SQL syntax?
is there a way to do qp.[somethinghere] to get the sql ? i would like to show it in my streamlit app
L
M
17 comments
I think probably, you can add a custom module at the end of the pipeline to return both the LLM response and the generated SQL
but we cant access the module above ? like str(qp.Modules["sql_output_parser"]) something like that
I don't think so. Need to add an element to the pipeline to get the final outputs you want, that collects the outputs of the text2sql_llm and response synthesizer I think

https://docs.llamaindex.ai/en/stable/module_guides/querying/pipeline/usage_pattern.html#subclassing-a-customquerycomponent
(accessing module inputs/outputs dynamically like you suggested is in the roadmap though)
im reading it but i dont know where to start 😦
Plain Text
from llama_index.query_pipeline import CustomQueryComponent
from typing import Dict, Any


class MyComponent(CustomQueryComponent):
    """My component."""

    @property
    def _input_keys(self) -> set:
        """Input keys dict."""
        return {"sql", "response"}

    @property
    def _output_keys(self) -> set:
        # can do multi-outputs too
        return {"sql", "response"}

    def _run_component(self, **kwargs) -> Dict[str, Any]:
        """Run the component."""
        sql = kwargs.get("sql")
        response = kwargs.get("response")
        return {"sql": sql, "response": response} 


modules={ ..., "final_output": MyComponent())
...

qp.add_link("text2sql_llm", "final_output", dest_key="sql")
qp.add_link("response_synthesis_llm", "final_output", dest_key="response")
That should work I think
lollok wait let me check all this πŸ™‚
ok but hold on... how do I do the print or like... with streamlit st.write(.. ?) on it ?
because what that does it.. im adding to module a "final_output" but how do I get to it after? isnt it the same problem ?
Plain Text
output = qp.run(...)
print(output['sql'])
print(str(output['response']))
I think it will be like that
it almost worked...but it so strange, because in the command prompt, i saw :
SQLResult: 5000.00
Answer: The total sales for yesterday were $50...
response: assistant: Your total sales for yesterday are None.

the real answer is "none" in the 'response' its good. i have no idea why its writting soemthing else in "answer"
maybe 5000 means something else like the token amount or something from that line : qp.add_link("text2sql_llm", "final_output", dest_key="sql")
Add a reply
Sign up and join the conversation on Discord