Spaces:
Build error
Build error
File size: 1,127 Bytes
7eebe0e 2b25d5e 7eebe0e 2b25d5e 7eebe0e 2b25d5e 7eebe0e 2b25d5e 7eebe0e 2b25d5e 7eebe0e 984b1db 7eebe0e |
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 |
from fastapi import FastAPI
from pydantic import BaseModel
# Assuming Llama class has been correctly imported and set up
from llama_cpp import Llama
# Model loading with specified path and configuration
llm = Llama(
model_path="Meta-Llama-3-8B-Instruct.Q4_K_M.gguf", # Update the path as necessary
n_ctx=4096, # Maximum number of tokens for context (input + output)
n_threads=4, # Number of CPU cores used
)
# Pydantic object for validation
class Validation(BaseModel):
user_prompt: str # User's input prompt
system_prompt: str # System's guiding prompt
# FastAPI application initialization
app = FastAPI()
# Endpoint for generating responses
@app.post("/generate_response")
async def generate_response(item: Validation):
# Construct the complete prompt using the given system and user prompts
prompt = f"{item.user_prompt}"
# Call the Llama model to generate a response
output = llm(prompt, max_tokens=1024, stop=["Q:", "\n"], echo=True) # Update parameters as needed
# Extract and return the text from the response
return output['choices'][0]['text']
|