Skip to content

Commit da75c67

Browse files
feat: add tongyi model bury point header (langgenius#2241)
* feat: add tongyi model bury point header * feat: add tongyi model bury point header * feat: add tongyi model bury point header, update version * feat: add tongyi model bury point header, update version * feat: add tongyi model bury point header, update version * feat: add tongyi model bury point header, update version --------- Co-authored-by: zhaojiangang-it <zjg02419448@alibaba-inc.com>
1 parent 0453b8c commit da75c67

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

models/tongyi/PRIVACY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Privacy
2+
3+
For full terms and privacy policy of tongyi, please visit https://help.aliyun.com/zh/model-studio/privacy-notice

models/tongyi/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ resource:
2525
model:
2626
enabled: false
2727
type: plugin
28-
version: 0.1.8
28+
version: 0.1.9
2929
created_at: "2024-12-10T16:13:50.29298939+08:00"

models/tongyi/models/constant.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://help.aliyun.com/zh/marketplace/partner-driven-large-model-tokens-consumption-buried-point-proposal?spm=a2c4g.11186623.help-menu-30488.d_2_2_0.53a66065QheeNw&scm=20140722.H_2927986._.OR_help-T_cn~zh-V_1
2+
# bury point header for aliyun
3+
BURY_POINT_HEADER = {
4+
'x-dashscope-euid': '{"bizType":"B2B", "moduleType":"Third-partyproducts", "moduleCode":"market_91320506MACC8K9EXF", "accountType":"Aliyun", "accountId":""}'}

models/tongyi/models/llm/llm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
)
6161
from dify_plugin.interfaces.model.large_language_model import LargeLanguageModel
6262
from openai import OpenAI
63+
from ..constant import BURY_POINT_HEADER
6364

6465
logger = logging.getLogger(__name__)
6566

@@ -247,13 +248,18 @@ def _generate(
247248
params["messages"] = self._convert_prompt_messages_to_tongyi_messages(
248249
credentials, prompt_messages, rich_content=True
249250
)
250-
response = MultiModalConversation.call(**params, stream=stream, incremental_output=incremental_output)
251+
response = MultiModalConversation.call(
252+
**params,
253+
stream=stream,
254+
headers=BURY_POINT_HEADER,
255+
incremental_output=incremental_output)
251256
else:
252257
params["messages"] = self._convert_prompt_messages_to_tongyi_messages(
253258
credentials, prompt_messages
254259
)
255260
response = Generation.call(
256261
**params,
262+
headers=BURY_POINT_HEADER,
257263
result_format="message",
258264
stream=stream,
259265
incremental_output=incremental_output,

models/tongyi/models/rerank/rerank.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
InvokeServerUnavailableError,
2020
)
2121
from dify_plugin.interfaces.model.rerank_model import RerankModel
22-
22+
from ..constant import BURY_POINT_HEADER
2323

2424
class GTERerankModel(RerankModel):
2525
"""
@@ -54,7 +54,7 @@ def _invoke(
5454
dashscope.base_http_api_url = "https://dashscope-intl.aliyuncs.com/api/v1"
5555
dashscope.api_key = credentials["dashscope_api_key"]
5656
response = dashscope.TextReRank.call(
57-
query=query, documents=docs, model=model, top_n=top_n, return_documents=True
57+
query=query, headers=BURY_POINT_HEADER, documents=docs, model=model, top_n=top_n, return_documents=True
5858
)
5959
rerank_documents = []
6060
if not response.output:

models/tongyi/models/speech2text/speech2text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dashscope
77
from dify_plugin import OAICompatSpeech2TextModel
88
from dashscope.audio.asr import *
9+
from ..constant import BURY_POINT_HEADER
910

1011
class TongyiSpeech2TextModel(OAICompatSpeech2TextModel):
1112
"""
@@ -41,7 +42,7 @@ def _invoke(self, model: str, credentials: dict, file: IO[bytes], user: Optional
4142
sample_rate=int(sample_rate),
4243
callback=None,
4344
)
44-
result = recognition.call(file_path)
45+
result = recognition.call(file=file_path, headers=BURY_POINT_HEADER)
4546
sentence_list = result.get_sentence()
4647
if sentence_list is None:
4748
return ''

models/tongyi/models/text_embedding/text_embedding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dify_plugin.errors.model import CredentialsValidateFailedError
88
from dify_plugin.interfaces.model.text_embedding_model import TextEmbeddingModel
99
from models._common import _CommonTongyi
10-
10+
from ..constant import BURY_POINT_HEADER
1111

1212
class TongyiTextEmbeddingModel(_CommonTongyi, TextEmbeddingModel):
1313
"""
@@ -109,7 +109,8 @@ def call_embedding_api(text):
109109
return dashscope.TextEmbedding.call(
110110
api_key=credentials_kwargs["dashscope_api_key"],
111111
model=model,
112-
input=text,
112+
input=text,
113+
headers=BURY_POINT_HEADER,
113114
text_type="document"
114115
)
115116
except Exception as e:
@@ -119,7 +120,6 @@ def call_embedding_api(text):
119120
for text in texts:
120121
# First attempt
121122
response = call_embedding_api(text)
122-
123123
# Handle rate limit error (429)
124124
# Check if response is an exception with rate limit info
125125
if hasattr(response, 'status_code') and response.status_code == 429:

models/tongyi/models/tts/tts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dify_plugin.errors.model import CredentialsValidateFailedError, InvokeBadRequestError
99
from dify_plugin.interfaces.model.tts_model import TTSModel
1010
from models._common import _CommonTongyi
11-
11+
from ..constant import BURY_POINT_HEADER
1212

1313
class TongyiText2SpeechModel(_CommonTongyi, TTSModel):
1414
"""
@@ -117,6 +117,7 @@ def _process_sentence(sentence: str, credentials: dict, voice: str, audio_type:
117117
sample_rate=48000,
118118
api_key=credentials.get("dashscope_api_key"),
119119
text=sentence.strip(),
120+
headers=BURY_POINT_HEADER,
120121
format=audio_type,
121122
)
122123
if isinstance(response.get_audio_data(), bytes):

0 commit comments

Comments
 (0)