Table of Contents

Class CoreService

Namespace
FoundationaLLM.Core.Services
Assembly
FoundationaLLM.Core.dll

Initializes a new instance of the CoreService class.

public class CoreService : ICoreService
Inheritance
CoreService
Implements
Inherited Members
Extension Methods

Constructors

CoreService(IAzureCosmosDBService, IEnumerable<IDownstreamAPIService>, ILogger<CoreService>, IOptions<ClientBrandingConfiguration>, IOptions<CoreServiceSettings>, IOrchestrationContext, IEnumerable<IResourceProviderService>, IConfiguration, IHttpClientFactoryService, IContextServiceClient)

Initializes a new instance of the CoreService class.

public CoreService(IAzureCosmosDBService cosmosDBService, IEnumerable<IDownstreamAPIService> downstreamAPIServices, ILogger<CoreService> logger, IOptions<ClientBrandingConfiguration> brandingSettings, IOptions<CoreServiceSettings> settings, IOrchestrationContext callContext, IEnumerable<IResourceProviderService> resourceProviderServices, IConfiguration configuration, IHttpClientFactoryService httpClientFactory, IContextServiceClient contextServiceClient)

Parameters

cosmosDBService IAzureCosmosDBService

The Azure Cosmos DB service that contains chat sessions and messages.

downstreamAPIServices IEnumerable<IDownstreamAPIService>

The services used to make calls to the downstream APIs.

logger ILogger<CoreService>

The logging interface used to log under the CoreService type name.

brandingSettings IOptions<ClientBrandingConfiguration>

The ClientBrandingConfiguration settings retrieved by the injected IOptions<TOptions>.

settings IOptions<CoreServiceSettings>

The CoreServiceSettings settings for the service.

callContext IOrchestrationContext

Contains contextual data for the calling service.

resourceProviderServices IEnumerable<IResourceProviderService>

A dictionary of IResourceProviderService resource providers hashed by resource provider name.

configuration IConfiguration

The IConfiguration service providing configuration settings.

httpClientFactory IHttpClientFactoryService

The IHttpClientFactory used to build HTTP clients.

contextServiceClient IContextServiceClient

The IContextServiceClient used to interact with the Context API.

Methods

CreateConversationAsync(string, ChatSessionProperties)

Creates a new chat session.

public Task<Conversation> CreateConversationAsync(string instanceId, ChatSessionProperties chatSessionProperties)

Parameters

instanceId string

The instance Id.

chatSessionProperties ChatSessionProperties

The session properties.

Returns

Task<Conversation>

DeleteAttachments(string, List<string>, UnifiedUserIdentity)

Deletes one or more attachments.

public Task<Dictionary<string, ResourceProviderDeleteResult?>> DeleteAttachments(string instanceId, List<string> resourcePaths, UnifiedUserIdentity userIdentity)

Parameters

instanceId string

The FoundationaLLM instance id.

resourcePaths List<string>

The list of resources to be deleted.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity providing information about the calling user identity.

Returns

Task<Dictionary<string, ResourceProviderDeleteResult>>

A dictionary with the delete operation result for each resource path.

DeleteConversationAsync(string, string)

Delete a chat session and related messages.

public Task DeleteConversationAsync(string instanceId, string sessionId)

Parameters

instanceId string

The instance id.

sessionId string

The session id to delete.

Returns

Task

DownloadAttachment(string, string, string, UnifiedUserIdentity)

Downloads an attachment.

public Task<AttachmentFile?> DownloadAttachment(string instanceId, string fileProvider, string fileId, UnifiedUserIdentity userIdentity)

Parameters

instanceId string

The FoundationaLLM instance id.

fileProvider string

The name of the file provider.

fileId string

The identifier of the file.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity providing information about the calling user identity.

Returns

Task<AttachmentFile>

An AttachmentFile object with the properties and the content of the attachment.

Remarks

The following file providers are supported:

  • FoundationaLLM.Attachments
  • FoundationaLLM.AzureOpenAI

GetAllConversationsAsync(string)

Returns list of chat session ids and names.

public Task<List<Conversation>> GetAllConversationsAsync(string instanceId)

Parameters

instanceId string

The instance id for which to retrieve chat sessions.

Returns

