Skip to content

Commit

Permalink
Fix load agent error for InstructMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Oceania2018 committed Dec 5, 2023
1 parent 78d66eb commit ed96ff0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public partial class AgentService
[MemoryCache(10 * 60, perInstanceCache: true)]
public async Task<Agent> LoadAgent(string id)
{
if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())
{
return null;
}

var hooks = _services.GetServices<IAgentHook>();

// Before agent is loaded.
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenS
var agent = await agentService.LoadAgent(message.CurrentAgentId);

var log = message.Role == AgentRole.Function ?
$"[[msg_id: {message.MessageId}] [{agent.Name}]: {message.FunctionName}({message.FunctionArgs})" :
$"[[msg_id: {message.MessageId}] [{agent.Name}]: {message.Content}";
$"[[msg_id: {message.MessageId}] [{agent?.Name}]: {message.FunctionName}({message.FunctionArgs})" :
$"[[msg_id: {message.MessageId}] [{agent?.Name}]: {message.Content}";

_logger.LogInformation(tokenStats.Prompt);
_logger.LogInformation(log);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.ApiAdapters;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Instructs;
using BotSharp.Abstraction.Instructs.Models;
using BotSharp.Core.Infrastructures;
Expand Down Expand Up @@ -48,6 +45,6 @@ public async Task<string> TextCompletion([FromBody] IncomingMessageModel input)
.SetState("model", input.Model);

var textCompletion = CompletionProvider.GetTextCompletion(_services);
return await textCompletion.GetCompletion(input.Text, Guid.Empty.ToString(), Guid.Empty.ToString());
return await textCompletion.GetCompletion(input.Text, Guid.Empty.ToString(), Guid.NewGuid().ToString());
}
}

0 comments on commit ed96ff0

Please sign in to comment.