Skip to content

Commit

Permalink
.Net - Updated Open AI Assistant Model Serialization (#5102)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Certain model properties not serializing properly due to definition
alignment.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

`Agent === Assistant` when dealing with Open AI models.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com>
  • Loading branch information
crickman and markwallace-microsoft committed Feb 21, 2024
1 parent 6954e97 commit 1f731ca
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/Experimental/Agents/Internal/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal ChatMessage(ThreadMessageModel model)
this.Annotations = content.Text!.Annotations.Select(a => new Annotation(a.Text, a.StartIndex, a.EndIndex, a.FileCitation?.FileId ?? a.FilePath!.FileId, a.FileCitation?.Quote)).ToArray();

this.Id = model.Id;
this.AgentId = string.IsNullOrWhiteSpace(model.AgentId) ? null : model.AgentId;
this.AgentId = string.IsNullOrWhiteSpace(model.AssistantId) ? null : model.AssistantId;
this.Role = model.Role;
this.Content = text;
this.Properties = new ReadOnlyDictionary<string, object>(model.Metadata);
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Experimental/Agents/Internal/ChatRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class ChatRun
public string Id => this._model.Id;

/// <inheritdoc/>
public string AgentId => this._model.AgentId;
public string AgentId => this._model.AssistantId;

/// <inheritdoc/>
public string ThreadId => this._model.ThreadId;
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/Experimental/Agents/Models/ThreadMessageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal sealed class ThreadMessageModel
public string ThreadId { get; set; } = string.Empty;

/// <summary>
/// The entity that produced the message. One of "user" or "agent".
/// The entity that produced the message. One of "user" or "assistant".
/// </summary>
[JsonPropertyName("role")]
public string Role { get; set; } = string.Empty;
Expand All @@ -57,10 +57,10 @@ internal sealed class ThreadMessageModel
public List<string> FileIds { get; set; } = new List<string>();

/// <summary>
/// If applicable, the ID of the agent that authored this message.
/// If applicable, the ID of the assistant that authored this message.
/// </summary>
[JsonPropertyName("agent_id")]
public string AgentId { get; set; } = string.Empty;
[JsonPropertyName("assistant_id")]
public string AssistantId { get; set; } = string.Empty;

/// <summary>
/// If applicable, the ID of the run associated with the authoring of this message.
Expand Down
14 changes: 7 additions & 7 deletions dotnet/src/Experimental/Agents/Models/ThreadRunModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ internal sealed class ThreadRunModel
public long CreatedAt { get; set; }

/// <summary>
/// ID of the agent used for execution of this run.
/// ID of the assistant used for execution of this run.
/// </summary>
[JsonPropertyName("agent_id")]
public string AgentId { get; set; } = string.Empty;
[JsonPropertyName("assistant_id")]
public string AssistantId { get; set; } = string.Empty;

/// <summary>
/// ID of the thread that was executed on as a part of this run.
Expand Down Expand Up @@ -79,25 +79,25 @@ internal sealed class ThreadRunModel
public ErrorModel? LastError { get; set; }

/// <summary>
/// The model that the agent used for this run.
/// The model that the assistant used for this run.
/// </summary>
[JsonPropertyName("model")]
public string Model { get; set; } = string.Empty;

/// <summary>
/// The instructions that the agent used for this run.
/// The instructions that the assistant used for this run.
/// </summary>
[JsonPropertyName("instructions")]
public string Instructions { get; set; } = string.Empty;

/// <summary>
/// The list of tools that the agent used for this run.
/// The list of tools that the assistant used for this run.
/// </summary>
[JsonPropertyName("tools")]
public List<ToolModel> Tools { get; set; } = new List<ToolModel>();

/// <summary>
/// The list of File IDs the agent used for this run.
/// The list of File IDs the assistant used for this run.
/// </summary>
[JsonPropertyName("file_ids")]
public List<string> FileIds { get; set; } = new List<string>();
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/Experimental/Agents/Models/ThreadRunStepModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ internal sealed class ThreadRunStepModel
public string RunId { get; set; } = string.Empty;

/// <summary>
/// ID of the agent associated with the run step.
/// ID of the assistant associated with the run step.
/// </summary>
[JsonPropertyName("agent_id")]
public string AgentId { get; set; } = string.Empty;
[JsonPropertyName("assistant_id")]
public string AssistantId { get; set; } = string.Empty;

/// <summary>
/// The ID of the thread to which the run and run step belongs.
Expand Down

0 comments on commit 1f731ca

Please sign in to comment.