Skip to content

Commit

Permalink
Merge pull request #1219 from solliancenet/jdh-long-running-ux
Browse files Browse the repository at this point in the history
Long-running agent requests from the User Portal & Core API updates
  • Loading branch information
ciprianjichici authored Jul 24, 2024
2 parents ccbb2d6 + 91c306e commit 0f3a154
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ log
**/vectorization-api-event-profile.json
**/vectorization-worker-event-profile.json
deploy/quick-start/.env
deploy/quick-start/tools
**/management-api-event-profile.json
**/testsettings.json

Expand Down
34 changes: 34 additions & 0 deletions src/dotnet/Common/Models/Orchestration/LongRunningOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Text.Json.Serialization;

namespace FoundationaLLM.Common.Models.Orchestration
{
/// <summary>
/// Represents the current state of a long-running operation.
/// </summary>
public class LongRunningOperation
{
/// <summary>
/// The identifier of the long-running operation.
/// </summary>
[JsonPropertyName("operation_id")]
public required string OperationId { get; set; }

/// <summary>
/// The status of the long-running operation.
/// </summary>
[JsonPropertyName("status")]
public required OperationStatus Status { get; set; }

/// <summary>
/// The message describing the current state of the operation.
/// </summary>
[JsonPropertyName("status_message")]
public string? StatusMessage { get; set; }

/// <summary>
/// The time stamp of the last update to the operation.
/// </summary>
[JsonPropertyName("last_updated")]
public DateTime? LastUpdated { get; set; }
}
}
23 changes: 0 additions & 23 deletions src/dotnet/Common/Models/Orchestration/OperationState.cs

This file was deleted.

24 changes: 24 additions & 0 deletions src/dotnet/Core/Interfaces/ICoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,28 @@ public interface ICoreService
/// <param name="completionPromptId">The id of the completion prompt to retrieve.</param>
/// <returns></returns>
Task<CompletionPrompt> GetCompletionPrompt(string instanceId, string sessionId, string completionPromptId);

/// <summary>
/// Begins a completion operation.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="completionRequest">The completion request containing the user prompt and message history.</param>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest);

/// <summary>
/// Gets the status of a completion operation.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The OperationId for which to retrieve the status.</param>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId);

/// <summary>
/// Gets a completion operation from the downstream API.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The ID of the operation to retrieve.</param>
/// <returns>Returns a <see cref="CompletionResponse" /> object.</returns>
Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId);
}
12 changes: 12 additions & 0 deletions src/dotnet/Core/Services/CoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public async Task<Completion> GetCompletionAsync(string instanceId, CompletionRe
}
}

/// <inheritdoc/>
public async Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest) =>
throw new NotImplementedException();

/// <inheritdoc/>
public Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId) =>
throw new NotImplementedException();

/// <inheritdoc/>
public async Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId) =>
throw new NotImplementedException();

