Skip to content

Commit d94b5cb

Browse files
authored
Merge pull request #916 from iceljc/features/add-latest-state
Features/add latest state
2 parents 4a5ec1c + f60bcda commit d94b5cb

File tree

70 files changed

+1168
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1168
-101
lines changed

src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>$(TargetFramework)</TargetFramework>

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public class RoleDialogModel : ITrackableMessage
108108
[JsonPropertyName("generated_images")]
109109
public List<ImageGeneration> GeneratedImages { get; set; } = new List<ImageGeneration>();
110110

111-
111+
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
112+
public string RenderedInstruction { get; set; } = string.Empty;
112113

113114
private RoleDialogModel()
114115
{

src/Infrastructure/BotSharp.Abstraction/Instructs/IInstructHook.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public interface IInstructHook
77
string SelfId { get; }
88
Task BeforeCompletion(Agent agent, RoleDialogModel message);
99
Task AfterCompletion(Agent agent, InstructResult result);
10+
Task OnResponseGenerated(InstructResponseModel response);
1011
}

src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ public virtual async Task AfterCompletion(Agent agent, InstructResult result)
1515
{
1616
return;
1717
}
18+
19+
public virtual async Task OnResponseGenerated(InstructResponseModel response)
20+
{
21+
return;
22+
}
1823
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace BotSharp.Abstraction.Instructs.Models;
4+
5+
public class InstructLogFilter : Pagination
6+
{
7+
public List<string>? AgentIds { get; set; }
8+
public List<string>? Providers { get; set; }
9+
public List<string>? Models { get; set; }
10+
public List<string>? TemplateNames { get; set; }
11+
12+
public static InstructLogFilter Empty()
13+
{
14+
return new InstructLogFilter();
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace BotSharp.Abstraction.Instructs.Models;
2+
3+
public class InstructResponseModel
4+
{
5+
public string? AgentId { get; set; }
6+
public string Provider { get; set; } = default!;
7+
public string Model { get; set; } = default!;
8+
public string? TemplateName { get; set; }
9+
public string UserMessage { get; set; } = default!;
10+
public string? SystemInstruction { get; set; }
11+
public string CompletionText { get; set; } = default!;
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Text.Json;
2+
3+
namespace BotSharp.Abstraction.Loggers.Models;
4+
5+
public class InstructionLogModel
6+
{
7+
[JsonPropertyName("id")]
8+
public string Id { get; set; } = default!;
9+
10+
[JsonPropertyName("agent_id")]
11+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
12+
public string? AgentId { get; set; }
13+
14+
[JsonPropertyName("agent_name")]
15+
[JsonIgnore]
16+
public string? AgentName { get; set; }
17+
18+
[JsonPropertyName("provider")]
19+
public string Provider { get; set; } = default!;
20+
21+
[JsonPropertyName("model")]
22+
public string Model { get; set; } = default!;
23+
24+
[JsonPropertyName("template_name")]
25+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26+
public string? TemplateName { get; set; }
27+
28+
[JsonPropertyName("user_message")]
29+
public string UserMessage { get; set; } = string.Empty;
30+
31+
[JsonPropertyName("system_instruction")]
32+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
33+
public string? SystemInstruction { get; set; }
34+
35+
[JsonPropertyName("completion_text")]
36+
public string CompletionText { get; set; } = string.Empty;
37+
38+
[JsonPropertyName("user_id")]
39+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
40+
public string? UserId { get; set; }
41+
42+
[JsonIgnore]
43+
public Dictionary<string, string> States { get; set; } = [];
44+
45+
[JsonPropertyName("states")]
46+
public Dictionary<string, JsonDocument> InnerStates { get; set; } = [];
47+
48+
[JsonPropertyName("created_time")]
49+
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
50+
}

src/Infrastructure/BotSharp.Abstraction/MLTasks/IAudioCompletion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public interface IAudioCompletion
66
{
77
string Provider { get; }
88

9+
string Model { get; }
10+
911
Task<string> GenerateTextFromAudioAsync(Stream audio, string audioFileName, string? text = null);
1012
Task<BinaryData> GenerateAudioFromTextAsync(string text);
1113

src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public interface IChatCompletion
77
/// </summary>
88
string Provider { get; }
99

10+
string Model { get; }
11+
1012
/// <summary>
1113
/// Set model name, one provider can consume different model or version(s)
1214
/// </summary>

src/Infrastructure/BotSharp.Abstraction/MLTasks/IImageCompletion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public interface IImageCompletion
99
/// </summary>
1010
string Provider { get; }
1111

12+
string Model { get; }
13+
1214
/// <summary>
1315
/// Set model name, one provider can consume different model or version(s)
1416
/// </summary>

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public interface IRealTimeCompletion
66
{
77
string Provider { get; }
88
string Model { get; }
9-
109
void SetModelName(string model);
1110

1211
Task Connect(RealtimeHubConnection conn,

src/Infrastructure/BotSharp.Abstraction/MLTasks/ITextCompletion.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface ITextCompletion
66
/// The LLM provider like Microsoft Azure, OpenAI, ClaudAI
77
/// </summary>
88
string Provider { get; }
9+
string Model { get; }
910

1011
/// <summary>
1112
/// Set model name, one provider can consume different model or version(s)

src/Infrastructure/BotSharp.Abstraction/MLTasks/ITextEmbedding.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ public interface ITextEmbedding
66
/// The Embedding provider like Microsoft Azure, OpenAI, ClaudAI
77
/// </summary>
88
string Provider { get; }
9+
string Model { get; }
10+
11+
void SetModelName(string model);
12+
13+
914
Task<float[]> GetVectorAsync(string text);
1015
Task<List<float[]>> GetVectorsAsync(List<string> texts);
11-
void SetModelName(string model);
16+
1217
void SetDimension(int dimension);
1318
int GetDimension();
1419
}

src/Infrastructure/BotSharp.Abstraction/Models/KeyValue.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ public override string ToString()
1313
return $"Key: {Key}, Value: {Value}";
1414
}
1515
}
16+
17+
public class KeyValue<T>
18+
{
19+
[JsonPropertyName("key")]
20+
public string Key { get; set; }
21+
22+
[JsonPropertyName("value")]
23+
public T? Value { get; set; }
24+
25+
public override string ToString()
26+
{
27+
return $"Key: {Key}, Value: {Value}";
28+
}
29+
}

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Instructs.Models;
12
using BotSharp.Abstraction.Loggers.Models;
23
using BotSharp.Abstraction.Plugins.Models;
34
using BotSharp.Abstraction.Repositories.Filters;
@@ -171,6 +172,14 @@ List<ConversationStateLogModel> GetConversationStateLogs(string conversationId)
171172
=> throw new NotImplementedException();
172173
#endregion
173174

175+
#region Instruction Log
176+
bool SaveInstructionLogs(IEnumerable<InstructionLogModel> logs)
177+
=> throw new NotImplementedException();
178+
179+
PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filter)
180+
=> throw new NotImplementedException();
181+
#endregion
182+
174183
#region Statistics
175184
BotSharpStats? GetGlobalStats(string metric, string dimension, string dimRefVal, DateTime recordTime, StatsInterval interval)
176185
=> throw new NotImplementedException();

src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,20 @@ public static string JsonArrayContent(this string text)
9292

9393
return JsonSerializer.Deserialize<T[]>(text, options);
9494
}
95+
96+
public static bool IsPrimitiveValue(this string value)
97+
{
98+
return int.TryParse(value, out _) ||
99+
long.TryParse(value, out _) ||
100+
double.TryParse(value, out _) ||
101+
float.TryParse(value, out _) ||
102+
bool.TryParse(value, out _) ||
103+
char.TryParse(value, out _) ||
104+
byte.TryParse(value, out _) ||
105+
sbyte.TryParse(value, out _) ||
106+
short.TryParse(value, out _) ||
107+
ushort.TryParse(value, out _) ||
108+
uint.TryParse(value, out _) ||
109+
ulong.TryParse(value, out _);
110+
}
95111
}

0 commit comments

Comments
 (0)