Skip to content

Commit 492a1d7

Browse files
committed
ITrackableMessage
1 parent 7ab383a commit 492a1d7

22 files changed

+103
-64
lines changed

docs/channels/components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Messaging Components
22

3-
Conversations are a lot more than simple text messages when you are building a AI chatbot. In addition to text, the `BotSharp`` allows you to send rich-media, like audio, video, and images, and provides a set of structured messaging options in the form of message templates, quick replies, buttons and more. The UI rendering program can render components according to the returned data format.
3+
Conversations are a lot more than simple text messages when you are building a AI chatbot. In addition to text, the `BotSharp` allows you to send rich-media, like audio, video, and images, and provides a set of structured messaging options in the form of message templates, quick replies, buttons and more. The UI rendering program can render components according to the returned data format.
44

55

66
## Text Messages
@@ -75,7 +75,7 @@ Message templates are structured message formats used for various purposes to pr
7575
...
7676
}
7777
]
78-
}
78+
}
7979
}
8080
}
8181
}
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1+
using BotSharp.Abstraction.Models;
2+
13
namespace BotSharp.Abstraction.Conversations.Models;
24

3-
public class IncomingMessageModel
5+
public class IncomingMessageModel : MessageConfig
46
{
57
public string Text { get; set; } = string.Empty;
6-
7-
public virtual string Channel { get; set; } = string.Empty;
8-
9-
/// <summary>
10-
/// Completion Provider
11-
/// </summary>
12-
[JsonPropertyName("provider")]
13-
public virtual string? Provider { get; set; } = null;
14-
15-
/// <summary>
16-
/// Model name
17-
/// </summary>
18-
[JsonPropertyName("model")]
19-
public virtual string? Model { get; set; } = null;
20-
21-
/// <summary>
22-
/// The sampling temperature to use that controls the apparent creativity of generated completions.
23-
/// </summary>
24-
public float Temperature { get; set; } = 0.5f;
25-
26-
/// <summary>
27-
/// An alternative value to Temperature, called nucleus sampling, that causes
28-
/// the model to consider the results of the tokens with probability mass.
29-
/// </summary>
30-
public float SamplingFactor { get; set; } = 0.5f;
31-
32-
/// <summary>
33-
/// Conversation states from input
34-
/// </summary>
35-
public List<string> States { get; set; } = new List<string>();
8+
public virtual string Channel { get; set; }
369
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
using BotSharp.Abstraction.Models;
2+
13
namespace BotSharp.Abstraction.Conversations.Models;
24

3-
public class RoleDialogModel
5+
public class RoleDialogModel : ITrackableMessage
46
{
7+
public string MessageId { get; set; }
8+
59
/// <summary>
610
/// user, system, assistant, function
711
/// </summary>
@@ -34,10 +38,15 @@ public class RoleDialogModel
3438
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
3539
public bool StopCompletion { get; set; }
3640

41+
private RoleDialogModel()
42+
{
43+
}
44+
3745
public RoleDialogModel(string role, string text)
3846
{
3947
Role = role;
4048
Content = text;
49+
MessageId = Guid.NewGuid().ToString();
4150
}
4251

4352
public override string ToString()

src/Infrastructure/BotSharp.Abstraction/Instructs/Models/InstructResult.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
using BotSharp.Abstraction.Models;
2+
13
namespace BotSharp.Abstraction.Instructs.Models;
24

3-
public class InstructResult
5+
public class InstructResult : ITrackableMessage
46
{
7+
public string MessageId { get; set; }
58
public string Text { get; set; }
69
public object Data { get; set; }
710
public ConversationState States { get; set; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Abstraction.Models;
2+
3+
/// <summary>
4+
/// Define a message ID to extend message-level applications, such as model fees, token usage, and data collection
5+
/// </summary>
6+
public interface ITrackableMessage
7+
{
8+
string MessageId { get; set; }
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace BotSharp.Abstraction.Models;
2+
3+
public class MessageConfig
4+
{
5+
/// <summary>
6+
/// Completion Provider
7+
/// </summary>
8+
[JsonPropertyName("provider")]
9+
public virtual string? Provider { get; set; } = null;
10+
11+
/// <summary>
12+
/// Model name
13+
/// </summary>
14+
[JsonPropertyName("model")]
15+
public virtual string? Model { get; set; } = null;
16+
17+
/// <summary>
18+
/// The sampling temperature to use that controls the apparent creativity of generated completions.
19+
/// </summary>
20+
public float Temperature { get; set; } = 0.5f;
21+
22+
/// <summary>
23+
/// An alternative value to Temperature, called nucleus sampling, that causes
24+
/// the model to consider the results of the tokens with probability mass.
25+
/// </summary>
26+
public float SamplingFactor { get; set; } = 0.5f;
27+
28+
/// <summary>
29+
/// Conversation states from input
30+
/// </summary>
31+
public List<string> States { get; set; } = new List<string>();
32+
}

src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace BotSharp.Abstraction.Routing.Models;
22

3-
public class RoutingArgs
3+
public class RoutingArgs : ITrackableMessage
44
{
5+
[JsonPropertyName("message_id")]
6+
public string MessageId { get; set; }
7+
58
[JsonPropertyName("function")]
69
public string Function { get; set; }
710

src/Infrastructure/BotSharp.Abstraction/Using.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
global using System.Text.Json.Serialization;
88
global using BotSharp.Abstraction.Agents.Models;
99
global using BotSharp.Abstraction.Conversations.Models;
10-
global using BotSharp.Abstraction.Agents.Enums;
10+
global using BotSharp.Abstraction.Agents.Enums;
11+
global using BotSharp.Abstraction.Models;

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public Task CleanHistory(string agentId)
7878
throw new NotImplementedException();
7979
}
8080

81-
public List<RoleDialogModel> GetDialogHistory(int lastCount = 20)
81+
public List<RoleDialogModel> GetDialogHistory(int lastCount = 50)
8282
{
8383
var dialogs = _storage.GetDialogs(_conversationId);
8484
return dialogs
85-
.Where(x => x.CreatedAt > DateTime.UtcNow.AddHours(-8))
85+
.Where(x => x.CreatedAt > DateTime.UtcNow.AddHours(-24))
8686
.TakeLast(lastCount)
8787
.ToList();
8888
}

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ namespace BotSharp.Core.Conversations.Services;
66
public class ConversationStorage : IConversationStorage
77
{
88
private readonly BotSharpDatabaseSettings _dbSettings;
9-
private readonly AgentSettings _agentSettings;
109
private readonly IServiceProvider _services;
11-
private readonly IUserIdentity _user;
1210
public ConversationStorage(
1311
BotSharpDatabaseSettings dbSettings,
14-
AgentSettings agentSettings,
15-
IServiceProvider services,
16-
IUserIdentity user)
12+
IServiceProvider services)
1713
{
1814
_dbSettings = dbSettings;
19-
_agentSettings = agentSettings;
2015
_services = services;
21-
_user = user;
2216
}
2317

2418
public void Append(string conversationId, RoleDialogModel dialog)
@@ -32,7 +26,7 @@ public void Append(string conversationId, RoleDialogModel dialog)
3226
{
3327
var args = dialog.FunctionArgs.Replace("\r", " ").Replace("\n", " ").Trim();
3428

35-
sb.AppendLine($"{dialog.CreatedAt}|{dialog.Role}|{agentId}|{dialog.FunctionName}|{args}");
29+
sb.AppendLine($"{dialog.CreatedAt}|{dialog.Role}|{agentId}|{dialog.MessageId}");
3630

3731
var content = dialog.Content;
3832
content = content.Replace("\r", " ").Replace("\n", " ").Trim();
@@ -44,9 +38,7 @@ public void Append(string conversationId, RoleDialogModel dialog)
4438
}
4539
else
4640
{
47-
var agentName = db.GetAgent(agentId)?.Name;
48-
49-
sb.AppendLine($"{dialog.CreatedAt}|{dialog.Role}|{agentId}|{agentName}|");
41+
sb.AppendLine($"{dialog.CreatedAt}|{dialog.Role}|{agentId}|{dialog.MessageId}");
5042
var content = dialog.Content.Replace("\r", " ").Replace("\n", " ").Trim();
5143
if (string.IsNullOrEmpty(content))
5244
{
@@ -73,15 +65,13 @@ public List<RoleDialogModel> GetDialogs(string conversationId)
7365
var createdAt = DateTime.Parse(meta.Split('|')[0]);
7466
var role = meta.Split('|')[1];
7567
var currentAgentId = meta.Split('|')[2];
76-
var funcName = meta.Split('|')[3];
77-
var funcArgs= meta.Split('|')[4];
68+
var messageId = meta.Split('|')[3];
7869
var text = dialog.Substring(4);
7970

8071
results.Add(new RoleDialogModel(role, text)
8172
{
8273
CurrentAgentId = currentAgentId,
83-
FunctionName = funcName,
84-
FunctionArgs = funcArgs,
74+
MessageId = messageId,
8575
Content = text,
8676
CreatedAt = createdAt
8777
});

0 commit comments

Comments
 (0)