全部產品
Search
文件中心

Intelligent Media Services:如何傳入文本作為大語言模型輸入

更新時間:Oct 30, 2025

本文將為您介紹如何通過調用介面傳入文本作為大模型(LLM)輸入內容。

功能概述

在使用者與智能體的通話過程中,您可以通過調用介面的方式,手動將常值內容傳入大型語言模型(LLM)。這一過程顯著增強了智能體的功能和靈活性,使其能夠根據最新的對話內容動態調整響應內容。

應用情境

在視覺理解通話情境中,如果您需要將手機拍攝的畫面及其對應的常值內容同時傳輸至多模態大模型,為了避免在拍攝過程中手機缺乏聲音輸入,阿里雲將自動產生一段常值內容,並與映像一同傳遞給大模型。在此過程中,您也可以自訂傳入的常值內容。

功能實現

在AI即時互動中,您可以選擇在用戶端或服務端調用介面,傳入常值內容作為大型語言模型(LLM)的輸入。

範例程式碼

用戶端調用

您可以參考不同平台的範例程式碼,通過調用端側介面將常值內容傳遞至LLM。

Android
// 建立請求參數Req對象,傳入詢問智能體的簡訊
ARTCAICallSendTextToAgentRequest req = ARTCAICallSendTextToAgentRequest("xxx");
// 發送給Agent,注意需要在接通後調用,engine為ARTCAICallEngine的對象
engine.sendTextToAgent(req)
iOS
// 建立請求參數Req對象
let req = ARTCAICallSendTextToAgentRequest(text: "xxx")
// 發送給Agent,注意需要在接通後調用
_ = self.engine.sendTextToAgent(req: req)

Web
// 發送給Agent,注意需要在接通後調用,engine為ARTCAICallEngine對象
engine.sendTextToAgent(new AICallSendTextToAgentRequest('xxx'));

服務端調用

在服務端,您可以通過調用SendAIAgentText - 傳入訊息作為LLM輸入介面,將常值內容傳入LLM。

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.rtc;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>使用AK&amp;SK初始化帳號Client</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.ice20201109.Client createClient() throws Exception {
        // 工程代碼泄露可能會導致 AccessKey 泄露,並威脅帳號下所有資源的安全性。以下程式碼範例僅供參考。
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填,請確保代碼運行環境設定了環境變數 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId("yourak")
                // 必填,請確保代碼運行環境設定了環境變數 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret("yoursk");
        // Endpoint 請參考 https://api.aliyun.com/product/ICE
        config.endpoint = "ice.cn-shanghai.aliyuncs.com";
        return new com.aliyun.ice20201109.Client(config);
    }

    private static void sendAIAgentText() throws Exception {
        com.aliyun.ice20201109.Client client =  createClient();

        com.aliyun.ice20201109.models.SendAIAgentTextRequest request = new com.aliyun.ice20201109.models.SendAIAgentTextRequest()
            .setInstanceId("yourinstanceid")
            .setText("yourtext");
            try {
                // 複製代碼運行請自行列印 API 的傳回值
                com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
                
                client.sendAIAgentTextWithOptions(request, runtime);
            } catch (TeaException error) {
                // 此處僅做列印展示,請謹慎對待異常處理,在工程專案中切勿直接忽略異常。
                // 錯誤 message
                System.out.println(error.getMessage());
                // 診斷地址
                com.aliyun.teautil.Common.assertAsString(error.message);
            } catch (Exception _error) {
                TeaException error = new TeaException(_error.getMessage(), _error);
                // 此處僅做列印展示,請謹慎對待異常處理,在工程專案中切勿直接忽略異常。
                // 錯誤 message
                System.out.println(error.getMessage());
                // 診斷地址
                com.aliyun.teautil.Common.assertAsString(error.message);
            }   
    }

    public static void main(String[] args_) throws Exception {
        sendAIAgentText();
    }
}