Skip to main content
Lainnya Model

Pengenalan maksud

Mengidentifikasi maksud pengguna dalam hitungan milidetik dan memilih tool yang sesuai untuk menangani kueri.

Wilayah China (Beijing) saja. Gunakan API key dari China (Beijing).
Model Studio telah merilis domain khusus ruang kerja untuk wilayah China (Beijing), Singapura, dan China (Hong Kong). Domain khusus baru ini memberikan performa lebih unggul dan stabilitas lebih tinggi untuk permintaan inferensi. Kami merekomendasikan migrasi ke domain baru berikut:
  • China (Beijing): dari https://dashscope.aliyuncs.com ke https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapura: dari https://dashscope-intl.aliyuncs.com ke https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
  • China (Hong Kong): dari https://cn-hongkong.dashscope.aliyuncs.com ke https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com
{WorkspaceId} adalah ID ruang kerja Anda, yang dapat ditemukan di halaman Workspace Details pada Konsol Model Studio. Domain lama tetap berfungsi sepenuhnya.

Model yang didukung

Model

Context window

Max input

Max output

Input price

Output price

(tokens)

(per 1M tokens)

tongyi-intent-detect-v3

8.192

8.192

1.024

$0,058

$0,144

Penggunaan

Prasyarat

Dapatkan API key dan ekspor API key sebagai variabel lingkungan. Jika Anda menggunakan OpenAI SDK atau DashScope SDK untuk melakukan panggilan, instal SDK.

Output informasi maksud dan pemanggilan fungsi sekaligus

Untuk mengembalikan informasi maksud dan pemanggilan fungsi sekaligus, atur pesan sistem sebagai berikut:
You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{Tool information}
Response in INTENT_MODE.
Sertakan Response in INTENT_MODE. dalam pesan sistem dan tentukan tool yang tersedia. Format informasi tool adalah sebagai berikut:
[{
    "name": "Name of tool 1",
    "description": "Description of tool 1",
    "parameters": {
        "type": "The type of the parameter, typically object",
        "properties": {
            "parameter_1": {
                "description": "Description of parameter_1",
                "type": "Type of parameter_1",
                "default": "Default value of parameter_1"
            },
            ...
            "parameter_n": {
                "description": "Description of parameter_n",
                "type": "Type of parameter_n",
                "default": "Default value of parameter_n"
            }
        },
        "required": [
        "parameter_1",
        ...
        "parameter_n"
    ]
    },
},
...
{
    "name": "Name of tool n",
    "description": "Description of tool n",
    "parameters": {
        "type": "The type of the parameter, typically object",
        "properties": {
            "parameter_1": {
                "description": "Description of parameter_1",
                "type": "Type of parameter_1",
                "default": "Default value of parameter_1"
            },
            ...
            "parameter_n": {
                "description": "Description of parameter_n",
                "type": "Type of parameter_n",
                "default": "Default value of parameter_n"
            }
        },
        "required": [
        "parameter_1",
        ...
        "parameter_n"
    ]
    },
}]
Contoh dengan dua tool (kueri waktu dan kueri cuaca):
[
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District."
                }
            },
            "required": ["location"]
        }
    }
]

Contoh permintaan

import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

tools_string = json.dumps(tools,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in INTENT_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Weather in Hangzhou"}
    ]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3",
    messages=messages
)

print(response.choices[0].message.content)

Contoh respons

<tags>
[function call, json response]
</tags><tool_call>
[{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}]
</tool_call><content>

</content>
Uraikan respons menggunakan fungsi parse_text:
import re

def parse_text(text):
    # Define regular expression patterns to match <tags>, <tool_call>, <content>, and their content
    tags_pattern = r'<tags>(.*?)</tags>'
    tool_call_pattern = r'<tool_call>(.*?)</tool_call>'
    content_pattern = r'<content>(.*?)</content>'
    # Use regular expressions to find matching content
    tags_match = re.search(tags_pattern, text, re.DOTALL)
    tool_call_match = re.search(tool_call_pattern, text, re.DOTALL)
    content_match = re.search(content_pattern, text, re.DOTALL)
    # Extract matched content (returns empty string if no match)
    tags = tags_match.group(1).strip() if tags_match else ""
    tool_call = tool_call_match.group(1).strip() if tool_call_match else ""
    content = content_match.group(1).strip() if content_match else ""
    # Store the extracted content in a dictionary
    result = {
      "tags": tags,
      "tool_call": tool_call,
      "content": content
    }
    return result

response = """<tags>
[function call, json response]
</tags><tool_call>
[{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}]
</tool_call><content>

</content>"""
print(parse_text(response))
Output-nya sebagai berikut:
{
    "tags": "[function call, json response]",
    "tool_call": [
        {
            "name": "get_current_weather",
            "arguments": {
                "location": "Hangzhou"
            }
        }
    ],
    "content": ""
}

Keluarkan hanya informasi intent

Untuk mengembalikan hanya informasi maksud, atur pesan sistem sebagai berikut:
You are Qwen, created by Alibaba Cloud. You are a helpful assistant. \nYou should choose one tag from the tag list:\n{intent information}\njust reply with the chosen tag.
Format informasi maksud adalah sebagai berikut:
{
    "Intent 1": "Description of Intent 1",
    "Intent 2": "Description of Intent 2",
    "Intent 3": "Description of Intent 3",
    ...
}

