mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-04 20:46:45 +00:00
templates: robocorp action server template (#15776)
--------- Co-authored-by: Rihards Gravis <rihards@gravis.lv> Co-authored-by: Mikko Korpela <mikko@robocorp.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from robocorp_action_server.agent import agent_executor
|
||||
|
||||
__all__ = ["agent_executor"]
|
@@ -0,0 +1,36 @@
|
||||
from langchain.agents import AgentExecutor, OpenAIFunctionsAgent
|
||||
from langchain_core.messages import SystemMessage
|
||||
from langchain_core.pydantic_v1 import BaseModel
|
||||
from langchain_openai import ChatOpenAI
|
||||
from langchain_robocorp import ActionServerToolkit
|
||||
|
||||
# Initialize LLM chat model
|
||||
llm = ChatOpenAI(model="gpt-4", temperature=0)
|
||||
|
||||
# Initialize Action Server Toolkit
|
||||
toolkit = ActionServerToolkit(url="http://localhost:8080")
|
||||
tools = toolkit.get_tools()
|
||||
|
||||
# Initialize Agent
|
||||
system_message = SystemMessage(content="You are a helpful assistant")
|
||||
prompt = OpenAIFunctionsAgent.create_prompt(system_message)
|
||||
agent = OpenAIFunctionsAgent(
|
||||
llm=llm,
|
||||
prompt=prompt,
|
||||
tools=tools,
|
||||
)
|
||||
|
||||
# Initialize Agent executor
|
||||
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
||||
|
||||
|
||||
# Typings for Langserve playground
|
||||
class Input(BaseModel):
|
||||
input: str
|
||||
|
||||
|
||||
class Output(BaseModel):
|
||||
output: str
|
||||
|
||||
|
||||
agent_executor = agent_executor.with_types(input_type=Input, output_type=Output) # type: ignore[arg-type, assignment]
|
Reference in New Issue
Block a user