Commit 62d3eeb4 authored by John Wang's avatar John Wang

Merge branch 'feat/claude-api-support' into deploy/dev

parents c66db061 05493c35
...@@ -35,7 +35,7 @@ class ProviderListApi(Resource): ...@@ -35,7 +35,7 @@ class ProviderListApi(Resource):
plaintext, the rest is replaced by * and the last two bits are displayed in plaintext plaintext, the rest is replaced by * and the last two bits are displayed in plaintext
""" """
ProviderService.init_supported_provider(current_user.current_tenant, "cloud") ProviderService.init_supported_provider(current_user.current_tenant)
providers = Provider.query.filter_by(tenant_id=tenant_id).all() providers = Provider.query.filter_by(tenant_id=tenant_id).all()
provider_list = [ provider_list = [
......
...@@ -10,44 +10,34 @@ from models.provider import * ...@@ -10,44 +10,34 @@ from models.provider import *
class ProviderService: class ProviderService:
@staticmethod @staticmethod
def init_supported_provider(tenant, edition): def init_supported_provider(tenant):
"""Initialize the model provider, check whether the supported provider has a record""" """Initialize the model provider, check whether the supported provider has a record"""
providers = Provider.query.filter_by(tenant_id=tenant.id).all() need_init_provider_names = [ProviderName.OPENAI.value, ProviderName.AZURE_OPENAI.value, ProviderName.ANTHROPIC.value]
openai_provider_exists = False providers = db.session.query(Provider).filter(
azure_openai_provider_exists = False Provider.tenant_id == tenant.id,
Provider.provider_type == ProviderType.CUSTOM.value,
# TODO: The cloud version needs to construct the data of the SYSTEM type Provider.provider_name.in_(need_init_provider_names)
).all()
exists_provider_names = []
for provider in providers: for provider in providers:
if provider.provider_name == ProviderName.OPENAI.value and provider.provider_type == ProviderType.CUSTOM.value: exists_provider_names.append(provider.provider_name)
openai_provider_exists = True
if provider.provider_name == ProviderName.AZURE_OPENAI.value and provider.provider_type == ProviderType.CUSTOM.value:
azure_openai_provider_exists = True
# Initialize the model provider, check whether the supported provider has a record not_exists_provider_names = list(set(need_init_provider_names) - set(exists_provider_names))
# Create default providers if they don't exist if not_exists_provider_names:
if not openai_provider_exists: # Initialize the model provider, check whether the supported provider has a record
openai_provider = Provider( for provider_name in not_exists_provider_names:
tenant_id=tenant.id, provider = Provider(
provider_name=ProviderName.OPENAI.value, tenant_id=tenant.id,
provider_type=ProviderType.CUSTOM.value, provider_name=provider_name,
is_valid=False provider_type=ProviderType.CUSTOM.value,
) is_valid=False
db.session.add(openai_provider) )
db.session.add(provider)
if not azure_openai_provider_exists:
azure_openai_provider = Provider(
tenant_id=tenant.id,
provider_name=ProviderName.AZURE_OPENAI.value,
provider_type=ProviderType.CUSTOM.value,
is_valid=False
)
db.session.add(azure_openai_provider)
if not openai_provider_exists or not azure_openai_provider_exists:
db.session.commit() db.session.commit()
@staticmethod @staticmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment