Skip to content

Commit eed66a7

Browse files
Merge pull request #35 from wisedev-code/feat/configurable-infer-memory-params
Feat/configurable infer memory params
2 parents d0a5cfa + b6e85db commit eed66a7

File tree

12 files changed

+82
-22
lines changed

12 files changed

+82
-22
lines changed

MaIN.Core.IntegrationTests/ChatTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text.Json;
22
using MaIN.Core.Hub;
33
using MaIN.Domain.Configuration;
4+
using MaIN.Domain.Entities;
45
using Microsoft.AspNetCore.Mvc.Testing;
56
using Microsoft.Extensions.Configuration;
67

@@ -67,6 +68,10 @@ public async Task Should_AnswerGameFromImage_ChatWithVision()
6768

6869
var result = await AIHub.Chat()
6970
.WithModel("llama3.2:3b")
71+
.WithMemoryParams(new MemoryParams
72+
{
73+
AnswerTokens = 1000
74+
})
7075
.WithMessage("What is the title of game?")
7176
.WithFiles(images)
7277
.CompleteAsync();

Releases/0.1.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 0.1.1 release
2+
3+
- Expanded Inference parameters to allow for more LLM behavior configuration
4+
- Added Memory parameters to allow LLM behavior configuration when working with files

src/MaIN.Core.UnitTests/AgentContextTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public async Task CreateAsync_ShouldCallAgentServiceCreateAgent()
132132
It.IsAny<Agent>(),
133133
It.IsAny<bool>(),
134134
It.IsAny<bool>(),
135-
It.IsAny<InferenceParams>()))
135+
It.IsAny<InferenceParams>(),
136+
It.IsAny<MemoryParams>()))
136137
.ReturnsAsync(agent);
137138

138139
// Act
@@ -144,7 +145,8 @@ public async Task CreateAsync_ShouldCallAgentServiceCreateAgent()
144145
It.IsAny<Agent>(),
145146
It.Is<bool>(f => f == true),
146147
It.Is<bool>(r => r == false),
147-
It.IsAny<InferenceParams>()),
148+
It.IsAny<InferenceParams>(),
149+
It.IsAny<MemoryParams>()),
148150
Times.Once);
149151
Assert.Equal(_agentContext, result);
150152
}

src/MaIN.Core/.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MaIN.NET</id>
5-
<version>0.1.0</version>
5+
<version>0.1.1</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Core/Hub/Contexts/AgentContext.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using MaIN.Domain.Entities.Agents;
33
using MaIN.Domain.Entities.Agents.AgentSource;
44
using MaIN.Domain.Models;
5-
using MaIN.Services.Dtos;
6-
using MaIN.Services.Mappers;
75
using MaIN.Services.Services.Abstract;
86
using MaIN.Services.Services.Models;
97

@@ -13,6 +11,7 @@ public class AgentContext
1311
{
1412
private readonly IAgentService _agentService;
1513
private InferenceParams? _inferenceParams;
14+
private MemoryParams? _memoryParams;
1615
private Agent _agent;
1716

1817
internal AgentContext(IAgentService agentService)
@@ -84,7 +83,13 @@ public AgentContext WithInferenceParams(InferenceParams inferenceParams)
8483
_inferenceParams = inferenceParams;
8584
return this;
8685
}
87-
86+
87+
public AgentContext WithMemoryParams(MemoryParams memoryParams)
88+
{
89+
_memoryParams = memoryParams;
90+
return this;
91+
}
92+
8893
public AgentContext WithCustomModel(string model, string path)
8994
{
9095
KnownModels.AddModel(model, path);
@@ -115,13 +120,13 @@ public AgentContext WithBehaviour(string name, string instruction)
115120

116121
public async Task<AgentContext> CreateAsync(bool flow = false, bool interactiveResponse = false)
117122
{
118-
await _agentService.CreateAgent(_agent, flow, interactiveResponse, _inferenceParams);
123+
await _agentService.CreateAgent(_agent, flow, interactiveResponse, _inferenceParams, _memoryParams);
119124
return this;
120125
}
121126

122127
public AgentContext Create(bool flow = false, bool interactiveResponse = false)
123128
{
124-
_ = _agentService.CreateAgent(_agent, flow, interactiveResponse, _inferenceParams).Result;
129+
_ = _agentService.CreateAgent(_agent, flow, interactiveResponse, _inferenceParams, _memoryParams).Result;
125130
return this;
126131
}
127132

src/MaIN.Core/Hub/Contexts/ChatContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public ChatContext WithInferenceParams(InferenceParams inferenceParams)
4141
_chat.InterferenceParams = inferenceParams;
4242
return this;
4343
}
44-
44+
45+
public ChatContext WithMemoryParams(MemoryParams memoryParams)
46+
{
47+
_chat.MemoryParams = memoryParams;
48+
return this;
49+
}
50+
4551
public ChatContext WithCustomModel(string model, string path)
4652
{
4753
KnownModels.AddModel(model, path);

src/MaIN.Domain/Entities/Chat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Chat
99
public ChatType Type { get; set; } = ChatType.Conversation;
1010
public bool Visual { get; set; }
1111
public InferenceParams InterferenceParams { get; set; } = new();
12+
public MemoryParams MemoryParams { get; set; } = new();
1213
public Dictionary<string, string> Properties { get; init; } = [];
1314
public List<string> Memory { get; } = [];
1415

src/MaIN.Domain/Entities/InferenceParams.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@ public class InferenceParams
44
{
55
public float Temperature { get; init; } = 0.8f;
66
public int ContextSize { get; init; } = 1024;
7+
public int GpuLayerCount { get; init; } = 30;
8+
public uint SeqMax { get; init; } = 1;
9+
public uint BatchSize { get; init; } = 512;
10+
public uint UBatchSize { get; init; } = 512;
11+
public bool Embeddings { get; init; } = false;
12+
public int TypeK { get; init; } = 0;
13+
public int TypeV { get; init; } = 0;
14+
15+
public int TokensKeep { get; set; }
16+
public int MaxTokens { get; set; }
17+
18+
public int TopK { get; init; } = 40;
19+
public float TopP { get; init; } = 0.9f;
720
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace MaIN.Domain.Entities;
2+
3+
public class MemoryParams
4+
{
5+
public int MaxMatchesCount { get; set; } = 5;
6+
public float FrequencyPenalty { get; set; } = 1f;
7+
public float Temperature { get; set; } = 0.6f;
8+
/// <summary>
9+
/// Maximum number of tokens to reserve for the answer.
10+
/// If LLM supports 5000 tokens and AnswerToken is 500 then prompt sent will contain max 4500 tokens
11+
/// (prompt + question + grounding information from memory)
12+
/// If your response is invalid make sure you meet those limits.
13+
/// </summary>
14+
public int AnswerTokens { get; set; } = 500;
15+
}

src/MaIN.Services/Services/Abstract/IAgentService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace MaIN.Services.Services.Abstract;
66
public interface IAgentService
77
{
88
Task<Chat> Process(Chat chat, string agentId, bool translatePrompt = false);
9-
Task<Agent> CreateAgent(Agent agent, bool flow = false, bool interactiveResponse = false, InferenceParams? inferenceParams = null);
9+
Task<Agent> CreateAgent(Agent agent, bool flow = false, bool interactiveResponse = false, InferenceParams? inferenceParams = null, MemoryParams? memoryParams = null);
1010
Task<Chat> GetChatByAgent(string agentId);
1111
Task<Chat> Restart(string agentId);
1212
Task<List<Agent>> GetAgents();

0 commit comments

Comments
 (0)