Skip to content

Commit 205c1bd

Browse files
docs: mirror README additions to zh/ja
1 parent a3e8ceb commit 205c1bd

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

‎README_ja.md‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,26 @@ response = MultiModalConversation.call(model="qwen-vl-max", messages=messages)
290290
print(response.output.choices[0].message.content[0]["text"])
291291
```
292292

293+
`AioMultiModalConversation` を使うと `async`/`await` 形式で呼び出せます:
294+
295+
```python
296+
import asyncio
297+
from dashscope import AioMultiModalConversation
298+
299+
async def main():
300+
messages = [{
301+
"role": "user",
302+
"content": [
303+
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"},
304+
{"text": "この画像には何が写っていますか?"},
305+
],
306+
}]
307+
response = await AioMultiModalConversation.call(model="qwen-vl-max", messages=messages)
308+
print(response.output.choices[0].message.content[0]["text"])
309+
310+
asyncio.run(main())
311+
```
312+
293313
### ローカルファイルの使用
294314

295315
URL を受け付けるすべてのフィールド(messages 内の `image`、`audio`、`video`、`ImageSynthesis` の `images` など)は、ローカルファイルパスもそのまま受け付けます。SDK が自動的に OSS へアップロードするため、手動でヘッダーを設定する必要はありません:
@@ -334,6 +354,22 @@ resp = MultiModalEmbedding.call(
334354
print(resp.output)
335355
```
336356

357+
### バッチ(オフライン)テキスト Embedding
358+
359+
大量のテキストを扱う場合、`TextEmbedding.call` を1件ずつ呼び出す代わりに、ファイル(1行1テキスト)を送信して非同期のバッチ Embedding を実行できます:
360+
361+
```python
362+
from dashscope import BatchTextEmbedding
363+
364+
resp = BatchTextEmbedding.call(
365+
model=BatchTextEmbedding.Models.text_embedding_async_v2,
366+
url="https://example.com/texts.txt",
367+
)
368+
print(resp.output.task_id, resp.output.task_status)
369+
if resp.output.task_status == "SUCCEEDED":
370+
print(resp.output.url) # ここから結果ファイルをダウンロード
371+
```
372+
337373
### テキストリランキング
338374

339375
```python
@@ -353,6 +389,26 @@ for r in resp.output.results:
353389
print(r.index, r.relevance_score, r.document)
354390
```
355391

392+
`AioTextReRank` を使うと `async`/`await` 形式で呼び出せます:
393+
394+
```python
395+
import asyncio
396+
from dashscope import AioTextReRank
397+
398+
async def main():
399+
resp = await AioTextReRank.call(
400+
model=AioTextReRank.Models.gte_rerank,
401+
query="中国の首都はどこですか?",
402+
documents=["中国の首都は北京です。", "中国は東アジアにある広大な国です。"],
403+
return_documents=True,
404+
top_n=1,
405+
)
406+
for r in resp.output.results:
407+
print(r.index, r.relevance_score, r.document)
408+
409+
asyncio.run(main())
410+
```
411+
356412
### コード生成
357413

358414
`CodeGeneration` は特定のコーディングシーン(`Scenes`)に対応しています:自然言語からのコード生成、コードの説明、コメント生成、コミットメッセージ生成、単体テスト生成、コードに関する質問応答、自然言語から SQL への変換など。
@@ -436,6 +492,21 @@ with open("output.wav", "wb") as f:
436492
f.write(result.get_audio_data())
437493
```
438494

495+
`HttpSpeechSynthesizer` は通常の HTTP(WebSocket 不要)で音声合成を呼び出します。持続的な接続を維持できない環境で便利です:
496+
497+
```python
498+
from dashscope.audio.http_tts import HttpSpeechSynthesizer
499+
500+
result = HttpSpeechSynthesizer.call(
501+
model="cosyvoice-v3-flash",
502+
text="Hello, Bailian.",
503+
voice="longxiaochun",
504+
audio_format="wav",
505+
)
506+
with open("output.wav", "wb") as f:
507+
f.write(result.audio_data)
508+
```
509+
439510
### ストリーミング音声合成(CosyVoice v2)
440511

441512
テキストを逐次ストリーミングで送信し、生成された音声データをコールバック経由でリアルタイムに受け取ります:

‎README_zh.md‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,26 @@ response = MultiModalConversation.call(model="qwen-vl-max", messages=messages)
288288
print(response.output.choices[0].message.content[0]["text"])
289289
```
290290

