oflakne26 commited on
Commit
8a7a2b3
·
verified ·
1 Parent(s): 04dbc8e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -3
main.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  from ctransformers import AutoModelForCausalLM
5
 
@@ -27,7 +27,7 @@ def setup_endpoints(app):
27
 
28
  models = {}
29
 
30
- # Load each model and create an endpoint
31
  for model_name in model_dirs:
32
  model_path = os.path.join(model_base_path, model_name)
33
  try:
@@ -37,8 +37,16 @@ def setup_endpoints(app):
37
  print(f"Failed to load model {model_name}: {e}")
38
  continue
39
 
 
 
 
 
 
 
 
 
40
  @app.post(f"/{model_name}")
41
- async def generate_response(item: Validation, model=model):
42
  try:
43
  response = model(item.inputs,
44
  temperature=item.temperature,
 
1
  import os
2
+ from fastapi import FastAPI, HTTPException, Depends
3
  from pydantic import BaseModel
4
  from ctransformers import AutoModelForCausalLM
5
 
 
27
 
28
  models = {}
29
 
30
+ # Load each model
31
  for model_name in model_dirs:
32
  model_path = os.path.join(model_base_path, model_name)
33
  try:
 
37
  print(f"Failed to load model {model_name}: {e}")
38
  continue
39
 
40
+ # Function to get model dependency
41
+ def get_model(model_name: str):
42
+ if model_name not in models:
43
+ raise HTTPException(status_code=404, detail="Model not found")
44
+ return models[model_name]
45
+
46
+ # Create an endpoint for each model
47
+ for model_name in model_dirs:
48
  @app.post(f"/{model_name}")
49
+ async def generate_response(item: Validation, model=Depends(lambda: get_model(model_name))):
50
  try:
51
  response = model(item.inputs,
52
  temperature=item.temperature,