Browse Source

Strongly type connection status

tags/v0.4.2-preview
sa_ddam213 2 years ago
parent
commit
d9fbd56f10
14 changed files with 50 additions and 16 deletions
  1. +1
    -1
      LLama.Web/Common/LLamaOptions.cs
  2. +1
    -1
      LLama.Web/Common/ModelOptions.cs
  3. +1
    -1
      LLama.Web/Common/ParameterOptions.cs
  4. +1
    -1
      LLama.Web/Common/PromptOptions.cs
  5. +9
    -0
      LLama.Web/Common/SessionConnectionStatus.cs
  6. +3
    -2
      LLama.Web/Hubs/ISessionClient.cs
  7. +4
    -3
      LLama.Web/Hubs/InteractiveHub.cs
  8. +1
    -0
      LLama.Web/Models/ModelSession.cs
  9. +4
    -4
      LLama.Web/Pages/Interactive.cshtml
  10. +2
    -1
      LLama.Web/Pages/Interactive.cshtml.cs
  11. +1
    -1
      LLama.Web/Program.cs
  12. +1
    -0
      LLama.Web/Services/IModelSessionService.cs
  13. +1
    -0
      LLama.Web/Services/ModelSessionService.cs
  14. +20
    -1
      LLama.Web/wwwroot/js/site.js

LLama.Web/Models/LLamaOptions.cs → LLama.Web/Common/LLamaOptions.cs View File