291+
使用 `AioMultiModalConversation` 可获得 `async`/`await` 形式:
292+
293+
```python
294+
import asyncio
295+
from dashscope import AioMultiModalConversation
296+
297+
async def main():
298+
messages = [{
299+
"role": "user",
300+
"content": [
301+
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"},
302+
{"text": "图中描绘的是什么景象?"},
303+
],
304+
}]
305+
response = await AioMultiModalConversation.call(model="qwen-vl-max", messages=messages)
306+
print(response.output.choices[0].message.content[0]["text"])
307+
308+
asyncio.run(main())
309+
```
310+
291311
### 使用本地文件
292312

293313
任何接受 URL 的字段(messages 中的 `image`、`audio`、`video`,`ImageSynthesis` 的 `images` 等)同样支持本地文件路径——SDK 会自动上传到 OSS,无需手动设置请求头:
@@ -332,6 +352,22 @@ resp = MultiModalEmbedding.call(
332352
print(resp.output)
333353
```
334354

355+
### 批量(离线)文本向量
356+
357+
对于大批量文本,可以提交一个文件(每行一条文本)进行异步批量向量化,而不必逐条调用 `TextEmbedding.call`:
358+
359+
```python
360+
from dashscope import BatchTextEmbedding
361+
362+
resp = BatchTextEmbedding.call(
363+
model=BatchTextEmbedding.Models.text_embedding_async_v2,
364+
url="https://example.com/texts.txt",
365+
)
366+
print(resp.output.task_id, resp.output.task_status)
367+
if resp.output.task_status == "SUCCEEDED":
368+
print(resp.output.url) # 从这里下载结果文件
369+
```
370+
335371
### 文本重排(ReRank)
336372

337373
```python
@@ -351,6 +387,26 @@ for r in resp.output.results:
351387
print(r.index, r.relevance_score, r.document)
352388
```
353389

390+
使用 `AioTextReRank` 可获得 `async`/`await` 形式:
391+
392+
```python
393+
import asyncio
394+
from dashscope import AioTextReRank
395+
396+
async def main():
397+
resp = await AioTextReRank.call(
398+
model=AioTextReRank.Models.gte_rerank,
399+
query="哈尔滨在哪?",
400+
documents=["黑龙江离俄罗斯很近", "哈尔滨是中国黑龙江省的省会,位于中国东北"],
401+
return_documents=True,
402+
top_n=1,
403+
)
404+
for r in resp.output.results:
405+
print(r.index, r.relevance_score, r.document)
406+
407+
asyncio.run(main())
408+
```
409+
354410
### 代码生成
355411

356412
`CodeGeneration` 面向特定编程场景(`Scenes`):自然语言生成代码、代码解释、生成注释、生成 commit message、生成单元测试、代码问答、自然语言生成 SQL。
@@ -434,6 +490,21 @@ with open("output.wav", "wb") as f:
434490
f.write(result.get_audio_data())
435491
```
436492

493+
`HttpSpeechSynthesizer` 通过普通 HTTP(无需 WebSocket)调用语音合成,适用于无法保持持久连接的环境:
494+
495+
```python
496+
from dashscope.audio.http_tts import HttpSpeechSynthesizer
497+
498+
result = HttpSpeechSynthesizer.call(
499+
model="cosyvoice-v3-flash",
500+
text="Hello, Bailian.",
501+
voice="longxiaochun",
502+
audio_format="wav",
503+
)
504+
with open("output.wav", "wb") as f:
505+
f.write(result.audio_data)
506+
```
507+
437508
### 流式语音合成(CosyVoice v2)
438509

439510
流式传入文本,并通过回调实时接收生成中的音频数据:

0 commit comments

Comments
 (0)