mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 22:42:05 +00:00
notebook fmt (#12498)
This commit is contained in:
@@ -7,9 +7,10 @@ def _format_docs(docs):
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def format_agent_scratchpad(intermediate_steps):
|
||||
thoughts = ""
|
||||
for action, observation in intermediate_steps:
|
||||
thoughts += action.log
|
||||
thoughts += '</search_query>' + _format_docs(observation)
|
||||
thoughts += "</search_query>" + _format_docs(observation)
|
||||
return thoughts
|
||||
|
@@ -10,16 +10,18 @@ prompt = ChatPromptTemplate.from_template(answer_prompt)
|
||||
|
||||
model = ChatAnthropic(model="claude-2", temperature=0, max_tokens_to_sample=1000)
|
||||
|
||||
chain = {
|
||||
"query": lambda x: x["query"],
|
||||
"information": executor | (lambda x: x["output"])
|
||||
} | prompt | model | StrOutputParser()
|
||||
chain = (
|
||||
{"query": lambda x: x["query"], "information": executor | (lambda x: x["output"])}
|
||||
| prompt
|
||||
| model
|
||||
| StrOutputParser()
|
||||
)
|
||||
|
||||
# Add typing for the inputs to be used in the playground
|
||||
|
||||
|
||||
class Inputs(BaseModel):
|
||||
query: str
|
||||
query: str
|
||||
|
||||
|
||||
chain = chain.with_types(input_type=Inputs)
|
||||
|
@@ -9,21 +9,33 @@ from .output_parser import parse_output
|
||||
from .prompts import retrieval_prompt
|
||||
from .retriever import retriever_description, search
|
||||
|
||||
prompt = ChatPromptTemplate.from_messages([
|
||||
("user", retrieval_prompt),
|
||||
("ai", "{agent_scratchpad}"),
|
||||
])
|
||||
prompt = ChatPromptTemplate.from_messages(
|
||||
[
|
||||
("user", retrieval_prompt),
|
||||
("ai", "{agent_scratchpad}"),
|
||||
]
|
||||
)
|
||||
prompt = prompt.partial(retriever_description=retriever_description)
|
||||
|
||||
model = ChatAnthropic(model="claude-2", temperature=0, max_tokens_to_sample=1000)
|
||||
|
||||
chain = RunnablePassthrough.assign(
|
||||
agent_scratchpad=lambda x: format_agent_scratchpad(x['intermediate_steps'])
|
||||
) | prompt | model.bind( stop_sequences=['</search_query>']) | StrOutputParser()
|
||||
chain = (
|
||||
RunnablePassthrough.assign(
|
||||
agent_scratchpad=lambda x: format_agent_scratchpad(x["intermediate_steps"])
|
||||
)
|
||||
| prompt
|
||||
| model.bind(stop_sequences=["</search_query>"])
|
||||
| StrOutputParser()
|
||||
)
|
||||
|
||||
agent_chain = RunnableMap({
|
||||
"partial_completion": chain,
|
||||
"intermediate_steps": lambda x: x['intermediate_steps']
|
||||
}) | parse_output
|
||||
agent_chain = (
|
||||
RunnableMap(
|
||||
{
|
||||
"partial_completion": chain,
|
||||
"intermediate_steps": lambda x: x["intermediate_steps"],
|
||||
}
|
||||
)
|
||||
| parse_output
|
||||
)
|
||||
|
||||
executor = AgentExecutor(agent=agent_chain, tools = [search], verbose=True)
|
||||
executor = AgentExecutor(agent=agent_chain, tools=[search], verbose=True)
|
||||
|
Reference in New Issue
Block a user