daniellefranca96 commited on
Commit
d20d20b
1 Parent(s): ef0c045

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +24 -0
main.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_cpp import Llama
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ import requests
5
+ from ctransformers import AutoModelForCausalLM
6
+
7
+ llm = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v0.6", model_file="ggml-model-q4_0.gguf")
8
+
9
+ #Pydantic object
10
+ class validation(BaseModel):
11
+ prompt: str
12
+ #Fast API
13
+ app = FastAPI()
14
+
15
+ @app.post("/llm_on_cpu")
16
+ async def stream(item: validation):
17
+ prefix="""<|user|>
18
+ """
19
+ suffix="""<|endoftext|><|assistant|>"""
20
+ user="""
21
+ {prompt}"""
22
+
23
+ prompt = f"{prefix}{user.replace('{prompt}', item.prompt)}{suffix}"
24
+ return llm(prompt)