-
I like to write narratives in human language after analyzing structured data using a pandas query pipeline. Currently, I am using response_synthesis_prompt for this task. Are there similar research agents in other packages? Specifically, can a research agent review the results and generate a narrative? Is this possible with LlamaIndex? If, yes, can you give me a sample code please? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Yes, it is possible to use LlamaIndex to review the results and generate a narrative. Below is a sample code using import pandas as pd
from llama_index.experimental.query_engine.pandas import PandasQueryEngine
from llama_index.core.response_synthesizers.factory import get_response_synthesizer
from llama_index.core.response_synthesizers.type import ResponseMode
# Sample DataFrame
df = pd.DataFrame(
{
"city": ["Toronto", "Tokyo", "Berlin"],
"population": [2930000, 13960000, 3645000]
}
)
# Initialize the PandasQueryEngine
query_engine = PandasQueryEngine(df=df, verbose=True)
# Get a response synthesizer for narrative generation
response_synthesizer = get_response_synthesizer(response_mode=ResponseMode.GENERATION)
# Query the DataFrame and generate a narrative
response = query_engine.query("What is the population of Tokyo?", response_synthesizer=response_synthesizer)
print(response.response) In this example, the |
Beta Was this translation helpful? Give feedback.
-
@dosu Thank you. What is the difference between 'response_synthesis_prompt' and 'response_synthesizer'? I used prompt to write about my dataset and attributes. |
Beta Was this translation helpful? Give feedback.
Yes, it is okay to use both
response_synthesis_prompt
andresponse_synthesizer
in your query. There are no explicit downsides mentioned in the provided documentation. Theresponse_synthesizer
is a flexible component that can be configured with various modes and custom prompts, including additional variables during query-time.For example, you can customize the prompts used in the response synthesizer and add additional variables: