-
Notifications
You must be signed in to change notification settings - Fork 324
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
feat: valid Pydantic #373
feat: valid Pydantic #373
Changes from 7 commits
93e020c
32be43e
b4cd95b
48c49bf
db8eb59
7f9c3d1
f940d7b
16e570c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ def get_embedder_settings(): | |
def upsert_embedder_setting( | ||
request: Request, | ||
languageEmbedderName: str, | ||
payload: Dict = Body(example={"openai_api_key": "your-key-here"}), | ||
payload: Dict = Body(..., example={"openai_api_key": "your-key-here"}) | ||
): | ||
"""Upsert the Embedder setting""" | ||
|
||
|
@@ -54,7 +54,17 @@ def upsert_embedder_setting( | |
status_code=400, | ||
detail=f"{languageEmbedderName} not supported. Must be one of {allowed_configurations}", | ||
) | ||
|
||
|
||
required = EMBEDDER_SCHEMAS[languageEmbedderName]['required'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there always a |
||
if crud.validate_presences(required, payload): | ||
raise HTTPException( | ||
status_code=405, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's go for 400 (bad request) |
||
detail={ | ||
"error": f"The following fields are required: {', '.join(required)}" | ||
} | ||
) | ||
|
||
|
||
# create the setting and upsert it | ||
final_setting = crud.upsert_setting_by_name( | ||
models.Setting(name=languageEmbedderName, category=EMBEDDER_CATEGORY, value=payload) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,16 @@ def test_upsert_llm_settings_success(client): | |
# assert | ||
assert response.status_code == 200 | ||
assert json["selected_configuration"] == 'LLMCustomConfig' | ||
assert json["settings"][0]["value"]["url"] == invented_url | ||
assert json["settings"][0]["value"]["url"] == invented_url | ||
|
||
def test_upsert_llm_settings_error(client): | ||
|
||
# set a different LLM | ||
invented_url = "https://example.com" | ||
payload = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for writing the test |
||
response = client.put("/settings/llm/LLMCustomConfig", json=payload) | ||
json = response.json() | ||
|
||
# check immediate response | ||
assert response.status_code == 405 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's go for 400 (bad request) |
||
assert json["detail"]["error"] == "The following fields are required: url" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with the utility of a
validate_presences
method, but it is not related to DB crud.I would move it here in the factory, where schemas are defined, or in utilis in case we'll use this validation method also for plugin settings. Also infrastructure could be a place for this method, if we go for a validation set of methods
What do you think?