Skip to content

Commit

Permalink
.Net Add version to CodeInterpreter API Calls (#6666)
Browse files Browse the repository at this point in the history
### Motivation and Context

Resolves #6510
  • Loading branch information
RogerBarreto committed Jun 11, 2024
1 parent a2720a6 commit dd7236e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 18 additions & 0 deletions dotnet/samples/Demos/CodeInterpreterPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ OpenAI__ChatModelId
# Azure Container Apps
AzureContainerApps__Endpoint
```

### Usage Example

User: Upload the file c:\temp\code-interpreter\test-file.txt

Assistant: The file test-file.txt has been successfully uploaded.

User: How many files I have uploaded ?

Assistant: You have uploaded 1 file.

User: Show me the contents of this file

Assistant: The contents of the file "test-file.txt" are as follows:

```text
the contents of the file
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.SemanticKernel.Plugins.Core.CodeInterpreter;
public partial class SessionsPythonPlugin
{
private static readonly string s_assemblyVersion = typeof(Kernel).Assembly.GetName().Version!.ToString();

private const string ApiVersion = "2024-02-02-preview";
private readonly Uri _poolManagementEndpoint;
private readonly SessionsPythonSettings _settings;
private readonly Func<Task<string>>? _authTokenProvider;
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task<string> ExecuteCodeAsync([Description("The valid Python code t

await this.AddHeadersAsync(httpClient).ConfigureAwait(false);

using var request = new HttpRequestMessage(HttpMethod.Post, this._poolManagementEndpoint + "python/execute")
using var request = new HttpRequestMessage(HttpMethod.Post, this._poolManagementEndpoint + $"python/execute?api-version={ApiVersion}")
{
Content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, "application/json")
};
Expand Down Expand Up @@ -155,7 +155,7 @@ private async Task AddHeadersAsync(HttpClient httpClient)
await this.AddHeadersAsync(httpClient).ConfigureAwait(false);

using var fileContent = new ByteArrayContent(File.ReadAllBytes(localFilePath));
using var request = new HttpRequestMessage(HttpMethod.Post, $"{this._poolManagementEndpoint}python/uploadFile?identifier={this._settings.SessionId}")
using var request = new HttpRequestMessage(HttpMethod.Post, $"{this._poolManagementEndpoint}python/uploadFile?identifier={this._settings.SessionId}&api-version={ApiVersion}")
{
Content = new MultipartFormDataContent
{
Expand Down Expand Up @@ -194,7 +194,7 @@ private async Task AddHeadersAsync(HttpClient httpClient)
using var httpClient = this._httpClientFactory.CreateClient();
await this.AddHeadersAsync(httpClient).ConfigureAwait(false);

var response = await httpClient.GetAsync(new Uri($"{this._poolManagementEndpoint}python/downloadFile?identifier={this._settings.SessionId}&filename={remoteFilePath}")).ConfigureAwait(false);
var response = await httpClient.GetAsync(new Uri($"{this._poolManagementEndpoint}python/downloadFile?identifier={this._settings.SessionId}&filename={remoteFilePath}&api-version={ApiVersion}")).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
var errorBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -230,7 +230,7 @@ public async Task<IReadOnlyList<SessionsRemoteFileMetadata>> ListFilesAsync()
using var httpClient = this._httpClientFactory.CreateClient();
await this.AddHeadersAsync(httpClient).ConfigureAwait(false);

var response = await httpClient.GetAsync(new Uri($"{this._poolManagementEndpoint}python/files?identifier={this._settings.SessionId}")).ConfigureAwait(false);
var response = await httpClient.GetAsync(new Uri($"{this._poolManagementEndpoint}python/files?identifier={this._settings.SessionId}&api-version={ApiVersion}")).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
Expand Down

0 comments on commit dd7236e

Please sign in to comment.