Skip to content

Commit

Permalink
刷新管控 API 参数和接口类型
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiichi-Origami committed Oct 28, 2024
1 parent b9424ba commit 4933313
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 10 deletions.
19 changes: 15 additions & 4 deletions python/qianfan/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ class Consts:
"/wenxinworkshop/modelrepo/eval/result/export/info"
)
ModelEvaluableModelListAPI: str = "/wenxinworkshop/modelrepo/eval/model/list"

ModelEvalV2API: str = "/v2/eval"
ModelEvalV2Create: str = "CreateEvalTask"
ModelEvalV2DescribeTasks: str = "DescribeEvalTasks"
ModelEvalV2DescribeTask: str = "DescribeEvalTask"
ModelEvalV2DescribeTaskReport: str = "DescribeEvalTaskReport"
ModelEvalV2DeleteTask: str = "DeleteEvalTask"

ServiceCreateAPI: str = "/wenxinworkshop/service/apply"
ServiceDetailAPI: str = "/wenxinworkshop/service/detail"
ServiceListAPI: str = "/wenxinworkshop/service/list"
Expand Down Expand Up @@ -247,13 +255,16 @@ class Consts:
TpmCreditPurchaseQueryParam: str = "PurchaseTPMResource"
TpmCreditInfoQueryParam: str = "DescribeTPMResource"
TpmCreditStopQueryParam: str = "ReleaseTPMResource"
TpmCreditResizeTPMResourceParam: str = "ResizeTPMResource"
TpmCreditAutoReleaseTPMResourceParam: str = "AutoReleaseTPMResource"

PrivateResourceAPI: str = "/v2/charge"
PrivateResourcePurchaseParam: str = "PurchaseServiceResource"
PrivateResourceGetResourceListParam: str = "DescribeServiceResources"
PrivateResourceGetResourceParam: str = "DescribeServiceResource"
PrivateResourceReleaseServiceResourceParam: str = "ReleaseServiceResource"
PrivateResourceCreateAutoRenewRulesParam: str = "CreateAutoRenewRules"
PrivateResourceGetResourceListParam: str = "DescribeComputeUnits"
PrivateResourceGetResourceParam: str = "DescribeComputeUnit"
PrivateResourceReleaseServiceResourceParam: str = "ReleaseComputeUnit"
PrivateResourceCreateAutoRenewRulesParam: str = "AutoReleaseComputeUnit"
PrivateResourceResizeComputeUnitParam: str = "ResizeComputeUnit"

ChatV2API: str = "/v2/chat/completions"
IAMBearerTokenAPI: str = "/v1/BCE-BEARER/token"
Expand Down
9 changes: 8 additions & 1 deletion python/qianfan/dataset/stress_test/qianfan_llm_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import re
import time
import traceback
from typing import Any, Dict, Iterator, Literal, Optional

