|
from fastapi import FastAPI |
|
import langchain |
|
app = FastAPI() |
|
|
|
@app.get("/") |
|
def read_root(): |
|
run_something() |
|
return {"Hello": "langchain {}".format(langchain.__version__)} |
|
|
|
from langchain.llms.fake import FakeListLLM |
|
|
|
from langchain.agents import load_tools |
|
from langchain.agents import initialize_agent |
|
from langchain.agents import AgentType |
|
|
|
def run_something(): |
|
tools = load_tools(["python_repl"]) |
|
responses = ["Action: Python REPL\nAction Input: print(2 + 2)", "Final Answer: 4"] |
|
llm = FakeListLLM(responses=responses) |
|
|
|
agent = initialize_agent( |
|
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True |
|
) |
|
agent.run("whats 2 + 2") |
|
|
|
|
|
|
|
|