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

Unable to update an existing secret name #85

Merged
merged 7 commits into from
Aug 27, 2024
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
Loading