Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Importante
L'estensione OpenAI di Azure per Funzioni di Azure è attualmente in anteprima.
L'assistente Azure OpenAI crea associazione di output consente di creare un nuovo chatbot assistente dall'esecuzione del codice della funzione.
Per informazioni sull'installazione e la configurazione dell'estensione OpenAI di Azure, vedere Estensioni OpenAI di Azure per Funzioni di Azure. Per altre informazioni sugli assistenti OpenAI di Azure, vedere API Assistenti OpenAI di Azure.
Nota
I riferimenti e gli esempi vengono forniti solo per il modello Node.js v4.
Nota
I riferimenti e gli esempi vengono forniti solo per il modello Python v2.
Nota
Anche se sono supportati entrambi i modelli di processo C#, vengono forniti solo esempi di modelli di lavoro isolati.
Esempio
In questo esempio viene illustrato il processo di creazione, in cui la funzione HTTP PUT che crea un nuovo chatbot assistente con l'ID specificato. La risposta alla richiesta viene restituita nella risposta HTTP.
/// <summary>
/// HTTP PUT function that creates a new assistant chat bot with the specified ID.
/// </summary>
[Function(nameof(CreateAssistant))]
public static async Task<CreateChatBotOutput> CreateAssistant(
[HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "assistants/{assistantId}")] HttpRequestData req,
string assistantId)
{
string instructions =
"""
Don't make assumptions about what values to plug into functions.
Ask for clarification if a user request is ambiguous.
""";
using StreamReader reader = new(req.Body);
string request = await reader.ReadToEndAsync();
return new CreateChatBotOutput
{
HttpResponse = new ObjectResult(new { assistantId }) { StatusCode = 201 },
ChatBotCreateRequest = new AssistantCreateRequest(assistantId, instructions)
{
ChatStorageConnectionSetting = DefaultChatStorageConnectionSetting,
CollectionName = DefaultCollectionName,
},
};
}
public class CreateChatBotOutput
{
[AssistantCreateOutput()]
public AssistantCreateRequest? ChatBotCreateRequest { get; set; }
[HttpResult]
public IActionResult? HttpResponse { get; set; }
}
In questo esempio viene illustrato il processo di creazione, in cui la funzione HTTP PUT che crea un nuovo chatbot assistente con l'ID specificato. La risposta alla richiesta viene restituita nella risposta HTTP.
/**
* The default storage account setting for the table storage account.
* This constant is used to specify the connection string for the table storage
* account
* where chat data will be stored.
*/
final String DEFAULT_CHATSTORAGE = "AzureWebJobsStorage";
/**
* The default collection name for the table storage account.
* This constant is used to specify the collection name for the table storage
* account
* where chat data will be stored.
*/
final String DEFAULT_COLLECTION = "ChatState";
/*
* HTTP PUT function that creates a new assistant chat bot with the specified ID.
*/
@FunctionName("CreateAssistant")
public HttpResponseMessage createAssistant(
@HttpTrigger(
name = "req",
methods = {HttpMethod.PUT},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "assistants/{assistantId}")
HttpRequestMessage<Optional<String>> request,
@BindingName("assistantId") String assistantId,
@AssistantCreate(name = "AssistantCreate") OutputBinding<AssistantCreateRequest> message,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");
String instructions = "Don't make assumptions about what values to plug into functions.\n" +
"Ask for clarification if a user request is ambiguous.";
AssistantCreateRequest assistantCreateRequest = new AssistantCreateRequest(assistantId, instructions);
assistantCreateRequest.setChatStorageConnectionSetting(DEFAULT_CHATSTORAGE);
assistantCreateRequest.setCollectionName(DEFAULT_COLLECTION);
message.setValue(assistantCreateRequest);
JSONObject response = new JSONObject();
response.put("assistantId", assistantId);
return request.createResponseBuilder(HttpStatus.CREATED)
.header("Content-Type", "application/json")
.body(response.toString())
.build();
}
In questo esempio viene illustrato il processo di creazione, in cui la funzione HTTP PUT che crea un nuovo chatbot assistente con l'ID specificato. La risposta alla richiesta viene restituita nella risposta HTTP.
const { app, input, output } = require("@azure/functions");
const CHAT_STORAGE_CONNECTION_SETTING = "AzureWebJobsStorage";
const COLLECTION_NAME = "ChatState";
const chatBotCreateOutput = output.generic({
type: 'assistantCreate'
})
app.http('CreateAssistant', {
methods: ['PUT'],
route: 'assistants/{assistantId}',
authLevel: 'anonymous',
extraOutputs: [chatBotCreateOutput],
handler: async (request, context) => {
const assistantId = request.params.assistantId
const instructions =
`
Don't make assumptions about what values to plug into functions.
Ask for clarification if a user request is ambiguous.
`
const createRequest = {
id: assistantId,
instructions: instructions,
chatStorageConnectionSetting: CHAT_STORAGE_CONNECTION_SETTING,
collectionName: COLLECTION_NAME
}
context.extraOutputs.set(chatBotCreateOutput, createRequest)
return { status: 202, jsonBody: { assistantId: assistantId } }
}
})
import { HttpRequest, InvocationContext, app, input, output } from "@azure/functions"
const CHAT_STORAGE_CONNECTION_SETTING = "AzureWebJobsStorage";
const COLLECTION_NAME = "ChatState";
const chatBotCreateOutput = output.generic({
type: 'assistantCreate'
})
app.http('CreateAssistant', {
methods: ['PUT'],
route: 'assistants/{assistantId}',
authLevel: 'anonymous',
extraOutputs: [chatBotCreateOutput],
handler: async (request: HttpRequest, context: InvocationContext) => {
const assistantId = request.params.assistantId
const instructions =
`
Don't make assumptions about what values to plug into functions.
Ask for clarification if a user request is ambiguous.
`
const createRequest = {
id: assistantId,
instructions: instructions,
chatStorageConnectionSetting: CHAT_STORAGE_CONNECTION_SETTING,
collectionName: COLLECTION_NAME
}
context.extraOutputs.set(chatBotCreateOutput, createRequest)
return { status: 202, jsonBody: { assistantId: assistantId } }
}
})
In questo esempio viene illustrato il processo di creazione, in cui la funzione HTTP PUT che crea un nuovo chatbot assistente con l'ID specificato. La risposta alla richiesta viene restituita nella risposta HTTP.
Ecco il file function.json per l'Assistente creazione:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"route": "assistants/{assistantId}",
"methods": [
"put"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
},
{
"type": "assistantCreate",
"direction": "out",
"dataType": "string",
"name": "Requests"
}
]
}
Per altre informazioni sulle proprietà dei file function.json, vedere la sezione configurazione.
{{Deriva dal commento del codice di esempio}}
using namespace System.Net
param($Request, $TriggerMetadata)
$assistantId = $Request.params.assistantId
$instructions = "Don't make assumptions about what values to plug into functions."
$instructions += "\nAsk for clarification if a user request is ambiguous."
$create_request = @{
"id" = $assistantId
"instructions" = $instructions
"chatStorageConnectionSetting" = "AzureWebJobsStorage"
"collectionName" = "ChatState"
}
Push-OutputBinding -Name Requests -Value (ConvertTo-Json $create_request)
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::Accepted
Body = (ConvertTo-Json @{ "assistantId" = $assistantId})
Headers = @{
"Content-Type" = "application/json"
}
})
In questo esempio viene illustrato il processo di creazione, in cui la funzione HTTP PUT che crea un nuovo chatbot assistente con l'ID specificato. La risposta alla richiesta viene restituita nella risposta HTTP.
DEFAULT_CHAT_STORAGE_SETTING = "AzureWebJobsStorage"
DEFAULT_CHAT_COLLECTION_NAME = "ChatState"
@apis.function_name("CreateAssistant")
@apis.route(route="assistants/{assistantId}", methods=["PUT"])
@apis.assistant_create_output(arg_name="requests")
def create_assistant(
req: func.HttpRequest, requests: func.Out[str]
) -> func.HttpResponse:
assistantId = req.route_params.get("assistantId")
instructions = """
Don't make assumptions about what values to plug into functions.
Ask for clarification if a user request is ambiguous.
"""
create_request = {
"id": assistantId,
"instructions": instructions,
"chatStorageConnectionSetting": DEFAULT_CHAT_STORAGE_SETTING,
"collectionName": DEFAULT_CHAT_COLLECTION_NAME,
}
requests.set(json.dumps(create_request))
response_json = {"assistantId": assistantId}
return func.HttpResponse(
json.dumps(response_json), status_code=202, mimetype="application/json"
)
Attributi
Applicare l'attributo CreateAssistant per definire un'associazione di output creata dall'assistente, che supporta questi parametri:
| Parametro | Descrizione |
|---|---|
| id | Identificatore dell'assistente da creare. |
| Istruzioni | Facoltativo. Le istruzioni fornite per l'assistente da seguire. |
| ChatStorageConnectionSetting |
Facoltativo. Nome della sezione di configurazione per le impostazioni della tabella per l'archiviazione chat. Il valore predefinito è AzureWebJobsStorage. |
| CollectionName |
Facoltativo. Nome della raccolta di tabelle per l'archiviazione chat. Il valore predefinito è ChatState. |
Annotazioni
L'annotazione CreateAssistant consente di definire un'associazione di output creata dall'assistente, che supporta questi parametri:
| Elemento | Descrizione |
|---|---|
| nome | Ottiene o imposta il nome dell'associazione di output. |
| ID | Identificatore dell'assistente da creare. |
| istruzioni | Facoltativo. Le istruzioni fornite per l'assistente da seguire. |
| chatStorageConnectionSetting |
Facoltativo. Nome della sezione di configurazione per le impostazioni della tabella per l'archiviazione chat. Il valore predefinito è AzureWebJobsStorage. |
| collectionName |
Facoltativo. Nome della raccolta di tabelle per l'archiviazione chat. Il valore predefinito è ChatState. |
Elementi Decorator
Durante l'anteprima, definire l'associazione di output come associazione generic_output_binding di tipo createAssistant, che supporta questi parametri:
| Parametro | Descrizione |
|---|---|
| arg_name | Nome della variabile che rappresenta il parametro di associazione. |
| ID | Identificatore dell'assistente da creare. |
| istruzioni | Facoltativo. Le istruzioni fornite per l'assistente da seguire. |
| chat_storage_connection_setting |
Facoltativo. Nome della sezione di configurazione per le impostazioni della tabella per l'archiviazione chat. Il valore predefinito è AzureWebJobsStorage. |
| collection_name |
Facoltativo. Nome della raccolta di tabelle per l'archiviazione chat. Il valore predefinito è ChatState. |
Impostazione
L'associazione supporta queste proprietà di configurazione impostate nel file function.json.
| Proprietà | Descrizione |
|---|---|
| tipo | Deve essere CreateAssistant. |
| direzione | Deve essere out. |
| nome | Nome dell'associazione di output. |
| ID | Identificatore dell'assistente da creare. |
| istruzioni | Facoltativo. Le istruzioni fornite per l'assistente da seguire. |
| chatStorageConnectionSetting |
Facoltativo. Nome della sezione di configurazione per le impostazioni della tabella per l'archiviazione chat. Il valore predefinito è AzureWebJobsStorage. |
| collectionName |
Facoltativo. Nome della raccolta di tabelle per l'archiviazione chat. Il valore predefinito è ChatState. |
Impostazione
Il binding supporta queste proprietà, definite nel codice:
| Proprietà | Descrizione |
|---|---|
| ID | Identificatore dell'assistente da creare. |
| istruzioni | Facoltativo. Le istruzioni fornite per l'assistente da seguire. |
| chatStorageConnectionSetting |
Facoltativo. Nome della sezione di configurazione per le impostazioni della tabella per l'archiviazione chat. Il valore predefinito è AzureWebJobsStorage. |
| collectionName |
Facoltativo. Nome della raccolta di tabelle per l'archiviazione chat. Il valore predefinito è ChatState. |
Utilizzo
Per esempi completi, vedere la sezione di esempio.