Contoh permintaan

import os
import json
from openai import OpenAI

intent_dict = {
    "play_game": "Play game",
    "email_querycontact": "Email query contact",
    "general_quirky": "quirky",
    "email_addcontact": "Email add contact",
    "takeaway_query": "Takeaway query",
    "recommendation_locations": "Location recommendation",
    "transport_traffic": "Transportation",
    "iot_cleaning": "IoT - vacuum cleaner, cleaner",
    "general_joke": "Joke",
    "lists_query": "Query list/checklist",
    "calendar_remove": "Calendar delete event",
    "transport_taxi": "Taxi, taxi booking",
    "qa_factoid": "Factual Q&A",
    "transport_ticket": "Transportation ticket",
    "play_radio": "Play radio",
    "alarm_set": "Set alarm",
}

intent_string = json.dumps(intent_dict,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
You should choose one tag from the tag list:
{intent_string}
Just reply with the chosen tag."""

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Wake me up at nine on Friday morning"}
    ]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3",
    messages=messages
)

print(response.choices[0].message.content)

Contoh respons

alarm_set

Tingkatkan kecepatan respons pengenalan maksud

Untuk meningkatkan kecepatan respons, gunakan huruf kapital tunggal untuk kategori maksud. Hal ini menghasilkan respons satu-token, sehingga mengoptimalkan latensi panggilan model.
import os
import json
from openai import OpenAI

intent_dict = {
    "A": "Play game",
    "B": "Email query contact",
    "C": "quirky",
    "D": "Email add contact",
    "E": "Takeaway query",
    "F": "Location recommendation",
    "G": "Transportation",
    "H": "IoT - vacuum cleaner, cleaner",
    "I": "Joke",
    "J": "Query list/checklist",
    "K": "Calendar delete event",
    "L": "Taxi, taxi booking",
    "M": "Factual Q&A",
    "N": "Transportation ticket",
    "O": "Play radio",
    "P": "Set alarm",
}

intent_string = json.dumps(intent_dict, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
You should choose one tag from the tag list:
{intent_string}
Just reply with the chosen tag."""

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "What is the earliest flight from Beijing to Hangzhou?"},
]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)

print(response.choices[0].message.content)
Output: hasil maksud satu-token.
M

Hanya output informasi pemanggilan fungsi

Untuk mengembalikan hanya informasi pemanggilan fungsi, atur pesan sistem sebagai berikut:
You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:\n{Tool information}\nResponse in NORMAL_MODE.
Format informasi tool sama seperti pada bagian Output informasi maksud dan pemanggilan fungsi sekaligus.

Contoh permintaan

import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

tools_string = json.dumps(tools,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in NORMAL_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Weather in Hangzhou"}
    ]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3",
    messages=messages
)

print(response.choices[0].message.content)

Contoh respons

<tool_call>
{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}
</tool_call>
Setelah menerima respons, gunakan fungsi parse_text untuk mengurai informasi tool dan parameter yang dikembalikan:
import re

def parse_text(text):
    tool_call_pattern = r'<tool_call>(.*?)</tool_call>'
    # Use regular expressions to find matching content
    tool_call_match = re.search(tool_call_pattern, text, re.DOTALL)
    # Extract matched content (returns empty string if no match)
    tool_call = tool_call_match.group(1).strip() if tool_call_match else ""
    return tool_call

response = """<tool_call>
{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}
</tool_call>"""
print(parse_text(response))
Output-nya sebagai berikut:
{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}

Konversasi multi-putaran

Jika sebuah kueri tidak memiliki informasi yang cukup, model akan mengajukan pertanyaan lanjutan. Setelah mengumpulkan parameter yang diperlukan, model akan mengembalikan informasi pemanggilan fungsi.
  • Output informasi maksud dan pemanggilan fungsi sekaligus
  • Hanya output informasi pemanggilan fungsi
Contoh permintaan
import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {},
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"],
        },
    },
]

tools_string = json.dumps(tools, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in INTENT_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {"role": "system", "content": system_prompt},
    # First round question
    {"role": "user", "content": "I want to check the weather"},
]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)

print("Query: I want to check the weather")
print("First-round output:\n")
print(response.choices[0].message.content)
messages.append(response.choices[0].message)
# Second round question
messages.append({"role": "user", "content": "In Hangzhou"})
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)
print("\nQuery: In Hangzhou")
print("Second-round output:\n")
print(response.choices[0].message.content)
Contoh respons
Query: I want to check the weather
First-round output:

<tags>
[weather inquiry]
</tags><tool_call>
[]
</tool_call><content>
OK. Which city's weather would you like to check?
</content>

Query: Hangzhou
Second-round output:

<tags>
[function call, json response]
</tags><tool_call>
[{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}]
</tool_call><content>

</content>

FAQ

Berapa jumlah maksimum tool yang dapat diberikan?

Berikan tidak lebih dari 10 tool. Melebihi batas ini dapat mengurangi akurasi pemanggilan tool.
Pembuatan Gambar
  • FAQ
Video Generation
Model Dunia
Audio
  • Pembuatan audio
Realtime API
Penyematan Teks
TokenPlan
Model production