File size: 954 Bytes
2ce47b6
 
 
 
a36c95d
 
 
 
 
 
2ce47b6
a36c95d
 
 
 
 
 
 
 
2ce47b6
a36c95d
 
 
 
2ce47b6
 
 
 
 
 
 
 
 
 
a36c95d
 
 
 
 
 
 
 
2ce47b6
 
 
 
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
41
42
43
44
45
46
47
from fastapi import FastAPI
from transformers import pipeline


from llama_cpp import Llama

llm = Llama.from_pretrained(
	repo_id="hugging-quants/Llama-3.2-1B-Instruct-Q8_0-GGUF",
	filename="llama-3.2-1b-instruct-q8_0.gguf",
)

check  = llm.create_chat_completion(
	messages = [
		{
			"role": "user",
			"content": "What is the capital of France?"
		}
	]
)

print(check['choices'][0]['message']['content'])

## create a new FASTAPI app instance
app=FastAPI()
@app.get("/")
def home():
    return {"message":"Hello World"}

# Define a function to handle the GET request at `/generate`


@app.get("/generate")
def generate(text:str):
    ## use the pipeline to generate text from given input text
    output= llm.create_chat_completion(
	messages = [
		{
			"role": "user",
			"content": f"{text}"
		}
	]
)

    ## return the generate text in Json reposnfe
    return {"output":output[0]['generated_text']}