Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separating out setting model type into a separate method in the job service #385

Merged
merged 7 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ repos:
- id: end-of-file-fixer
- id: requirements-txt-fixer
exclude: requirements_lock.txt

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
2 changes: 1 addition & 1 deletion lumigator/python/mzai/backend/backend/api/routes/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_job_metadata(job_id: UUID) -> JobSubmissionResponse:
)
elif resp.status_code != HTTPStatus.OK:
loguru.logger.error(
f"Unexpected status code getting job metadata text: "
"Unexpected status code getting job metadata text: "
"{resp.status_code}, error: {resp.text or ''}"
veekaybee marked this conversation as resolved.
Show resolved Hide resolved
)
raise HTTPException(
Expand Down
14 changes: 10 additions & 4 deletions lumigator/python/mzai/backend/backend/services/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,23 @@ def _get_config_template(self, job_type: str, model_name: str) -> str:

return config_template

def _get_job_params(self, job_type: str, record, request: BaseModel) -> dict:
# get dataset S3 path from UUID
dataset_s3_path = self.data_service.get_dataset_s3_path(request.dataset)

def _set_model_type(self, request: BaseModel) -> str:
"""Sets model URL based on protocol address"""
if request.model.startswith("oai://"):
model_url = settings.OAI_API_URL
elif request.model.startswith("mistral://"):
model_url = settings.MISTRAL_API_URL
else:
model_url = request.model_url

return model_url

def _get_job_params(self, job_type: str, record, request: BaseModel) -> dict:
# get dataset S3 path from UUID
dataset_s3_path = self.data_service.get_dataset_s3_path(request.dataset)

model_url = self._set_model_type(request)

# provide a reasonable system prompt for services where none was specified
if request.system_prompt is None and not request.model.startswith("hf://"):
request.system_prompt = settings.DEFAULT_SUMMARIZER_PROMPT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_set_null_inference_job_params(job_record,job_service ):
request = JobInferenceCreate(name="test_run_hugging_face",
description="Test run for Huggingface model",
model="Test run for Huggingface model",
model="hf://facebook/bart-large-cnn",
dataset="cced289c-f869-4af1-9195-1d58e32d1cc1")
params = job_service._get_job_params("INFERENCE", job_record,request)
assert params["max_samples"] == -1
Expand All @@ -18,7 +18,38 @@ def test_set_explicit_inference_job_params(job_record,job_service ):
request = JobInferenceCreate(name="test_run_hugging_face",
description="Test run for Huggingface model",
max_samples=10,
model="Test run for Huggingface model",
model="hf://facebook/bart-large-cnn",
dataset="cced289c-f869-4af1-9195-1d58e32d1cc1")
params = job_service._get_job_params("INFERENCE", job_record,request)
assert params["max_samples"] == 10


def test_set_model_hf(job_record,job_service):
request = JobInferenceCreate(name="test_run_hugging_face",
description="Test run for Huggingface model",
max_samples=10,
model="hf://facebook/bart-large-cnn",
model_url="hf://facebook/bart-large-cnn",
dataset="cced289c-f869-4af1-9195-1d58e32d1cc1")
model_url = job_service._set_model_type(request)
assert model_url == "hf://facebook/bart-large-cnn"

def test_set_model_openai(job_record,job_service):
request = JobInferenceCreate(name="test_run_openai",
description="Test run for OpenAI server",
max_samples=10,
model="oai://gpt-4-turbo",
dataset="cced289c-f869-4af1-9195-1d58e32d1cc1")

model_url = job_service._set_model_type(request)
assert model_url == "https://api.openai.com/v1"
veekaybee marked this conversation as resolved.
Show resolved Hide resolved

def test_set_model_mistral(job_record,job_service):
request = JobInferenceCreate(name="test_run_mistral",
description="Test run for Mistral server",
max_samples=10,
model="mistral://open-mistral-7b",
veekaybee marked this conversation as resolved.
Show resolved Hide resolved
dataset="cced289c-f869-4af1-9195-1d58e32d1cc1")

model_url = job_service._set_model_type(request)
assert model_url == "https://api.mistral.ai/v1"
4 changes: 2 additions & 2 deletions lumigator/python/mzai/sdk/tests/data/job-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"model": "some_model",
"dataset": "6f6487ac-7170-4a11-af7a-0f6db1ec9a74",
"max_samples": 5,
"model_url": "s3://some_url",
"model_url": "hf://facebook/bart-large-cnn",
veekaybee marked this conversation as resolved.
Show resolved Hide resolved
"system_prompt": "some prompt",
"config_infer_template": "some_infer_template",
"config_eval_template": "some_eval_template"
}
}