fix: credentials validate compatible problem (#2170)

This commit is contained in:
takatost 2024-01-24 17:19:25 +08:00 committed by GitHub
parent 78524a56ed
commit 784da52ea6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -153,8 +153,16 @@ class ProviderConfiguration(BaseModel):
if provider_record:
try:
original_credentials = json.loads(
provider_record.encrypted_config) if provider_record.encrypted_config else {}
# fix origin data
if provider_record.encrypted_config:
if not provider_record.encrypted_config.startswith("{"):
original_credentials = {
"openai_api_key": provider_record.encrypted_config
}
else:
original_credentials = json.loads(provider_record.encrypted_config)
else:
original_credentials = {}
except JSONDecodeError:
original_credentials = {}