Sadiksmart0 commited on
Commit
f3a346f
·
verified ·
1 Parent(s): 340c2c6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from langchain_community.llms import Ollama
4
+ from langchain.callbacks.manager import CallbackManager
5
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
6
+
7
+ app = FastAPI()
8
+ MODEL_NAME = 'tinyllama'
9
+
10
+ def get_llm():
11
+ callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
12
+ return Ollama(model=MODEL_NAME, callback_manager=callback_manager)
13
+
14
+ class Question(BaseModel):
15
+ text: str
16
+
17
+ @app.get("/")
18
+ def read_root():
19
+ return {"message": f"Welcome to {MODEL_NAME} FastAPI"}
20
+
21
+ @app.post("/ask")
22
+ def ask_question(question: Question):
23
+ llm = get_llm()
24
+ response = llm(question.text)
25
+ return {"response": response}