@@ -1,4 +1,4 @@
namespace LLama.Web.Models
namespace LLama.Web.Common
{ {
public class LLamaOptions public class LLamaOptions
{ {

LLama.Web/Models/ModelOptions.cs → LLama.Web/Common/ModelOptions.cs View File

@@ -1,6 +1,6 @@
using LLama.Common; using LLama.Common;


namespace LLama.Web.Models
namespace LLama.Web.Common
{ {
public class ModelOptions : ModelParams public class ModelOptions : ModelParams
{ {

LLama.Web/Models/ParameterOptions.cs → LLama.Web/Common/ParameterOptions.cs View File

@@ -1,6 +1,6 @@
using LLama.Common; using LLama.Common;


namespace LLama.Web.Models
namespace LLama.Web.Common
{ {
public class ParameterOptions : InferenceParams public class ParameterOptions : InferenceParams
{ {

LLama.Web/Models/PromptOptions.cs → LLama.Web/Common/PromptOptions.cs View File

@@ -1,4 +1,4 @@
namespace LLama.Web.Models
namespace LLama.Web.Common
{ {
public class PromptOptions public class PromptOptions
{ {

+ 9
- 0
LLama.Web/Common/SessionConnectionStatus.cs View File

@@ -0,0 +1,9 @@
namespace LLama.Web.Common
{
public enum SessionConnectionStatus
{
Disconnected = 0,
Loaded = 4,
Connected = 10
}
}

+ 3
- 2
LLama.Web/Hubs/ISessionClient.cs View File

@@ -1,10 +1,11 @@
using LLama.Web.Models;
using LLama.Web.Common;
using LLama.Web.Models;


namespace LLama.Web.Hubs namespace LLama.Web.Hubs
{ {
public interface ISessionClient public interface ISessionClient
{ {
Task OnStatus(string status, string data = null);
Task OnStatus(string connectionId, SessionConnectionStatus status);
Task OnResponse(ResponseFragment fragment); Task OnResponse(ResponseFragment fragment);
Task OnError(string error); Task OnError(string error);
} }


+ 4
- 3
LLama.Web/Hubs/InteractiveHub.cs View File

@@ -1,4 +1,5 @@
using LLama.Web.Models;
using LLama.Web.Common;
using LLama.Web.Models;
using LLama.Web.Services; using LLama.Web.Services;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@@ -24,7 +25,7 @@ namespace LLama.Web.Hubs
{ {
_logger.Log(LogLevel.Information, "OnConnectedAsync, Id: {0}", Context.ConnectionId); _logger.Log(LogLevel.Information, "OnConnectedAsync, Id: {0}", Context.ConnectionId);
await base.OnConnectedAsync(); await base.OnConnectedAsync();
await Clients.Caller.OnStatus("Connected", Context.ConnectionId);
await Clients.Caller.OnStatus(Context.ConnectionId, SessionConnectionStatus.Connected);
} }




@@ -55,7 +56,7 @@ namespace LLama.Web.Hubs
} }
_logger.Log(LogLevel.Information, "[OnLoadModel] - New model session added, Connection: {0}", Context.ConnectionId); _logger.Log(LogLevel.Information, "[OnLoadModel] - New model session added, Connection: {0}", Context.ConnectionId);
await Clients.Caller.OnStatus("Loaded", Context.ConnectionId);
await Clients.Caller.OnStatus(Context.ConnectionId, SessionConnectionStatus.Loaded);
} }






+ 1
- 0
LLama.Web/Models/ModelSession.cs View File

@@ -1,4 +1,5 @@
using LLama.Abstractions; using LLama.Abstractions;
using LLama.Web.Common;


namespace LLama.Web.Models namespace LLama.Web.Models
{ {


+ 4
- 4
LLama.Web/Pages/Interactive.cshtml View File

@@ -172,12 +172,12 @@
const chatInput = $("#input"); const chatInput = $("#input");




const onStatus = (status, data) => {
if (status == "Connected") {
const onStatus = (connectionId, status) => {
connectionId = connectionId;
if (status == Enums.SessionConnectionStatus.Connected) {
$("#socket").text("Connected").addClass("text-success"); $("#socket").text("Connected").addClass("text-success");
connectionId = data;
} }
else if (status == "Loaded") {
else if (status == Enums.SessionConnectionStatus.Loaded) {
enableControls(); enableControls();
$("#session-details").html(Mustache.render(sessionDetailsTemplate, { model: getSelectedModel(), prompt: getSelectedPrompt(), parameter: getSelectedParameter() })); $("#session-details").html(Mustache.render(sessionDetailsTemplate, { model: getSelectedModel(), prompt: getSelectedPrompt(), parameter: getSelectedParameter() }));
onInfo(`New model session successfully started`) onInfo(`New model session successfully started`)


+ 2
- 1
LLama.Web/Pages/Interactive.cshtml.cs View File

@@ -1,4 +1,5 @@
using LLama.Web.Models;
using LLama.Web.Common;
using LLama.Web.Models;
using LLama.Web.Services; using LLama.Web.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;


+ 1
- 1
LLama.Web/Program.cs View File

@@ -1,5 +1,5 @@
using LLama.Web.Common;
using LLama.Web.Hubs; using LLama.Web.Hubs;
using LLama.Web.Models;
using LLama.Web.Services; using LLama.Web.Services;


namespace LLama.Web namespace LLama.Web


+ 1
- 0
LLama.Web/Services/IModelSessionService.cs View File

@@ -1,4 +1,5 @@
using LLama.Abstractions; using LLama.Abstractions;
using LLama.Web.Common;
using LLama.Web.Models; using LLama.Web.Models;


namespace LLama.Web.Services namespace LLama.Web.Services


+ 1
- 0
LLama.Web/Services/ModelSessionService.cs View File

@@ -1,4 +1,5 @@
using LLama.Abstractions; using LLama.Abstractions;
using LLama.Web.Common;
using LLama.Web.Models; using LLama.Web.Models;
using System.Collections.Concurrent; using System.Collections.Concurrent;




+ 20
- 1
LLama.Web/wwwroot/js/site.js View File

@@ -29,4 +29,23 @@ const ajaxGetJsonAsync = (url, data) => {
dataType: 'json', dataType: 'json',
data: data data: data
}); });
}
}




const Enums = {
SessionConnectionStatus: Object.freeze({
Disconnected: 0,
Loaded: 4,
Connected: 10
}),

GetName: (enumType, enumKey) => {
return Object.keys(enumType)[enumKey]
},

GetValue: (enumType, enumName) => {
return enumType[enumName];
}
};

Loading…
Cancel
Save