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
7 changes: 4 additions & 3 deletions core/KendoCoreService/Controllers/LLMController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<IActionResult> AIChatCompletion([FromBody] IList<ChatMessage>
messages.Prepend(new ChatMessage(ChatRole.System, DefaultSystemPrompt));
}

var response = await _chatClient.CompleteAsync(messages, options);
var response = await _chatClient.GetResponseAsync(messages, options);

return Json(response);
}
Expand All @@ -53,14 +53,15 @@ private void ValidateMessagesLength(IList<ChatMessage> messages)
{
var tokenizer = GptEncoding.GetEncoding("cl100k_base");

foreach (var message in messages)
for (var i = 0; i < messages.Count; i++)
{
var message = messages[i];
var tokens = tokenizer.Encode(message.Text);

if (tokens.Count > 1000)
{
var truncatedTokens = tokens.Take(1000).ToList();
message.Text = tokenizer.Decode(truncatedTokens);
messages[i] = new ChatMessage(message.Role, tokenizer.Decode(truncatedTokens));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/KendoCoreService/KendoCoreService.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -10,8 +10,8 @@
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.Core" Version="1.44.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.11" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.4.4-preview.1.25259.16" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.4-preview.1.25259.16" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SharpToken" Version="2.0.3" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion core/KendoCoreService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
));

builder.Services.AddChatClient(services => services.GetRequiredService<AzureOpenAIClient>()
.AsChatClient(builder.Configuration["AI:AzureOpenAI:Chat:ModelId"] ?? "gpt-4o-mini"));
.GetChatClient(builder.Configuration["AI:AzureOpenAI:Chat:ModelId"] ?? "gpt-4o-mini").AsIChatClient());

builder.Services.AddControllers()
.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
Expand Down