File size: 409 Bytes
891be39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

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("/generate")
def generate(text:str) ->dict:
  llm = get_llm()
  res = llm(text)
  return {"text":res}