-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.py
More file actions
36 lines (27 loc) · 805 Bytes
/
serve.py
File metadata and controls
36 lines (27 loc) · 805 Bytes
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
from dotenv import load_dotenv
from fastapi import FastAPI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langserve import add_routes
load_dotenv()
model = ChatOpenAI(model="gpt-4", temperature=0.1)
system_prompt = "Translate the following into {language}"
prompt_template = ChatPromptTemplate.from_messages(
[("system", system_prompt), ("user", "{text}")]
)
parser = StrOutputParser()
chain = prompt_template | model | parser
app = FastAPI(
title="Translator App",
version="1.0.0",
description="Translation Chat Bot",
)
add_routes(
app,
chain,
path="/chain",
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="localhost", port=8000)