Guhanselvam commited on
Commit
386fc65
·
verified ·
1 Parent(s): fabd018

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +21 -0
api.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from llama_cpp import Llama # Change this import as per your LLaMA library
4
+
5
+ app = FastAPI()
6
+
7
+ # Initialize LLaMA model
8
+ model = Llama(model_path="path/to/llama-3.2-model.bin") # Specify the correct path to your model
9
+
10
+ class LlamaRequest(BaseModel):
11
+ prompt: str
12
+
13
+ @app.post("/llama/")
14
+ async def get_llama_response(request: LlamaRequest):
15
+ try:
16
+ response = model.generate(request.prompt) # Call the LLaMA model
17
+ return {"response": response}
18
+ except Exception as e:
19
+ raise HTTPException(status_code=500, detail=str(e))
20
+
21
+ # To run the API, use 'uvicorn api:app --reload' in the terminal.