Skip to content

Commit

Permalink
support sensenova api validate.
Browse files Browse the repository at this point in the history
  • Loading branch information
JingofXin committed Dec 24, 2024
1 parent dd14d87 commit 0ba97e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lazyllm/engine/lightengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,20 @@ def online_model_get_training_cost(self, token, job_id, source):
"""
return self.online_train_client.get_training_cost(token, job_id, source)

def online_model_validate_api_key(self, token, source):
def online_model_validate_api_key(self, token, source, secret_key=None):
"""
Validates the API key for a given supplier.
Args:
- token (str): API-Key provided by the user, used for authentication.
- source (str): Specifies the supplier. Supported suppliers are 'openai', 'glm' and 'qwen'.
- secret_key (str): The secret key provided by the user for authentication,
required only when the source is 'sensenova'. Default is None.
Returns:
- bool: True if the API key is valid, False otherwise.
"""
return self.online_train_client.validate_api_key(token, source)
return self.online_train_client.validate_api_key(token, source, secret_key)

def build_node(self, node):
if not isinstance(node, Node):
Expand Down
11 changes: 11 additions & 0 deletions lazyllm/module/onlineChatModule/sensenovaModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ def _create_finetuning_job(self, train_model, train_file_id, **kw) -> Tuple[str,
status = r.json()["job"]["status"]
return (fine_tuning_job_id, status)

def _validate_api_key(self):
fine_tune_url = urljoin(self._base_url, "models")
headers = {
"Authorization": f"Bearer {self._api_key}",
"Content-Type": "application/json"
}
response = requests.get(fine_tune_url, headers=headers)
if response.status_code == 200:
return True
return False

def _query_finetuning_job(self, fine_tuning_job_id) -> Tuple[str, str]:
fine_tune_url = urljoin(self._base_url, f"fine-tunes/{fine_tuning_job_id}")
headers = {
Expand Down
6 changes: 4 additions & 2 deletions lazyllm/tools/train_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,18 @@ def get_training_cost(self, token, job_id, source):
lazyllm.LOG.error(error)
return error

def validate_api_key(self, token, source):
def validate_api_key(self, token, source, secret_key=None):
"""
Validates the API key for a given supplier.
Args:
- token (str): API-Key provided by the user, used for authentication.
- source (str): Specifies the supplier. Supported suppliers are 'openai', 'glm' and 'qwen'.
- secret_key (str): The secret key provided by the user for authentication,
required only when the source is 'sensenova'. Default is None.
Returns:
- bool: True if the API key is valid, False otherwise.
"""
m = lazyllm.OnlineChatModule(source=source, api_key=token)
m = lazyllm.OnlineChatModule(source=source, api_key=token, secret_key=secret_key)
return m._validate_api_key()

0 comments on commit 0ba97e1

Please sign in to comment.