-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge sc-agent-workflow-and-tools-options into sc-basic-models-and-en…
…dpoints-ui
- Loading branch information
Showing
64 changed files
with
1,890 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
{ | ||
"telemetry_activity_source": "CoreAPI", | ||
"telemetry_activities": [ | ||
{ | ||
"name": "AsyncCompletions_StartCompletionOperation" | ||
}, | ||
{ | ||
"name": "Completions_GetCompletion" | ||
} | ||
] | ||
} | ||
] |
33 changes: 33 additions & 0 deletions
33
src/dotnet/Common/Constants/Telemetry/TelemetryActivityTagNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace FoundationaLLM.Common.Constants.Telemetry | ||
{ | ||
/// <summary> | ||
/// Provides the names of the tags used in telemetry activities. | ||
/// </summary> | ||
public static class TelemetryActivityTagNames | ||
{ | ||
/// <summary> | ||
/// The FoundationaLLM instance identifier tag. | ||
/// </summary> | ||
public const string InstanceId = "FoundationaLLM-InstanceId"; | ||
|
||
/// <summary> | ||
/// The FoundationaLLM conversation identifier tag. | ||
/// </summary> | ||
public const string ConversationId = "FoundationaLLM-ConversationId"; | ||
|
||
/// <summary> | ||
/// The FoundationaLLM operation identifier tag. | ||
/// </summary> | ||
public const string OperationId = "FoundationaLLM-OperationId"; | ||
|
||
/// <summary> | ||
/// The FoundationaLLM user principal name tag. | ||
/// </summary> | ||
public const string UPN = "FoundationaLLM-UPN"; | ||
|
||
/// <summary> | ||
/// The FoundationaLLM user identifier tag. | ||
/// </summary> | ||
public const string UserId = "FoundationaLLM-UserId"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/dotnet/Common/Interfaces/IResourceProviderResourceCacheService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using FoundationaLLM.Common.Models.ResourceProviders; | ||
|
||
namespace FoundationaLLM.Common.Interfaces | ||
{ | ||
/// <summary> | ||
/// Provides the resource caching services used by FoundationaLLM resource providers. | ||
/// </summary> | ||
public interface IResourceProviderResourceCacheService | ||
{ | ||
/// <summary> | ||
/// Tries to get a resource value identified by a resource reference from the cache. | ||
/// </summary> | ||
/// <typeparam name="T">The type of resource value to be retrieved.</typeparam> | ||
/// <param name="resourceReference">The <see cref="ResourceReference"/> used as a key in the cache.</param> | ||
/// <param name="resourceValue">The resource value to be retrieved.</param> | ||
/// <returns><see langword="true"/> is the resource value was found in the cache, <see langword="false"/> otherwise.</returns> | ||
bool TryGetValue<T>(ResourceReference resourceReference, out T? resourceValue) where T: ResourceBase; | ||
|
||
/// <summary> | ||
/// Sets a resource value identified by a resource reference in the cache. | ||
/// </summary> | ||
/// <typeparam name="T">The type of resource value to be set.</typeparam> | ||
/// <param name="resourceReference">The <see cref="ResourceReference"/> used as a key in the cache.</param> | ||
/// <param name="resourceValue">The resource value to be set.</param> | ||
void SetValue<T>(ResourceReference resourceReference, T resourceValue) where T : ResourceBase; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/dotnet/Common/Services/ResourceProviders/ResourceProviderResourceCacheService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using FoundationaLLM.Common.Interfaces; | ||
using FoundationaLLM.Common.Models.ResourceProviders; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace FoundationaLLM.Common.Services.ResourceProviders | ||
{ | ||
/// <summary> | ||
/// Provides the resource caching services used by FoundationaLLM resource providers. | ||
/// </summary> | ||
/// <param name="logger">The <see cref="ILogger"/> used to log information.</param> | ||
public class ResourceProviderResourceCacheService( | ||
ILogger logger) : IResourceProviderResourceCacheService | ||
{ | ||
private readonly ILogger _logger = logger; | ||
|
||
private readonly IMemoryCache _cache = new MemoryCache(new MemoryCacheOptions | ||
{ | ||
SizeLimit = 10000, // Limit cache size to 5000 resources. | ||
ExpirationScanFrequency = TimeSpan.FromMinutes(5) // Scan for expired items every five minutes. | ||
}); | ||
private readonly MemoryCacheEntryOptions _cacheEntryOptions = new MemoryCacheEntryOptions() | ||
.SetAbsoluteExpiration(TimeSpan.FromMinutes(60)) // Cache entries are valid for 60 minutes. | ||
.SetSlidingExpiration(TimeSpan.FromMinutes(30)) // Reset expiration time if accessed within 5 minutes. | ||
.SetSize(1); // Each cache entry is a single resource. | ||
|
||
/// <inheritdoc/> | ||
public void SetValue<T>(ResourceReference resourceReference, T resourceValue) where T : ResourceBase | ||
{ | ||
try | ||
{ | ||
_cache.Set<T>(GetCacheKey(resourceReference), resourceValue, _cacheEntryOptions); | ||
_logger.LogInformation("The resource {ResourceName} of type {ResourceType} has been set in the cache.", | ||
resourceReference.Name, | ||
resourceReference.Type); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, "There was an error setting the resource {ResourceName} of type {ResourceType} in the cache.", | ||
resourceReference.Name, | ||
resourceReference.Type); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool TryGetValue<T>(ResourceReference resourceReference, out T? resourceValue) where T : ResourceBase | ||
{ | ||
resourceValue = default; | ||
|
||
try | ||
{ | ||
if (_cache.TryGetValue<T>(GetCacheKey(resourceReference), out T? cachedValue) | ||
&& cachedValue != null) | ||
{ | ||
resourceValue = cachedValue; | ||
_logger.LogInformation("The resource {ResourceName} of type {ResourceType} has been retrieved from the cache.", | ||
resourceReference.Name, | ||
resourceReference.Type); | ||
return true; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, "There was an error getting the resource {ResourceName} of type {ResourceType} from the cache.", | ||
resourceReference.Name, | ||
resourceReference.Type); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private string GetCacheKey(ResourceReference resourceReference) => | ||
$"{resourceReference.Type}|{resourceReference.Name}"; | ||
} | ||
} |
Oops, something went wrong.