mirror of
https://github.com/open-webui/pipelines
synced 2025-06-04 03:47:04 +00:00
refac
This commit is contained in:
parent
f508caaea7
commit
24e02a9017
10
main.py
10
main.py
@ -64,6 +64,8 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
app = FastAPI(docs_url="/docs", redoc_url=None, lifespan=lifespan)
|
app = FastAPI(docs_url="/docs", redoc_url=None, lifespan=lifespan)
|
||||||
|
|
||||||
|
app.state.PIPELINES = PIPELINES
|
||||||
|
|
||||||
|
|
||||||
origins = ["*"]
|
origins = ["*"]
|
||||||
|
|
||||||
@ -112,14 +114,14 @@ async def get_models():
|
|||||||
async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm):
|
async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm):
|
||||||
user_message = get_last_user_message(form_data.messages)
|
user_message = get_last_user_message(form_data.messages)
|
||||||
|
|
||||||
if form_data.model not in PIPELINES:
|
if form_data.model not in app.state.PIPELINES:
|
||||||
return HTTPException(
|
return HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail=f"Model {form_data.model} not found",
|
detail=f"Model {form_data.model} not found",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def job():
|
def job():
|
||||||
get_response = PIPELINES[form_data.model]["module"].get_response
|
get_response = app.state.PIPELINES[form_data.model]["module"].get_response
|
||||||
|
|
||||||
if form_data.stream:
|
if form_data.stream:
|
||||||
|
|
||||||
@ -184,7 +186,7 @@ async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm):
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
return await job()
|
return await run_in_threadpool(job)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
Loading…
Reference in New Issue
Block a user