Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up method OpenAIToolsAgentComponent.create_agent_runnable by 11% in src/backend/base/langflow/components/langchain_utilities/openai_tools.py #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ def get_chat_history_data(self) -> list[Data] | None:
return self.chat_history

def create_agent_runnable(self):
if "input" not in self.user_prompt:
msg = "Prompt must contain 'input' key."
raise ValueError(msg)
try:
user_prompt = self.user_prompt
except KeyError:
raise ValueError("Prompt must contain 'input' key.")

messages = [
("system", self.system_prompt),
("placeholder", "{chat_history}"),
HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=self.user_prompt)),
HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=user_prompt)),
("placeholder", "{agent_scratchpad}"),
]

prompt = ChatPromptTemplate.from_messages(messages)
return create_openai_tools_agent(self.llm, self.tools, prompt)