Skip to content

Commit

Permalink
feat: update resource & fix model (#622)
Browse files Browse the repository at this point in the history
* feat: update api and add custom apdater resource

* fix: openai resource

* feat: add eb4turbo and fix model deploy

* feat: add char-fiction
  • Loading branch information
danielhjz authored Jun 28, 2024
1 parent 71a2ebe commit ec0e4fe
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 18 deletions.
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "qianfan"
version = "0.3.17.1"
version = "0.3.18"
description = "文心千帆大模型平台 Python SDK"
authors = []
license = "Apache-2.0"
Expand Down
23 changes: 19 additions & 4 deletions python/qianfan/extensions/openai/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def openai_chat_request_to_qianfan(
if "tool_calls" in item:
item["function_call"] = item["tool_calls"][0]["function"]
qianfan_request["messages"] = messages
self.qianfan_req_post_process(qianfan_request)
return qianfan_request

def openai_completion_request_to_qianfan(
Expand All @@ -214,6 +215,7 @@ def openai_completion_request_to_qianfan(
if isinstance(prompt, list):
prompt = "".join(prompt)
qianfan_request["prompt"] = prompt
self.qianfan_req_post_process(qianfan_request)
return qianfan_request

def convert_openai_embedding_request(
Expand All @@ -232,16 +234,29 @@ def convert_openai_embedding_request(
request_list = []
i = 0
while i < len(input):
self.qianfan_req_post_process(qianfan_request)
request_list.append(
{
"texts": input[i : min(i + self.EmbeddingBatchSize, len(input))],
**qianfan_request,
},
self.qianfan_req_post_process(
{
"texts": input[
i : min(i + self.EmbeddingBatchSize, len(input))
],
**qianfan_request,
}
)
)
i += self.EmbeddingBatchSize

return request_list

def qianfan_req_post_process(
self, qianfan_request: Dict[str, Any]
) -> Dict[str, Any]:
qianfan_request["extra_parameters"] = {
"request_source": f"qianfan_py_sdk_v{qianfan.VERSION}_openai"
}
return qianfan_request

@classmethod
def qianfan_chat_response_to_openai(
cls, openai_request: OpenAIRequest, qianfan_response_list: List[QianfanResponse]
Expand Down
4 changes: 2 additions & 2 deletions python/qianfan/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ def deploy(self, **kwargs: Any) -> "Service":
if self.deploy_config.qps is not None:
res_config["qps"] = self.deploy_config.qps
svc_publish_resp = api.Service.V2.create_service(
model_id=model.id,
model_version_id=model.version_id,
model_set_id=model.id,
model_id=model.version_id,
name=self.deploy_config.name or f"svc{model.id}_{model.version_id}",
url_suffix=self.deploy_config.endpoint_suffix
or f"svc{model.id}_{model.version_id}",
Expand Down
7 changes: 5 additions & 2 deletions python/qianfan/resources/console/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,10 @@ def list_all_entity_in_dataset(
def create_offline_batch_inference_task(
cls,
name: str,
endpoint: str,
input_bos_uri: str,
output_bos_uri: str,
model_id: Optional[str] = None,
endpoint: Optional[str] = None,
inference_params: Dict[str, Any] = {},
description: Optional[str] = None,
**kwargs: Any,
Expand All @@ -888,8 +889,10 @@ def create_offline_batch_inference_task(
Parameters:
name (str):
Name of the batch inference task
model_id (Optional[str]):
model id of the model to be used for inference.
endpoint (str):
Endpoint of the model to be used for inference
Endpoint of the model to be used for inference.
input_bos_uri (str):
BOS URI of the input data
output_bos_uri (str):
Expand Down
11 changes: 11 additions & 0 deletions python/qianfan/resources/console/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def create_task(
dataset_config: Dict[str, Any],
increment_task_id: Optional[str] = None,
increment_checkpoint_step: Optional[int] = None,
model_config: Optional[Dict[str, Any]] = None,
resource_config: Optional[Dict[str, Any]] = None,
**kwargs: Any,
) -> QfRequest:
"""
Expand All @@ -255,6 +257,11 @@ def create_task(
The task id of the increment task.
increment_checkpoint_step (Optional[int]):
The checkpoint step for the increment task.
model_config (Optional[Dict[str, Any]]):
The model config of the fine-tuning task for custom_mode training.
resource_config (Optional[Dict[str, Any]]):
The resource config of the fine-tuning task, which can indicates
the specific private resources.
kwargs:
Additional keyword arguments that can be passed to customize
the request.
Expand Down Expand Up @@ -283,6 +290,10 @@ def create_task(
req.json_body["incrementTaskId"] = increment_task_id
if increment_checkpoint_step is not None:
req.json_body["incrementCheckpointStep"] = increment_checkpoint_step
if model_config is not None:
req.json_body["modelConfig"] = model_config
if resource_config is not None:
req.json_body["resourceConfig"] = resource_config
return req

@classmethod
Expand Down
16 changes: 8 additions & 8 deletions python/qianfan/resources/console/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def service_list(
@console_api_request
def create_service(
cls,
model_set_id: str,
model_id: str,
model_version_id: str,
name: str,
url_suffix: str,
resource_config: Dict,
Expand All @@ -232,9 +232,9 @@ def create_service(
get service list .
Parameters:
model_set_id: str,
model set id.
model_id: str,
model id.
model_version_id: str,
model version id.
name: str,
service name.
Expand Down Expand Up @@ -264,8 +264,8 @@ def create_service(
k: v
for k, v in {
**kwargs,
"modelSetId": model_set_id,
"modelId": model_id,
"modelVersionId": model_version_id,
"name": name,
"urlSuffix": url_suffix,
"description": description,
Expand Down Expand Up @@ -371,8 +371,8 @@ def service_metric(
def modify_service(
cls,
service_id: str,
model_set_id: str,
model_id: str,
model_version_id: str,
**kwargs: Any,
) -> QfRequest:
"""
Expand All @@ -381,9 +381,9 @@ def modify_service(
Parameters:
service_id: str,
service id. svco-xxx
model_set_id: str,
model set id. am-xxx
model_id: str,
model id. am-xxx
model_version_id: str,
model version id. amv-xxx
kwargs:
Expand All @@ -401,7 +401,7 @@ def modify_service(
)
req.json_body = {
"serviceId": service_id,
"modelSetId": model_set_id,
"modelId": model_id,
"modelVersionId": model_version_id,
}
return req
3 changes: 2 additions & 1 deletion python/qianfan/resources/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ def _generate_body(
kwargs["stream"] = stream
if "extra_parameters" not in kwargs:
kwargs["extra_parameters"] = {}
kwargs["extra_parameters"]["request_source"] = f"qianfan_py_sdk_v{VERSION}"
if kwargs["extra_parameters"].get("request_source") is None:
kwargs["extra_parameters"]["request_source"] = f"qianfan_py_sdk_v{VERSION}"
return kwargs

def _data_postprocess(self, data: QfResponse) -> QfResponse:
Expand Down
64 changes: 64 additions & 0 deletions python/qianfan/resources/llm/chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,52 @@ def _supported_models(cls) -> Dict[str, QfLLMInfo]:
input_price_per_1k_tokens=0.12,
output_price_per_1k_tokens=0.12,
),
"ERNIE-4.0-Turbo-8K": QfLLMInfo(
endpoint="/chat/ernie-4.0-turbo-8k",
required_keys={"messages"},
optional_keys={
"stream",
"temperature",
"top_p",
"penalty_score",
"user_id",
"system",
"stop",
"enable_system_memory",
"system_memory_id",
"disable_search",
"enable_citation",
"enable_trace",
"max_output_tokens",
"response_format",
},
max_input_chars=20000,
max_input_tokens=5120,
input_price_per_1k_tokens=0.12,
output_price_per_1k_tokens=0.12,
),
"ERNIE-Lite-AppBuilder-8K-0614": QfLLMInfo(
endpoint="/chat/ai_apaas_lite",
required_keys={"messages"},
optional_keys={
"stream",
"temperature",
"top_p",
"penalty_score",
"system",
"user_id",
"tools",
"tool_choice",
"max_output_tokens",
"min_output_tokens",
"frequency_penalty",
"presence_penalty",
},
max_input_chars=11200,
max_input_tokens=7168,
input_price_per_1k_tokens=0.004,
output_price_per_1k_tokens=0.008,
),
"ERNIE-3.5-8K-0613": QfLLMInfo(
endpoint="/chat/ernie-3.5-8k-0613",
required_keys={"messages"},
Expand Down Expand Up @@ -553,6 +599,24 @@ def _supported_models(cls) -> Dict[str, QfLLMInfo]:
input_price_per_1k_tokens=0.004,
output_price_per_1k_tokens=0.008,
),
"ERNIE-Character-Fiction-8K": QfLLMInfo(
endpoint="/chat/ernie-char-fiction-8k",
required_keys={"messages"},
optional_keys={
"stream",
"temperature",
"top_p",
"penalty_score",
"system",
"user_id",
"stop",
"max_output_tokens",
},
max_input_chars=24000,
max_input_tokens=6144,
input_price_per_1k_tokens=0.004,
output_price_per_1k_tokens=0.008,
),
"BLOOMZ-7B": QfLLMInfo(
endpoint="/chat/bloomz_7b1",
required_keys={"messages"},
Expand Down

0 comments on commit ec0e4fe

Please sign in to comment.