Task<List<Conversation>>

GetChatCompletionAsync(string, CompletionRequest)

Receive a prompt from a user, retrieve the message history from the related session, generate a completion response, and log full completion results.

public Task<Message> GetChatCompletionAsync(string instanceId, CompletionRequest completionRequest)

Parameters

instanceId string

The instance id.

completionRequest CompletionRequest

The completion request.

Returns

Task<Message>

GetChatSessionMessagesAsync(string, string)

Returns the chat messages related to an existing session.

public Task<List<Message>> GetChatSessionMessagesAsync(string instanceId, string sessionId)

Parameters

instanceId string

The instance id for which to retrieve chat messages.

sessionId string

The session id for which to retrieve chat messages.

Returns

Task<List<Message>>

GetCompletionAsync(string, CompletionRequest)

Provides a completion for a user prompt, without a session.

public Task<Message> GetCompletionAsync(string instanceId, CompletionRequest directCompletionRequest)

Parameters

instanceId string

The instance id.

directCompletionRequest CompletionRequest

The completion request.

Returns

Task<Message>

GetCompletionOperationStatus(string, string)

Gets the status of a completion operation.

public Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId)

Parameters

instanceId string

The FoundationaLLM instance id.

operationId string

The OperationId for which to retrieve the status.

Returns

Task<LongRunningOperation>

Returns a LongRunningOperation object containing the OperationId, Status, and result.

GetCompletionPrompt(string, string, string)

Returns the completion prompt for a given session and completion prompt id.

public Task<CompletionPrompt> GetCompletionPrompt(string instanceId, string sessionId, string completionPromptId)

Parameters

instanceId string

The instance Id.

sessionId string

The session id from which to retrieve the completion prompt.

completionPromptId string

The id of the completion prompt to retrieve.

Returns

Task<CompletionPrompt>

GetCoreConfiguration(string, UnifiedUserIdentity)

Gets the file store configuration for the given instance.

public Task<CoreConfiguration> GetCoreConfiguration(string instanceId, UnifiedUserIdentity userIdentity)

Parameters

instanceId string

The FoundationaLLM instance id.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity providing information about the calling user identity.

Returns

Task<CoreConfiguration>

The file store configuration.

RateMessageAsync(string, string, string, MessageRatingRequest)

Rate an assistant message. This can be used to discover useful AI responses for training, discoverability, and other benefits down the road.

public Task RateMessageAsync(string instanceId, string id, string sessionId, MessageRatingRequest rating)

Parameters

instanceId string

The instance id.

id string

The message id to rate.

sessionId string

The session id to which the message belongs.

rating MessageRatingRequest

The rating and optional comments to assign to the message.

Returns

Task

RenameConversationAsync(string, string, ChatSessionProperties)

Rename the chat session from its default (eg., "New Chat") to the summary provided by OpenAI.

public Task<Conversation> RenameConversationAsync(string instanceId, string sessionId, ChatSessionProperties chatSessionProperties)

Parameters

instanceId string

The instance id.

sessionId string

The session id to rename.

chatSessionProperties ChatSessionProperties

The session properties.

Returns

Task<Conversation>

StartCompletionOperation(string, CompletionRequest)

Begins a completion operation.

public Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest)

Parameters

instanceId string

The FoundationaLLM instance id.

completionRequest CompletionRequest

The completion request containing the user prompt and message history.

Returns

Task<LongRunningOperation>

Returns an LongRunningOperation object containing the OperationId and Status.

UploadAttachment(string, string, AttachmentFile, string, UnifiedUserIdentity)

Uploads an attachment.

public Task<ResourceProviderUpsertResult<AttachmentFile>> UploadAttachment(string instanceId, string sessionId, AttachmentFile attachmentFile, string agentName, UnifiedUserIdentity userIdentity)

Parameters

instanceId string

The FoundationaLLM instance id.

sessionId string

The session id from which the attachment is uploaded.

attachmentFile AttachmentFile

The AttachmentFile object containing the attachment file data.

agentName string

The name of the agent.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity providing information about the calling user identity.

Returns

Task<ResourceProviderUpsertResult<AttachmentFile>>

A ResourceProviderUpsertResult<T> object with the FoundationaLLM.Attachment resource provider object id.