Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ public async Task<RoleDialogModel> GetChatCompletionsStreamingAsync(Agent agent,
var allText = textStream.GetText();
_logger.LogCritical($"Text Content: {allText}");

responseMessage = new RoleDialogModel(AgentRole.Assistant, allText)
if (choice.FinishReason == ChatFinishReason.Length)
{
_logger.LogWarning($"Action: {nameof(GetChatCompletionsStreamingAsync)}, Reason: {choice.FinishReason}, Agent: {agent.Name}, MaxOutputTokens: {options.MaxOutputTokenCount}, Content:{allText}");
}

responseMessage = new RoleDialogModel(AgentRole.Assistant, ProviderHelper.ResolveStreamedContent(choice.FinishReason.Value, allText))
{
CurrentAgentId = agent.Id,
MessageId = messageId,
Expand Down
12 changes: 12 additions & 0 deletions src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/ProviderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;

namespace BotSharp.Plugin.DeepSeek.Providers;

public static class ProviderHelper
{
public const string MaxTokensMessage = "AI response exceeded max output length";

/// <summary>
/// Content of the final streamed message. A reply cut off by the output limit gets the same notice as the
/// non-streaming path instead of silently passing the truncated text off as a complete answer.
/// </summary>
public static string ResolveStreamedContent(ChatFinishReason reason, string collectedText)
{
return reason == ChatFinishReason.Length ? MaxTokensMessage : collectedText;
}

public static OpenAIClient GetClient(string provider, string model, IServiceProvider services)
{
var settingsService = services.GetRequiredService<ILlmProviderService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ public async Task<RoleDialogModel> GetChatCompletionsStreamingAsync(Agent agent,
var allText = textStream.GetText();
_logger.LogCritical($"Text Content: {allText}");

responseMessage = new RoleDialogModel(AgentRole.Assistant, allText)
if (choice.FinishReason == ChatFinishReason.Length)
{
_logger.LogWarning($"Action: {nameof(GetChatCompletionsStreamingAsync)}, Reason: {choice.FinishReason}, Agent: {agent.Name}, MaxOutputTokens: {options.MaxOutputTokenCount}, Content:{allText}");
}

responseMessage = new RoleDialogModel(AgentRole.Assistant, ProviderHelper.ResolveStreamedContent(choice.FinishReason.Value, allText))
{
CurrentAgentId = agent.Id,
MessageId = messageId,
Expand Down
12 changes: 12 additions & 0 deletions src/Plugins/BotSharp.Plugin.LiteLLM/Providers/ProviderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;

namespace BotSharp.Plugin.LiteLLM.Providers;

public static class ProviderHelper
{
public const string MaxTokensMessage = "AI response exceeded max output length";

/// <summary>
/// Content of the final streamed message. A reply cut off by the output limit gets the same notice as the
/// non-streaming path instead of silently passing the truncated text off as a complete answer.
/// </summary>
public static string ResolveStreamedContent(ChatFinishReason reason, string collectedText)
{
return reason == ChatFinishReason.Length ? MaxTokensMessage : collectedText;
}

public static OpenAIClient GetClient(string provider, string model, IServiceProvider services)
{
var settingsService = services.GetRequiredService<ILlmProviderService>();
Expand Down
4 changes: 4 additions & 0 deletions tests/BotSharp.Core.UnitTests/BotSharp.Core.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.FileHandler\BotSharp.Plugin.FileHandler.csproj" />
<!-- For GoogleAiUsageTests: Gemini thinking tokens must be counted as output tokens. -->
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.GoogleAI\BotSharp.Plugin.GoogleAI.csproj" />
<!-- For DeepSeekAIStreamedContentTests: the streamed final-message content lives here. -->
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj" />
<!-- For LiteLLMStreamedContentTests: the streamed final-message content lives here. -->
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.LiteLLM\BotSharp.Plugin.LiteLLM.csproj" />
<!-- For ConversationRelayKeptLinesTests: the history must show every line the caller heard on a relay call. -->
<ProjectReference Include="..\..\src\Plugins\BotSharp.Plugin.Twilio\BotSharp.Plugin.Twilio.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using BotSharp.Plugin.DeepSeek.Providers;
using OpenAI.Chat;
using Xunit;

namespace BotSharp.Core.UnitTests.Plugins;

public class DeepSeekAIStreamedContentTests
{
[Theory]
[InlineData("partial answer")]
[InlineData("")]
public void ResolveStreamedContent_Stop_ReturnsCollectedText(string text)
{
Assert.Equal(text, ProviderHelper.ResolveStreamedContent(ChatFinishReason.Stop, text));
}

// Streaming used to hand back the truncated text as if it were a complete answer; the non-streaming path shows a notice.
[Theory]
[InlineData("partial answer")]
[InlineData("")]
public void ResolveStreamedContent_Length_ReturnsSameNoticeAsNonStreaming(string text)
{
Assert.Equal("AI response exceeded max output length", ProviderHelper.ResolveStreamedContent(ChatFinishReason.Length, text));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using BotSharp.Plugin.LiteLLM.Providers;
using OpenAI.Chat;
using Xunit;

namespace BotSharp.Core.UnitTests.Plugins;

public class LiteLLMStreamedContentTests
{
[Theory]
[InlineData("partial answer")]
[InlineData("")]
public void ResolveStreamedContent_Stop_ReturnsCollectedText(string text)
{
Assert.Equal(text, ProviderHelper.ResolveStreamedContent(ChatFinishReason.Stop, text));
}

// Streaming used to hand back the truncated text as if it were a complete answer; the non-streaming path shows a notice.
[Theory]
[InlineData("partial answer")]
[InlineData("")]
public void ResolveStreamedContent_Length_ReturnsSameNoticeAsNonStreaming(string text)
{
Assert.Equal("AI response exceeded max output length", ProviderHelper.ResolveStreamedContent(ChatFinishReason.Length, text));
}
}
Loading