Skip to content

Commit d88fc09

Browse files
committed
Make chat service not inherit IDisposable
1 parent 5ca98aa commit d88fc09

5 files changed

Lines changed: 5 additions & 13 deletions

File tree

src/BE/Controllers/Api/AnthropicCompatible/AnthropicCountTokenController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<ActionResult> CountTokens([FromBody] JsonObject json, Cancella
4949
try
5050
{
5151
Model cm = userModel.Model;
52-
using ChatService s = cf.CreateChatService(cm);
52+
ChatService s = cf.CreateChatService(cm);
5353
ChatRequest chatRequest = request.ToChatRequest(currentApiKey.User.Id.ToString(), cm);
5454
int inputTokens = await s.CountTokenAsync(chatRequest, cancellationToken);
5555

src/BE/Controllers/Api/AnthropicCompatible/AnthropicMessagesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private async Task<ActionResult> ProcessMessage(
7070
CancellationToken cancellationToken)
7171
{
7272
Model cm = userModel.Model;
73-
using ChatService s = cf.CreateChatService(cm);
73+
ChatService s = cf.CreateChatService(cm);
7474
UserBalance userBalance = await db.UserBalances
7575
.Where(x => x.UserId == currentApiKey.User.Id)
7676
.FirstOrDefaultAsync(cancellationToken) ?? throw new InvalidOperationException("User balance not found.");

src/BE/Controllers/Api/OpenAICompatible/OpenAIChatCompletionController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private async Task<ActionResult> ChatCompletionUseCache(
237237
private async Task<ActionResult> ChatCompletionNoCache(CcoWrapper cco, UserModel userModel, InChatContext icc, Task<int> clientInfoIdTask, CancellationToken cancellationToken)
238238
{
239239
Model cm = userModel.Model;
240-
using ChatService s = cf.CreateChatService(cm);
240+
ChatService s = cf.CreateChatService(cm);
241241
UserBalance userBalance = await db.UserBalances
242242
.Where(x => x.UserId == currentApiKey.User.Id)
243243
.FirstOrDefaultAsync(cancellationToken) ?? throw new InvalidOperationException("User balance not found.");

src/BE/Controllers/Chats/Chats/ChatController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ async Task<Step> RunOne(ChatRequest request, CancellationToken cancellationToken
632632
string? errorText = null;
633633
try
634634
{
635-
using ChatService s = chatFactory.CreateChatService(userModel.Model);
635+
ChatService s = chatFactory.CreateChatService(userModel.Model);
636636

637637
bool responseStated = false, reasoningStarted = false;
638638
await foreach (InternalChatSegment seg in icc.Run(calc, userModel, s.ChatEntry(request, fup, UsageSource.WebChat, cancellationToken)))

src/BE/Services/Models/ChatServices/ChatService.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Chats.BE.Services.Models;
1313

14-
public abstract partial class ChatService : IDisposable
14+
public abstract partial class ChatService
1515
{
1616
internal static Tokenizer Tokenizer { get; } = TiktokenTokenizer.CreateForEncoding("o200k_base");
1717

@@ -206,12 +206,4 @@ static async Task<StepContent> DownloadImagePart(HttpClient http, string url, Ca
206206
}
207207

208208
private static readonly HttpClient http = new();
209-
210-
public void Dispose()
211-
{
212-
Disposing();
213-
GC.SuppressFinalize(this);
214-
}
215-
216-
protected virtual void Disposing() { }
217209
}

0 commit comments

Comments
 (0)