Skip to content

Commit

Permalink
Fix secret update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Aug 27, 2024
1 parent fa894f5 commit 1bee9a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion fastagency/studio/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ async def validate_secret_model(
type: str = "secret"

found_model = await DefaultDB.backend().find_model(model_uuid=model_uuid)
if "api_key" in found_model["json_str"]:

if "api_key" not in model:
model["api_key"] = found_model["json_str"]["api_key"]

try:
validated_model = Registry.get_default().validate(type, name, model)
return validated_model.model_dump()
Expand Down
21 changes: 18 additions & 3 deletions tests/studio/app/test_openai_extensively.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,29 @@ async def test_validate_secret_model(
background_tasks=BackgroundTasks(),
)

# Remove api_key and send name alone to validate route
model_dict.pop("api_key")
# Pass only name in the request, this should only update the name and retain the existing api_key
model_dict_with_updated_name = {"name": "Hello World! Updated"}

response = client.post(
f"/user/{user_uuid}/models/secret/OpenAIAPIKey/{api_key_model_uuid}/validate",
json=model_dict,
json=model_dict_with_updated_name,
)
assert response.status_code == 200

expected = {"name": "Hello World! Updated", "api_key": model_dict["api_key"]}
assert response.json() == expected

# Pass both name and api_key in the request, this should update both name and api_key
model_dict_with_updated_name_and_api_key = {
"name": "Hello World! Updated Again",
"api_key": "sk-proj-SomeLengthStringWhichCanHave-and_inItAndTheLengthCanBeChangedAtAnyTime", # pragma: allowlist secret
}
response = client.post(
f"/user/{user_uuid}/models/secret/OpenAIAPIKey/{api_key_model_uuid}/validate",
json=model_dict_with_updated_name_and_api_key,
)
assert response.status_code == 200
assert response.json() == model_dict_with_updated_name_and_api_key


# we will do this for OpenAI only, the rest should be the same
Expand Down

0 comments on commit 1bee9a4

Please sign in to comment.