Вывод, который я получаю из приведенного ниже кода:
{'input': '2+2', 'text': 'Конечно, я был бы рад помочь с этим вопрос!\n\nВы задали вопрос: "2 + 2".\n\nЧтобы ответить на этот вопрос, мы можем следовать порядку операций, который часто называют аббревиатурой PEMDAS: круглые скобки, показатели степени, умножение и деление. (слева направо), сложение и вычитание (слева направо).\n\nВ этом случае мы просто складываем два числа, поэтому нам не нужно беспокоиться о порядке операций. Мы можем просто сложить 2 + 2, чтобы получить:\n\n2 + 2 = 4\n\nИтак, ответ на вопрос «2 + 2» — 4. Если у вас есть еще вопросы, дайте мне знать!'
Ожидается:
математика
В приведенном выше примере мне просто нужна цепочка результатов, которые были выполнены.
from langchain.utilities import SQLDatabase
from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.agents.agent_types import AgentType
from langchain.prompts import PromptTemplate
from langchain.prompts.chat import ChatPromptTemplate
from langchain.chains import LLMChain
from langchain.chains.router import MultiPromptChain
from langchain.chains.router.llm_router import LLMRouterChain, RouterOutputParser
from google.colab import userdata
from langchain_groq import ChatGroq
GROQ=userdata.get('GROQ')
# Initialize the ChatGroq language model
llm = ChatGroq(temperature=0.1,
groq_api_key=GROQ,
model_name="mixtral-8x7b-32768",
max_tokens=32000,
top_p=0.1,
frequency_penalty=0.1,
presence_penalty=0.1)
# Define prompt templates for different subjects
physics_template = """You are a very smart physics professor. \
You are great at answering questions about physics in a concise\
and easy to understand manner. \
When you don't know the answer to a question you admit\
that you don't know.
Here is a question:
{input}"""
math_template = """You are a very good mathematician. \
You are great at answering math questions. \
You are so good because you are able to break down \
hard problems into their component parts,
answer the component parts, and then put them together\
to answer the broader question.
Here is a question:
{input}"""
history_template = """You are a very good historian. \
You have an excellent knowledge of and understanding of people,\
events and contexts from a range of historical periods. \
You have the ability to think, reflect, debate, discuss and \
evaluate the past. You have a respect for historical evidence\
and the ability to make use of it to support your explanations \
and judgements.
Here is a question:
{input}"""
# Defining the prompt templates
prompt_infos = [
{
"name": "physics",
"description": "Good for answering questions about physics",
"prompt_template": physics_template
},
{
"name": "math",
"description": "Good for answering math questions",
"prompt_template": math_template
},
{
"name": "History",
"description": "Good for answering history questions",
"prompt_template": history_template
}
]
destination_chains = {}
for p_info in prompt_infos:
name = p_info["name"]
prompt_template = p_info["prompt_template"]
prompt = ChatPromptTemplate.from_template(template=prompt_template)
chain = LLMChain(llm=llm, prompt=prompt)
destination_chains[name] = chain
destinations = [f"{p['name']}: {p['description']}" for p in prompt_infos]
destinations_str = "\n".join(destinations)
default_prompt = ChatPromptTemplate.from_template("{input}")
default_chain = LLMChain(llm=llm, prompt=default_prompt)
router_template = MULTI_PROMPT_ROUTER_TEMPLATE.format(
destinations=destinations_str
)
router_prompt = PromptTemplate(
template=router_template,
input_variables=["input"],
output_parser=RouterOutputParser(),
)
router_chain = LLMRouterChain.from_llm(llm, router_prompt)
chain = MultiPromptChain(router_chain=router_chain,
destination_chains=destination_chains,
default_chain=default_chain, verbose=True
)
Подробнее здесь: https://stackoverflow.com/questions/784 ... -the-input