Skip to content

Commit 3a4a537

Browse files
authored
Merge pull request #40 from songguocola/dev/tingwu
feat(multimodal-dialog): add tingwu api
2 parents f9bc3fe + 9e44123 commit 3a4a537

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

dashscope/multimodal/tingwu/__init__.py

Whitespace-only changes.

dashscope/multimodal/tingwu/tingwu.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from typing import Dict, Any
2+
3+
from dashscope.api_entities.api_request_factory import _build_api_request
4+
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
5+
from dashscope.client.base_api import BaseApi
6+
from dashscope.common.error import ModelRequired
7+
8+
9+
class TingWu(BaseApi):
10+
"""API for TingWu APP.
11+
12+
"""
13+
14+
task = None
15+
task_group = None
16+
function = None
17+
18+
@classmethod
19+
def call(
20+
cls,
21+
model: str,
22+
user_defined_input: Dict[str, Any],
23+
parameters: Dict[str, Any] = None,
24+
api_key: str = None,
25+
**kwargs
26+
) -> DashScopeAPIResponse:
27+
"""Call generation model service.
28+
29+
Args:
30+
model (str): The requested model, such as qwen-turbo
31+
api_key (str, optional): The api api_key, can be None,
32+
if None, will get by default rule(TODO: api key doc).
33+
user_defined_input: custom input
34+
parameters: custom parameters
35+
**kwargs:
36+
base_address: base address
37+
additional parameters for request
38+
39+
Raises:
40+
InvalidInput: The history and auto_history are mutually exclusive.
41+
42+
Returns:
43+
Union[GenerationResponse,
44+
Generator[GenerationResponse, None, None]]: If
45+
stream is True, return Generator, otherwise GenerationResponse.
46+
"""
47+
if model is None or not model:
48+
raise ModelRequired('Model is required!')
49+
input_config, parameters = cls._build_input_parameters(input_config=user_defined_input,
50+
params=parameters,
51+
**kwargs)
52+
53+
request = _build_api_request(
54+
model=model,
55+
input=input_config,
56+
api_key=api_key,
57+
task_group=TingWu.task_group,
58+
task=TingWu.task,
59+
function=TingWu.function,
60+
is_service=False,
61+
**parameters)
62+
response = request.call()
63+
64+
return response
65+
66+
@classmethod
67+
def _build_input_parameters(cls,
68+
input_config,
69+
params: Dict[str, Any] = None,
70+
**kwargs):
71+
parameters = {}
72+
if params is not None:
73+
parameters = params
74+
75+
input_param = input_config
76+
77+
if kwargs.keys() is not None:
78+
for key in kwargs.keys():
79+
parameters[key] = kwargs[key]
80+
return input_param, {**parameters, **kwargs}

samples/test_tingwu_usages.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 调用TingWu
2+
from dashscope.multimodal.tingwu.tingwu import TingWu
3+
import os
4+
5+
# 创建TingWu实例
6+
tingwu = TingWu()
7+
resp = TingWu.call(
8+
model='tingwu-automotive-service-inspection',
9+
user_defined_input={"fileUrl": "http://demo.com/test.mp3", "appid": "123456"},
10+
api_key=os.getenv("DASHSCOPE_API_KEY"),
11+
base_address="https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"
12+
)
13+
print(resp)

0 commit comments

Comments
 (0)