Implemented also OpenAI
This commit is contained in:
@@ -1,16 +1,27 @@
|
|||||||
using System.Diagnostics;
|
using System.ClientModel;
|
||||||
|
using System.ClientModel.Primitives;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
using LMStudio;
|
using LMStudio;
|
||||||
|
using OpenAI;
|
||||||
|
using OpenAI.Chat;
|
||||||
|
|
||||||
string baseUrl = Environment.GetEnvironmentVariable("LMSTUDIO_BASE_URL") ?? string.Empty;
|
|
||||||
|
string baseUrl = Environment.GetEnvironmentVariable("LMSTUDIO_BASE_URL") ?? "http://lmstudio:8001";
|
||||||
string model = Environment.GetEnvironmentVariable("LMSTUDIO_MODEL") ?? string.Empty;
|
string model = Environment.GetEnvironmentVariable("LMSTUDIO_MODEL") ?? string.Empty;
|
||||||
string apiKey = Environment.GetEnvironmentVariable("LMSTUDIO_API_KEY") ?? string.Empty;
|
string apiKey = Environment.GetEnvironmentVariable("LMSTUDIO_API_KEY") ?? string.Empty;
|
||||||
var lmsclient = new ModelConnection(baseUrl, model, apiKey);
|
var lmsclient = new ModelConnection(baseUrl, model, apiKey);
|
||||||
Dictionary<long, LMStudio.Chat> lmsChats = new();
|
Dictionary<long, LMStudio.Chat> lmsChats = new();
|
||||||
|
|
||||||
|
var options = new OpenAIClientOptions() {
|
||||||
|
Endpoint = new(baseUrl),
|
||||||
|
NetworkTimeout = new TimeSpan(0, 0, 30)
|
||||||
|
};
|
||||||
|
var openAiApiKey = new ApiKeyCredential(apiKey);
|
||||||
|
var openAiClient = new OpenAIClient(openAiApiKey, options);
|
||||||
|
|
||||||
string token = Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN") ?? string.Empty;
|
string token = Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN") ?? string.Empty;
|
||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
var bot = new TelegramBotClient(token, cancellationToken:cts.Token);
|
var bot = new TelegramBotClient(token, cancellationToken:cts.Token);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="LMStudio" Version="1.2.0" />
|
<PackageReference Include="LMStudio" Version="1.2.0" />
|
||||||
|
<PackageReference Include="OpenAI" Version="2.1.0" />
|
||||||
<PackageReference Include="Telegram.Bot" Version="22.2.0" />
|
<PackageReference Include="Telegram.Bot" Version="22.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,7 @@
|
|||||||
dockerfile: TelegramBot/Dockerfile
|
dockerfile: TelegramBot/Dockerfile
|
||||||
env_file:
|
env_file:
|
||||||
- TelegramBot/.env
|
- TelegramBot/.env
|
||||||
|
|
||||||
|
llama-cpp:
|
||||||
|
image: ghcr.io/ggerganov/llama.cpp:server
|
||||||
|
|
||||||
0
lmstudio.env
Normal file
0
lmstudio.env
Normal file
Reference in New Issue
Block a user