/// <inheritdoc/>
public async Task<Completion> GenerateChatSessionNameAsync(string instanceId, string? sessionId, string? text)
{
Expand Down
39 changes: 36 additions & 3 deletions src/dotnet/CoreAPI/Controllers/CompletionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace FoundationaLLM.Core.API.Controllers
/// </remarks>
[Authorize(Policy = "DefaultPolicy")]
[ApiController]
[Route("instances/{instanceId}/[controller]")]
[Route("instances/{instanceId}")]
public class CompletionsController : ControllerBase
{
private readonly ICoreService _coreService;
Expand Down Expand Up @@ -60,17 +60,50 @@ public CompletionsController(ICoreService coreService,
/// </summary>
/// <param name="instanceId">The instance ID of the current request.</param>
/// <param name="completionRequest">The user prompt for which to generate a completion.</param>
[HttpPost(Name = "GetCompletion")]
[HttpPost("completions", Name = "GetCompletion")]
public async Task<IActionResult> GetCompletion(string instanceId, [FromBody] CompletionRequest completionRequest) =>
!string.IsNullOrWhiteSpace(completionRequest.SessionId) ? Ok(await _coreService.GetChatCompletionAsync(instanceId, completionRequest)) :
Ok(await _coreService.GetCompletionAsync(instanceId, completionRequest));

/// <summary>
/// Begins a completion operation.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="completionRequest">The completion request containing the user prompt and message history.</param>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
[HttpPost("async-completions")]
public async Task<ActionResult<LongRunningOperation>> StartCompletionOperation(string instanceId, CompletionRequest completionRequest)
{
var state = await _coreService.StartCompletionOperation(instanceId, completionRequest);
return Accepted(state);
}

/// <summary>
/// Gets the status of a completion operation.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The OperationId for which to retrieve the status.</param>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
[HttpGet("async-completions/{operationId}/status")]
public async Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId) =>
await _coreService.GetCompletionOperationStatus(instanceId, operationId);

/// <summary>
/// Gets a completion operation from the downstream APIs.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The ID of the operation to retrieve.</param>
/// <returns>Returns a completion response</returns>
[HttpGet("async-completions/{operationId}/result")]
public async Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId) =>
await _coreService.GetCompletionOperationResult(instanceId, operationId);

/// <summary>
/// Retrieves a list of global and private agents.
/// </summary>
/// <param name="instanceId">The instance ID of the current request.</param>
/// <returns>A list of available agents.</returns>
[HttpGet("agents", Name = "GetAgents")]
[HttpGet("completions/agents", Name = "GetAgents")]
public async Task<IEnumerable<ResourceProviderGetResult<AgentBase>>> GetAgents(string instanceId) =>
await _agentResourceProvider.GetResourcesWithRBAC<AgentBase>(instanceId, _callContext.CurrentUserIdentity!);
}
Expand Down
10 changes: 5 additions & 5 deletions src/dotnet/Gatekeeper/Interfaces/IGatekeeperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ public interface IGatekeeperService
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="completionRequest">The completion request containing the user prompt and message history.</param>
/// <returns>Returns an <see cref="OperationState"/> object containing the OperationId and Status.</returns>
Task<OperationState> StartCompletionOperation(string instanceId, CompletionRequest completionRequest);
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest);

/// <summary>
/// Gets the status of a completion operation.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The OperationId to retrieve the status for.</param>
/// <returns>Returns an <see cref="OperationState"/> object containing the OperationId and Status.</returns>
Task<OperationState> GetCompletionOperationStatus(string instanceId, string operationId);
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId);

/// <summary>
/// Gets a completion operation from the Gatekeeper service.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The ID of the operation to retrieve.</param>
/// <returns>Returns a <see cref="CompletionResponse" /> object.</returns>
Task<CompletionResponse> GetCompletionOperation(string instanceId, string operationId);
Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId);
}
6 changes: 3 additions & 3 deletions src/dotnet/Gatekeeper/Services/GatekeeperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public async Task<CompletionResponse> GetCompletion(string instanceId, Completio
}

/// <inheritdoc/>
public async Task<OperationState> StartCompletionOperation(string instanceId, CompletionRequest completionRequest) =>
public async Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest) =>
// TODO: Need to call State API to start the operation.
throw new NotImplementedException();

/// <inheritdoc/>
public Task<OperationState> GetCompletionOperationStatus(string instanceId, string operationId) => throw new NotImplementedException();
public Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId) => throw new NotImplementedException();

/// <inheritdoc/>
public async Task<CompletionResponse> GetCompletionOperation(string instanceId, string operationId) =>
public async Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId) =>
// TODO: Need to call State API to get the operation.
throw new NotImplementedException();

