File size: 728 Bytes
89b0286
7efc171
 
 
 
83982dc
7efc171
 
 
 
278e439
7efc171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89b0286
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import uvicorn
from transformers import AutoTokenizer, LlamaForCausalLM
from fastapi import FastAPI
from pydantic import BaseModel

model_path = 'EleutherAI/llemma_7b'

model = LlamaForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)


class validation(BaseModel):
    prompt: str


app = FastAPI()


@app.post("/prompt")
async def stream(item: validation):
    inputs = tokenizer(item.prompt, return_tensors="pt")

    generate_ids = model.generate(inputs.input_ids, max_length=30)

    var = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
    return var

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)