Skip to content

Commit 33cbb17

Browse files
authored
Add files via upload
1 parent c9da81a commit 33cbb17

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

llm.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from fastapi import FastAPI
2+
from langchain.prompts import ChatPromptTemplate
3+
from langchain.chains import LLMChain
4+
from langserve import add_routes
5+
import uvicorn
6+
from langchain_community.llms import Ollama
7+
8+
# Setup FastAPI app
9+
app = FastAPI(
10+
title="Langchain Server",
11+
version="1.0", # version should be a string
12+
description="A simple API server"
13+
)
14+
15+
# Initialize Ollama model
16+
llm = Ollama(model="llama3.1")
17+
18+
# Create prompts
19+
prompt1 = ChatPromptTemplate.from_template("write me an essay about {topic} with 100 words")
20+
prompt2 = ChatPromptTemplate.from_template("write a poem about {topic} in 100 words")
21+
22+
# Create LLMChains
23+
chain1 = LLMChain(llm=llm, prompt=prompt1)
24+
chain2 = LLMChain(llm=llm, prompt=prompt2)
25+
26+
# Add routes
27+
add_routes(
28+
app,
29+
chain1,
30+
path="/essay"
31+
)
32+
add_routes(
33+
app,
34+
chain2,
35+
path="/poem"
36+
)
37+
38+
# Run the app
39+
if __name__ == "__main__":
40+
uvicorn.run(app, host="127.0.0.1", port=8090)

0 commit comments

Comments
 (0)