-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
42 lines (33 loc) · 898 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from fastapi import FastAPI
from langchain_core.prompts import ChatPromptTemplate
from langserve import add_routes
from fastapi.middleware.cors import CORSMiddleware
from web_agent import init, graph
from dotenv import load_dotenv
load_dotenv()
from langchain.chat_models import ChatOpenAI
app = FastAPI(
title="LangChain Server",
version="1.0",
description="A simple api server using Langchain's Runnable interfaces",
)
# Set all CORS enabled origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["*"],
)
prompt = ChatPromptTemplate.from_template("tell me a joke about {topic}")
model = ChatOpenAI()
add_routes(
app,
graph,
path="/talk",
)
if __name__ == "__main__":
import uvicorn
init()
uvicorn.run(app, host="localhost", port=8000)