Skip to content

Commit

Permalink
feat: support spark v2 validate (langgenius#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
takatost authored Sep 1, 2023
1 parent 73c86ee commit a7cdb74
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions api/core/model_providers/providers/spark_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ def is_provider_credentials_valid_or_raise(cls, credentials: dict):
if 'api_secret' not in credentials:
raise CredentialsValidateFailedError('Spark api_secret must be provided.')

try:
credential_kwargs = {
'app_id': credentials['app_id'],
'api_key': credentials['api_key'],
'api_secret': credentials['api_secret'],
}
credential_kwargs = {
'app_id': credentials['app_id'],
'api_key': credentials['api_key'],
'api_secret': credentials['api_secret'],
}

try:
chat_llm = ChatSpark(
model_name='spark-v2',
max_tokens=10,
temperature=0.01,
**credential_kwargs
Expand All @@ -104,7 +105,27 @@ def is_provider_credentials_valid_or_raise(cls, credentials: dict):

chat_llm(messages)
except SparkError as ex:
raise CredentialsValidateFailedError(str(ex))
# try spark v1.5 if v2.1 failed
try:
chat_llm = ChatSpark(
model_name='spark',
max_tokens=10,
temperature=0.01,
**credential_kwargs
)

messages = [
HumanMessage(
content="ping"
)
]

chat_llm(messages)
except SparkError as ex:
raise CredentialsValidateFailedError(str(ex))
except Exception as ex:
logging.exception('Spark config validation failed')
raise ex
except Exception as ex:
logging.exception('Spark config validation failed')
raise ex
Expand Down

0 comments on commit a7cdb74

Please sign in to comment.