Partilhar via


Guia de Migração do Plug-in Python para Sessões - maio de 2025

O SessionsPythonPlugin foi atualizado para usar a versão mais recente (2024-10-02-preview) da API de Sessões Dinâmicas do Azure Code Interpreter. A nova API introduziu alterações disruptivas, que são refletidas na interface pública da API do plugin.

Este guia de migração irá ajudá-lo a migrar o seu código existente para a versão mais recente do plugin.

A inicialização do plugin

A assinatura do construtor do plugin foi alterada para aceitar a CancellationToken como um argumento para a authTokenProvider função. Essa alteração permite cancelar o processo de geração de tokens, se necessário:

// Before
static async Task<string> GetAuthTokenAsync()
{
    return tokenProvider.GetToken();
}

// After
static async Task<string> GetAuthTokenAsync(CancellationToken ct)
{
    return tokenProvider.GetToken(ct);
}

var plugin = new SessionsPythonPlugin(settings, httpClientFactory, GetAuthTokenAsync);

O método UploadFileAsync

A UploadFileAsync assinatura do método foi alterada para representar melhor a finalidade dos parâmetros:

// Before
string remoteFilePath = "your_file.txt";
string? localFilePath = "C:\documents\your_file.txt";

await plugin.UploadFileAsync(remoteFilePath: remoteFilePath, localFilePath: localFilePath);

// After
string remoteFileName = "your_file.txt";
string localFilePath = "C:\documents\your_file.txt";

await plugin.UploadFileAsync(remoteFileName: remoteFileName, localFilePath: localFilePath);

O método DownloadFileAsync

Da mesma forma, a assinatura do DownloadFileAsync método foi alterada para representar melhor a finalidade dos parâmetros:

// Before
string remoteFilePath = "your_file.txt";
await plugin.DownloadFileAsync(remoteFilePath: remoteFilePath);

// After
string remoteFileName = "your_file.txt";
await plugin.DownloadFileAsync(remoteFileName: remoteFileName);

O método ExecuteCodeAsync

A ExecuteCodeAsync assinatura do método foi alterada para fornecer uma maneira estruturada de trabalhar com resultados de execução:

// Before
string result = await plugin.ExecuteCodeAsync(code: "print('Hello, world!')");

// After
SessionsPythonCodeExecutionResult result = await plugin.ExecuteCodeAsync(code: "print('Hello, world!')");
string status = result.Status;
string? executionResult = result.Result?.ExecutionResult;
string? stdout = result.Result?.StdOut;
string? stderr = result.Result?.StdErr;

A classe SessionsRemoteFileMetadata

A SessionsRemoteFileMetadata classe de modelo, usada pelos UploadFileAsync métodos and ListFilesAsync , foi atualizada para representar melhor os metadados de arquivos e diretórios remotos:

// Before
SessionsRemoteFileMetadata file = await plugin.UploadFileAsync(...);
string fileName = file.Filename;
long fileSize = file.Size;
DateTime? lastModified = file.LastModifiedTime;

// After
SessionsRemoteFileMetadata file = await plugin.UploadFileAsync(...);
string name = file.Name;
long? size = file.SizeInBytes;
DateTime lastModified = file.LastModifiedAt;