-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update finetuning api with openai format. (#535)
* update finetuning api with openai format. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update doc and use 8001 port. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: test <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: root <[email protected]>
- Loading branch information
1 parent
7d5da06
commit 1ff81da
Showing
6 changed files
with
307 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import uvicorn | ||
from fastapi import BackgroundTasks, FastAPI | ||
from fastapi import BackgroundTasks | ||
|
||
from comps import opea_microservices, register_microservice | ||
from comps.cores.proto.api_protocol import FineTuningJobIDRequest, FineTuningJobsRequest | ||
from comps.finetuning.handlers import ( | ||
handle_cancel_finetuning_job, | ||
handle_create_finetuning_jobs, | ||
handle_list_finetuning_jobs, | ||
handle_retrieve_finetuning_job, | ||
) | ||
from comps.finetuning.models import FineTuningJob, FineTuningJobList, FineTuningJobsRequest | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.post("/v1/fine_tuning/jobs", response_model=FineTuningJob) | ||
@register_microservice(name="opea_service@finetuning", endpoint="/v1/fine_tuning/jobs", host="0.0.0.0", port=8001) | ||
def create_finetuning_jobs(request: FineTuningJobsRequest, background_tasks: BackgroundTasks): | ||
return handle_create_finetuning_jobs(request, background_tasks) | ||
|
||
|
||
@app.get("/v1/fine_tuning/jobs", response_model=FineTuningJobList) | ||
@register_microservice( | ||
name="opea_service@finetuning", endpoint="/v1/fine_tuning/jobs", host="0.0.0.0", port=8001, methods=["GET"] | ||
) | ||
def list_finetuning_jobs(): | ||
return handle_list_finetuning_jobs() | ||
|
||
|
||
@app.get("/v1/fine_tuning/jobs/{fine_tuning_job_id}", response_model=FineTuningJob) | ||
def retrieve_finetuning_job(fine_tuning_job_id): | ||
job = handle_retrieve_finetuning_job(fine_tuning_job_id) | ||
@register_microservice( | ||
name="opea_service@finetuning", endpoint="/v1/fine_tuning/jobs/retrieve", host="0.0.0.0", port=8001 | ||
) | ||
def retrieve_finetuning_job(request: FineTuningJobIDRequest): | ||
job = handle_retrieve_finetuning_job(request) | ||
return job | ||
|
||
|
||
@app.post("/v1/fine_tuning/jobs/{fine_tuning_job_id}/cancel", response_model=FineTuningJob) | ||
def cancel_finetuning_job(fine_tuning_job_id): | ||
job = handle_cancel_finetuning_job(fine_tuning_job_id) | ||
@register_microservice( | ||
name="opea_service@finetuning", endpoint="/v1/fine_tuning/jobs/cancel", host="0.0.0.0", port=8001 | ||
) | ||
def cancel_finetuning_job(request: FineTuningJobIDRequest): | ||
job = handle_cancel_finetuning_job(request) | ||
return job | ||
|
||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="0.0.0.0", port=8000) | ||
opea_microservices["opea_service@finetuning"].start() |
Oops, something went wrong.