File size: 467 Bytes
891be39
 
 
 
 
 
 
 
 
 
 
 
57ed3b9
 
 
 
 
891be39
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

from fastapi import FastAPI
from ctransformers import AutoModelForCausalLM

##create a new FastAPI app instance
app = FastAPI()

def get_llm():
  model_path = "TheBloke/CodeLlama-7B-GGUF"
  llm = AutoModelForCausalLM.from_pretrained("TheBloke/CodeLlama-7B-GGUF", model_type="llama")
  return llm

@app.get("/")
def index():
    return {"Hello, World!"}


@app.get("/generate")
def generate(text:str) ->dict:
  llm = get_llm()
  res = llm(text)
  return {"text":res}