重要
適用於 Azure Functions 的 Azure OpenAI 延伸模組目前為預覽狀態。
Azure OpenAI 助理查詢輸入繫結可讓您將助理 API 查詢整合到程式碼執行中。
如需 Azure OpenAI 延伸模組的安裝和設定詳細資訊,請參閱適用於 Azure Functions 的 Azure OpenAI 延伸模組。 若要深入了解 Azure OpenAI 助理,請參閱 Azure OpenAI 助理 API。
注意
參考和範例僅適用於 Node.js v4 模型。
注意
參考和範例僅適用於 Python v2 模型。
注意
雖然支援這兩個 C# 進程模型,但只會 提供隔離的背景工作模型 範例。
範例
此範例示範建立程序,其中 HTTP GET 函式可查詢助理聊天機器人的交談歷程記錄。 對提示的回應將在 HTTP 回應中傳回。
/// <summary>
/// HTTP GET function that queries the conversation history of the assistant chat bot.
/// </summary>
[Function(nameof(GetChatState))]
public static IActionResult GetChatState(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "assistants/{assistantId}")] HttpRequestData req,
string assistantId,
[AssistantQueryInput("{assistantId}", TimestampUtc = "{Query.timestampUTC}", ChatStorageConnectionSetting = DefaultChatStorageConnectionSetting, CollectionName = DefaultCollectionName)] AssistantState state)
{
return new OkObjectResult(state);
}
此範例示範建立程序,其中 HTTP GET 函式可查詢助理聊天機器人的交談歷程記錄。 對提示的回應將在 HTTP 回應中傳回。
/*
* HTTP GET function that queries the conversation history of the assistant chat bot.
*/
@FunctionName("GetChatState")
public HttpResponseMessage getChatState(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "assistants/{assistantId}")
HttpRequestMessage<Optional<String>> request,
@BindingName("assistantId") String assistantId,
@AssistantQuery(name = "AssistantState", id = "{assistantId}", timestampUtc = "{Query.timestampUTC}", chatStorageConnectionSetting = DEFAULT_CHATSTORAGE, collectionName = DEFAULT_COLLECTION) AssistantState state,
final ExecutionContext context) {
return request.createResponseBuilder(HttpStatus.OK)
.header("Content-Type", "application/json")
.body(state)
.build();
}
此範例示範建立程序,其中 HTTP GET 函式可查詢助理聊天機器人的交談歷程記錄。 對提示的回應將在 HTTP 回應中傳回。
const { app, input, output } = require("@azure/functions");
const chatBotQueryInput = input.generic({
type: 'assistantQuery',
id: '{assistantId}',
timestampUtc: '{Query.timestampUTC}',
chatStorageConnectionSetting: CHAT_STORAGE_CONNECTION_SETTING,
collectionName: COLLECTION_NAME
})
app.http('GetChatState', {
methods: ['GET'],
route: 'assistants/{assistantId}',
authLevel: 'anonymous',
extraInputs: [chatBotQueryInput],
handler: async (_, context) => {
const state = context.extraInputs.get(chatBotQueryInput)
return { status: 200, jsonBody: state }
}
})
此範例示範建立程序,其中 HTTP GET 函式可查詢助理聊天機器人的交談歷程記錄。 對提示的回應將在 HTTP 回應中傳回。
import { HttpRequest, InvocationContext, app, input, output } from "@azure/functions"
const chatBotQueryInput = input.generic({
type: 'assistantQuery',
id: '{assistantId}',
timestampUtc: '{Query.timestampUTC}',
chatStorageConnectionSetting: CHAT_STORAGE_CONNECTION_SETTING,
collectionName: COLLECTION_NAME
})
app.http('GetChatState', {
methods: ['GET'],
route: 'assistants/{assistantId}',
authLevel: 'anonymous',
extraInputs: [chatBotQueryInput],
handler: async (_, context) => {
const state: any = context.extraInputs.get(chatBotQueryInput)
return { status: 200, jsonBody: state }
}
})
此範例示範建立程序,其中 HTTP GET 函式可查詢助理聊天機器人的交談歷程記錄。 對提示的回應將在 HTTP 回應中傳回。
以下是 取得聊天狀態的function.json 檔案:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"route": "assistants/{assistantId}",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
},
{
"name": "State",
"type": "assistantQuery",
"direction": "in",
"dataType": "string",
"id": "{assistantId}",
"timestampUtc": "{Query.timestampUTC}",
"chatStorageConnectionSetting": "AzureWebJobsStorage",
"collectionName": "ChatState"
}
]
}
如需 function.json 檔案屬性的詳細資訊,請參閱設定一節。
using namespace System.Net
param($Request, $TriggerMetadata, $State)
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $State
Headers = @{
"Content-Type" = "application/json"
}
})
此範例示範建立程序,其中 HTTP GET 函式可查詢助理聊天機器人的交談歷程記錄。 對提示的回應將在 HTTP 回應中傳回。
@apis.function_name("GetChatState")
@apis.route(route="assistants/{assistantId}", methods=["GET"])
@apis.assistant_query_input(
arg_name="state",
id="{assistantId}",
timestamp_utc="{Query.timestampUTC}",
chat_storage_connection_setting=DEFAULT_CHAT_STORAGE_SETTING,
collection_name=DEFAULT_CHAT_COLLECTION_NAME,
)
def get_chat_state(req: func.HttpRequest, state: str) -> func.HttpResponse:
return func.HttpResponse(state, status_code=200, mimetype="application/json")
屬性
套用 AssistantQuery
屬性來定義助理查詢輸入繫結,其支援下列參數:
參數 | 描述 |
---|---|
標識碼 | 取得要查詢之助理的識別碼。 |
時間戳UTC | 選擇性。 取得或設定要擷取之聊天歷程記錄中最早訊息的時間戳記。 時間戳應為 ISO 8601 格式,例如 2023-08-01T00:00:00Z。 |
註釋
assistantQuery
註釋可讓您定義助理查詢輸入繫結,其支援下列參數:
元素 | 描述 |
---|---|
名字 | 取得或設定輸入繫結的名稱。 |
識別碼 | 取得要查詢之助理的識別碼。 |
時間戳UTC | 選擇性。 取得或設定要擷取之聊天歷程記錄中最早訊息的時間戳記。 時間戳應為 ISO 8601 格式,例如 2023-08-01T00:00:00Z。 |
裝飾項目
在預覽期間,將輸入繫結定義為 generic_input_binding
類型的 assistantQuery
繫結,其支援下列參數:
參數 | 描述 |
---|---|
arg_name | 代表繫結參數的變數名稱。 |
識別碼 | 取得要查詢之助理的識別碼。 |
time_stamp_utc | 選擇性。 取得或設定要擷取之聊天歷程記錄中最早訊息的時間戳記。 時間戳應為 ISO 8601 格式,例如 2023-08-01T00:00:00Z。 |
組態
繫結支援您在 function.json 檔案中設定的下列組態屬性。
屬性 | 描述 |
---|---|
類型 | 必須是 assistantQuery 。 |
方向 | 必須是 in 。 |
名字 | 輸入繫結的名稱。 |
識別碼 | 取得要查詢之助理的識別碼。 |
時間戳UTC | 選擇性。 取得或設定要擷取之聊天歷程記錄中最早訊息的時間戳記。 時間戳應為 ISO 8601 格式,例如 2023-08-01T00:00:00Z。 |
組態
繫結支援您在程式碼中定義的下列屬性:
屬性 | 描述 |
---|---|
識別碼 | 取得要查詢之助理的識別碼。 |
時間戳UTC | 選擇性。 取得或設定要擷取之聊天歷程記錄中最早訊息的時間戳記。 時間戳應為 ISO 8601 格式,例如 2023-08-01T00:00:00Z。 |
使用方式
如需完整範例,請參閱範例一節。