Expand Down
12 changes: 6 additions & 6 deletions src/dotnet/GatekeeperAPI/Controllers/CompletionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public async Task<CompletionResponse> GetCompletion(string instanceId, Completio
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="completionRequest">The completion request containing the user prompt and message history.</param>
/// <returns>Returns an <see cref="OperationState"/> object containing the OperationId and Status.</returns>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
[HttpPost("async-completions")]
public async Task<ActionResult<OperationState>> StartCompletionOperation(string instanceId, CompletionRequest completionRequest)
public async Task<ActionResult<LongRunningOperation>> StartCompletionOperation(string instanceId, CompletionRequest completionRequest)
{
var state = await _gatekeeperService.StartCompletionOperation(instanceId, completionRequest);
return Accepted(state);
Expand All @@ -48,9 +48,9 @@ public async Task<ActionResult<OperationState>> StartCompletionOperation(string
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The OperationId for which to retrieve the status.</param>
/// <returns>Returns an <see cref="OperationState"/> object containing the OperationId and Status.</returns>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
[HttpGet("async-completions/{operationId}/status")]
public async Task<OperationState> GetCompletionOperationStatus(string instanceId, string operationId) =>
public async Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId) =>
await _gatekeeperService.GetCompletionOperationStatus(instanceId, operationId);

/// <summary>
Expand All @@ -60,8 +60,8 @@ public async Task<OperationState> GetCompletionOperationStatus(string instanceId
/// <param name="operationId">The ID of the operation to retrieve.</param>
/// <returns>Returns a completion response</returns>
[HttpGet("async-completions/{operationId}/result")]
public async Task<CompletionResponse> GetCompletionOperation(string instanceId, string operationId) =>
await _gatekeeperService.GetCompletionOperation(instanceId, operationId);
public async Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId) =>
await _gatekeeperService.GetCompletionOperationResult(instanceId, operationId);

}
}
12 changes: 6 additions & 6 deletions src/dotnet/Orchestration/Interfaces/IOrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ public interface IOrchestrationService
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="completionRequest">The completion request containing the user prompt and message history.</param>
/// <returns>Returns an <see cref="OperationState"/> object containing the OperationId and Status.</returns>
Task<OperationState> StartCompletionOperation(string instanceId, CompletionRequest completionRequest);
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest);

/// <summary>
/// Gets the status of a completion operation.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The OperationId to retrieve the status for.</param>
/// <returns>Returns an <see cref="OperationState"/> object containing the OperationId and Status.</returns>
Task<OperationState> GetCompletionOperationStatus(string instanceId, string operationId);
/// <param name="operationId">The OperationId for which to retrieve the status.</param>
/// <returns>Returns an <see cref="LongRunningOperation"/> object containing the OperationId and Status.</returns>
Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId);

/// <summary>
/// Gets a completion operation from the Orchestration service.
/// </summary>
/// <param name="instanceId">The FoundationaLLM instance id.</param>
/// <param name="operationId">The ID of the operation to retrieve.</param>
/// <returns>Returns a <see cref="CompletionResponse" /> object.</returns>
Task<CompletionResponse> GetCompletionOperation(string instanceId, string operationId);
Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId);
}
8 changes: 4 additions & 4 deletions src/dotnet/Orchestration/Services/OrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class OrchestrationService : IOrchestrationService
/// <summary>
/// Constructor for the Orchestration Service.
/// </summary>
/// <param name="resourceProviderServices">A list of of <see cref="IResourceProviderService"/> resource providers hashed by resource provider name.</param>
/// <param name="resourceProviderServices">A list of <see cref="IResourceProviderService"/> resource providers hashed by resource provider name.</param>
/// <param name="llmOrchestrationServiceManager">The <see cref="ILLMOrchestrationServiceManager"/> managing the internal and external LLM orchestration services.</param>
/// <param name="callContext">The call context of the request being handled.</param>
/// <param name="configuration">The <see cref="IConfiguration"/> used to retrieve app settings from configuration.</param>
Expand Down Expand Up @@ -101,15 +101,15 @@ public async Task<CompletionResponse> GetCompletion(string instanceId, Completio
}

/// <inheritdoc/>
public async Task<OperationState> StartCompletionOperation(string instanceId, CompletionRequest completionRequest) =>
public async Task<LongRunningOperation> StartCompletionOperation(string instanceId, CompletionRequest completionRequest) =>
// TODO: Need to call State API to start the operation.
throw new NotImplementedException();

/// <inheritdoc/>
public Task<OperationState> GetCompletionOperationStatus(string instanceId, string operationId) => throw new NotImplementedException();
public Task<LongRunningOperation> GetCompletionOperationStatus(string instanceId, string operationId) => throw new NotImplementedException();

/// <inheritdoc/>
public async Task<CompletionResponse> GetCompletionOperation(string instanceId, string operationId) =>
public async Task<CompletionResponse> GetCompletionOperationResult(string instanceId, string operationId) =>
// TODO: Need to call State API to get the operation.
throw new NotImplementedException();

Expand Down
Loading

0 comments on commit 0f3a154

Please sign in to comment.