from locust import constant, events, task
Expand Down Expand Up @@ -269,7 +270,13 @@ def _request_internal(

if GlobalData.data["log"] == 1:
if self.exc:
self._write_result({"error": str(self.exc)})
self._write_result(
{
"exception_type": type(self.exc),
"error": str(self.exc),
"stack": "\n".join(traceback.format_tb(self.exc.__traceback__)),
}
)
else:
if (
res.get("request", {}).get("headers", {}).get("Authorization", None)
Expand Down
114 changes: 111 additions & 3 deletions python/qianfan/resources/console/charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Charge(object):
@classmethod
@console_api_request
def charge_tpm_credit(
cls, model: str, purchase_count: int, **kwargs: Any
cls, model: str, purchase_count: int, billing: Dict[str, Any], **kwargs: Any
) -> QfRequest:
"""
charge the rpm / tpm credit.
Expand All @@ -40,6 +40,8 @@ def charge_tpm_credit(
The model you want to charge to.
purchase_count (int):
how many credit you want to charge.
billing (Dict[str, Any]):
billing info
kwargs (Any):
Additional keyword arguments.
Expand All @@ -54,7 +56,7 @@ def charge_tpm_credit(
req.json_body = {
"model": model,
"purchaseCount": purchase_count,
"billing": {"paymentTiming": "Postpaid"},
"billing": billing,
**kwargs,
}
return req
Expand All @@ -66,6 +68,7 @@ def tpm_credit_info(
model: str,
payment_type: Optional[str] = None,
instance_id: Optional[str] = None,
status: Optional[str] = None,
**kwargs: Any
) -> QfRequest:
"""
Expand All @@ -79,6 +82,8 @@ def tpm_credit_info(
Only available type is "Postpaid" currently.
instance_id (Optional[str]):
which specific instance you want to get.
status (str):
which status of instance you want to get.
**kwargs (Any):
Additional keyword arguments.
Expand All @@ -101,6 +106,9 @@ def tpm_credit_info(
if instance_id:
req.json_body["instanceId"] = instance_id

if status:
req.json_body["status"] = status

return req

@classmethod
Expand Down Expand Up @@ -135,6 +143,74 @@ def stop_tpm_credit_charging(

return req

@classmethod
@console_api_request
def resize_tpm_resource(
cls, instance_id: str, count: Optional[int], **kwargs: Any
) -> QfRequest:
"""
resize the rpm / tpm charging
Parameters:
instance_id (str):
which specific instance you want to get.
count: (Optional[int])
how many tpm resources should be after resize.
**kwargs (Any):
Additional keyword arguments.
Note:
The `@console_api_request` decorator is applied to this method, enabling it to
send the generated QfRequest and return a QfResponse to the user.
API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/cm2cy5ion
"""

req = QfRequest(method="POST", url=Consts.TpmCreditAPI)
req.query = {"Action": Consts.TpmCreditResizeTPMResourceParam}
req.json_body = {
"instanceId": instance_id,
}

if count:
req.json_body["count"] = count

return req

@classmethod
@console_api_request
def auto_release_tpm_resource(
cls, instance_id: str, release_time: Optional[str], **kwargs: Any
) -> QfRequest:
"""
resize the rpm / tpm charging
Parameters:
instance_id (str):
which specific instance you want to get.
release_time: (Optional[str])
when resources are released automatically. None for cancel
**kwargs (Any):
Additional keyword arguments.
Note:
The `@console_api_request` decorator is applied to this method, enabling it to
send the generated QfRequest and return a QfResponse to the user.
API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/cm2cy5ion
"""

req = QfRequest(method="POST", url=Consts.TpmCreditAPI)
req.query = {"Action": Consts.TpmCreditAutoReleaseTPMResourceParam}
req.json_body = {
"instanceId": instance_id,
}

if release_time:
req.json_body["releaseTime"] = release_time

return req

@classmethod
@console_api_request
def purchase_service_resource(
Expand Down Expand Up @@ -172,7 +248,7 @@ def purchase_service_resource(

@classmethod
@console_api_request
def ger_service_resource_list(
def get_service_resource_list(
cls, service_id: str, payment_timing: Optional[str] = None, **kwargs: Any
) -> QfRequest:
"""
Expand Down Expand Up @@ -313,3 +389,35 @@ def create_auto_renew_rules(
)

return req

@classmethod
@console_api_request
def resize_service_resource_count(
cls, instance_id: str, count: int, **kwargs: Any
) -> QfRequest:
"""
release purchase private service resource from qianfan
Parameters:
instance_id (str):
The resource instance id.
count (int):
how many instance count you want to set
**kwargs (Any):
other arguments
Note:
The `@console_api_request` decorator is applied to this method, enabling it to
send the generated QfRequest and return a QfResponse to the user.
API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Tm2cxzmhi
"""

req = QfRequest(method="POST", url=Consts.PrivateResourceAPI)
req.query = {"Action": Consts.PrivateResourceResizeComputeUnitParam}
req.json_body = {
"count": count,
"instanceId": instance_id,
}

return req
2 changes: 2 additions & 0 deletions python/qianfan/resources/console/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class TrainMode(str, Enum):
"""PostPretrain """
DPO = "DPO"
"""DPO"""
KTO = "KTO"
"""KTO"""


class TrainParameterScale(str, Enum):
Expand Down
Loading

0 comments on commit 4933313

Please sign in to comment.