Skip to content

Commit

Permalink
Revert "Fix issue with resource reference types"
Browse files Browse the repository at this point in the history
This reverts commit 0bcaa4b.
  • Loading branch information
ciprianjichici committed Sep 18, 2024
1 parent 0bcaa4b commit 832a7f6
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 650 deletions.
2 changes: 1 addition & 1 deletion src/dotnet/AIModel/Models/AIModelReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AIModelReference : ResourceReference
/// The object type of the data source.
/// </summary>
[JsonIgnore]
public override Type ResourceType =>
public Type AIModelType =>
Type switch
{
AIModelTypes.Basic => typeof(AIModelBase),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private async Task<ResourceProviderUpsertResult> UpdateAIModel(ResourcePath reso

aiModel.ObjectId = resourcePath.GetObjectId(_instanceSettings.Id, _name);

var validator = _resourceValidatorFactory.GetValidator(aiModelReference.ResourceType);
var validator = _resourceValidatorFactory.GetValidator(aiModelReference.AIModelType);
if (validator is IValidator aiModelValidator)
{
var context = new ValidationContext<object>(aiModel);
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/Agent/Models/Resources/AgentReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AgentReference : ResourceReference
/// The object type of the agent.
/// </summary>
[JsonIgnore]
public override Type ResourceType =>
public Type AgentType =>
Type switch
{
AgentTypes.Basic => typeof(AgentBase),
Expand Down
31 changes: 31 additions & 0 deletions src/dotnet/Agent/Models/Resources/AgentReferenceStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace FoundationaLLM.Agent.Models.Resources
{
/// <summary>
/// Models the content of the agent reference store managed by the FoundationaLLM.Agent resource provider.
/// </summary>
public class AgentReferenceStore
{
/// <summary>
/// The list of all agents registered in the system.
/// </summary>
public required List<AgentReference> AgentReferences { get; set; }

/// <summary>
/// Creates a string-based dictionary of <see cref="AgentReference"/> values from the current object.
/// </summary>
/// <returns>The string-based dictionary of <see cref="AgentReference"/> values from the current object.</returns>
public Dictionary<string, AgentReference> ToDictionary() =>
AgentReferences.ToDictionary<AgentReference, string>(ar => ar.Name);

/// <summary>
/// Creates a new instance of the <see cref="AgentReferenceStore"/> from a dictionary.
/// </summary>
/// <param name="dictionary">A string-based dictionary of <see cref="AgentReference"/> values.</param>
/// <returns>The <see cref="AgentReferenceStore"/> object created from the dictionary.</returns>
public static AgentReferenceStore FromDictionary(Dictionary<string, AgentReference> dictionary) =>
new()
{
AgentReferences = [.. dictionary.Values]
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private async Task<ResourceProviderUpsertResult> UpdateAgent(ResourcePath resour
StatusCodes.Status500InternalServerError);
}

var validator = _resourceValidatorFactory.GetValidator(agentReference.ResourceType);
var validator = _resourceValidatorFactory.GetValidator(agentReference.AgentType);
if (validator is IValidator agentValidator)
{
var context = new ValidationContext<object>(agent);
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/DataSource/Models/DataSourceReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DataSourceReference : ResourceReference
/// The object type of the data source.
/// </summary>
[JsonIgnore]
public override Type ResourceType =>
public Type DataSourceType =>
Type switch
{
DataSourceTypes.Basic => typeof(DataSourceBase),
Expand Down
35 changes: 35 additions & 0 deletions src/dotnet/DataSource/Models/DataSourceReferenceStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace FoundationaLLM.DataSource.Models
{
/// <summary>
/// Models the content of the data source reference store managed by the FoundationaLLM.DataSource resource provider.
/// </summary>
public class DataSourceReferenceStore
{
/// <summary>
/// The list of all data sources registered in the system.
/// </summary>
public required List<DataSourceReference> DataSourceReferences { get; set; }
/// <summary>
/// The name of the default data source.
/// </summary>
public string? DefaultDataSourceName { get; set; }

/// <summary>
/// Creates a string-based dictionary of <see cref="DataSourceReference"/> values from the current object.
/// </summary>
/// <returns>The string-based dictionary of <see cref="DataSourceReference"/> values from the current object.</returns>
public Dictionary<string, DataSourceReference> ToDictionary() =>
DataSourceReferences.ToDictionary<DataSourceReference, string>(ar => ar.Name);

/// <summary>
/// Creates a new instance of the <see cref="DataSourceReferenceStore"/> from a dictionary.
/// </summary>
/// <param name="dictionary">A string-based dictionary of <see cref="DataSourceReference"/> values.</param>
/// <returns>The <see cref="DataSourceReferenceStore"/> object created from the dictionary.</returns>
public static DataSourceReferenceStore FromDictionary(Dictionary<string, DataSourceReference> dictionary) =>
new()
{
DataSourceReferences = [.. dictionary.Values]
};
}
}
Loading

0 comments on commit 832a7f6

Please sign in to comment.