Spaces:
Runtime error
Runtime error
File size: 1,268 Bytes
5203638 aff3875 5203638 830ad8f 5203638 74cf1d0 5203638 74cf1d0 5203638 74cf1d0 5203638 74cf1d0 5203638 | 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 | from fastapi import FastAPI
from llama_index_llms_huggingface_api import HuggingFaceInferenceAPI
from pydantic import BaseModel
# Define your Pydantic model with protected namespaces disabled
class ModelConfig(BaseModel):
model_id: str
model_name: str
class Config:
protected_namespaces = () # Disable protected namespaces warning
# Define Settings class
class Settings:
llm = None # Initialize the llm attribute
# Initialize FastAPI app
app = FastAPI()
# Set up the HuggingFaceInferenceAPI with the new class
Settings.llm = HuggingFaceInferenceAPI(
api_key="your_api_key", # Replace with your actual API key
model_name="your_model_name" # Replace with your actual model name
)
# Sample endpoint to test the LLM
@app.post("/predict/")
async def predict(input_text: str):
try:
response = Settings.llm.generate(input_text) # Replace with the appropriate method for your API
return {"prediction": response}
except Exception as e:
return {"error": str(e)}
# Sample endpoint to retrieve model configuration
@app.get("/model-config/")
async def get_model_config():
return {"model_id": Settings.llm.model_id, "model_name": Settings.llm.model_name}
# Run the app using: uvicorn app:app --reload
|