Replies: 1 comment 5 replies
-
I found a similar unsolved discussion regarding the To address your issue of ensuring comprehensive responses across all questions, you can consider using a query decomposition technique. This involves breaking down your complex input into simpler sub-questions that can be processed individually. Here's an example of how you can achieve this using LangChain: from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage
# Define a pydantic model to enforce the output structure
class Questions(BaseModel):
questions: List[str] = Field(
description="A list of sub-questions related to the input query."
)
# Create an instance of the model and enforce the output structure
model = ChatOpenAI(model="gpt-4o", temperature=0)
structured_model = model.with_structured_output(Questions)
# Define the system prompt
system = """You are a helpful assistant that generates multiple sub-questions related to an input question. \n
The goal is to break down the input into a set of sub-problems / sub-questions that can be answered in isolation. \n"""
# Pass the question to the model
question = """Execute these questions one after one and write answers based on your end results.
1. **Strategic Leadership**: Define and execute a global vision and technical strategy for AI & Gen AI services that aligns with company goals and market trends.
2. **Team Management**: Mentor and manage a multidisciplinary team of data scientists, machine learning engineers, and Gen AI professionals, fostering a culture of innovation and continuous improvement.
"""
questions = structured_model.invoke([SystemMessage(content=system)]+[HumanMessage(content=question)]) This code uses a structured output model to decompose your input into sub-questions, which can then be processed sequentially or in parallel. This approach might be more effective than using To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Currently, my chain is only answering the first question. How can I make it work so that all questions are addressed? Or better ways other than fuzzy_match_runnable?
Beta Was this translation helpful? Give feedback.
All reactions