File size: 1,065 Bytes
39cc8a5
823c760
48434c1
a5b1f33
1aba7f3
97917f4
48434c1
6d3fbf5
70f94ec
6d3fbf5
383a904
6d3fbf5
 
e9ad359
4545ff6
39cc8a5
 
 
 
 
 
a5b1f33
c6cb00e
65f1222
1aba7f3
 
 
97917f4
 
e9ad359
 
 
97917f4
 
 
8a5a310
 
823c760
73fcf85
 
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
30
31
32
33
34
35
36
37
38
39
40
from fastapi import FastAPI
import uvicorn
from transformers import AutoModel, AutoTokenizer

model_name = "Tap-M/Luna-AI-Llama2-Uncensored"

model = AutoModel.from_pretrained(
    model_name,  # Example model
    offload_folder="./offload",  # Temporary directory
    trust_remote_code=True        # Required for some models
)

# load tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token

app = FastAPI()

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

@app.get("/message")
async def message(input: str):
    prompt = "USER:" + input + "\nASSISTANT:"
    
    inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True)
    
    output = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"], 
        max_new_tokens=100,
    )
    
    response = tokenizer.decode(output[0], skip_special_tokens=True)
    
    return response

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