From 0aa0e597103f16fae533f0312804509ce869e064 Mon Sep 17 00:00:00 2001 From: Mikhail Shahovalov Date: Fri, 9 May 2025 15:16:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BD=D0=BE=20=D0=B6=D0=B8=D0=B2=D0=BE?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.idea.YandexGPT/.idea/indexLayout.xml | 8 +++++++ .idea/.idea.YandexGPT/.idea/vcs.xml | 6 ++++++ YandexGPT.CLI/Program.cs | 24 +++++++++++++++++++-- YandexGPT.CLI/Services/YandexGptService.cs | 21 ++++++++++++++++++ YandexGPT.CLI/YandexGPT.CLI.csproj | 5 +++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .idea/.idea.YandexGPT/.idea/indexLayout.xml create mode 100644 .idea/.idea.YandexGPT/.idea/vcs.xml create mode 100644 YandexGPT.CLI/Services/YandexGptService.cs diff --git a/.idea/.idea.YandexGPT/.idea/indexLayout.xml b/.idea/.idea.YandexGPT/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.YandexGPT/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.YandexGPT/.idea/vcs.xml b/.idea/.idea.YandexGPT/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.YandexGPT/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/YandexGPT.CLI/Program.cs b/YandexGPT.CLI/Program.cs index e5dff12..9744e5e 100644 --- a/YandexGPT.CLI/Program.cs +++ b/YandexGPT.CLI/Program.cs @@ -1,3 +1,23 @@ -// See https://aka.ms/new-console-template for more information +using OpenAI.Chat; +using OpenAI.RealtimeConversation; +using YandexGPT.CLI.Services; + +Console.WriteLine("Let's start!"); + +var service = new YandexGptService(); +var client = service.CreateClient(); +var chat = client.GetChatClient("gpt://b1gg9b7e74q248tvan7f/yandexgpt/latest"); + + +var query = Console.ReadLine();; +while (query is not ("exit" and "quit")) +{ + var message = ChatMessage.CreateUserMessage(query); + var response = chat.CompleteChat(message); + foreach (var row in response.Value.Content) + { + Console.WriteLine(row.Text); + } + query = Console.ReadLine(); +} -Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/YandexGPT.CLI/Services/YandexGptService.cs b/YandexGPT.CLI/Services/YandexGptService.cs new file mode 100644 index 0000000..5fc456f --- /dev/null +++ b/YandexGPT.CLI/Services/YandexGptService.cs @@ -0,0 +1,21 @@ +using System.ClientModel; +using OpenAI; + +namespace YandexGPT.CLI.Services; + +public class YandexGptService +{ + + public OpenAIClient CreateClient() + { + var options = new OpenAI.OpenAIClientOptions() + { + Endpoint = new Uri("https://llm.api.cloud.yandex.net/v1") + }; + var credential = new ApiKeyCredential("AQVN1a58GEuuJPE4-cQptps_j35i0DRAvx8d8VJN"); + var client = new OpenAI.OpenAIClient(credential, options); + + + return client; + } +} \ No newline at end of file diff --git a/YandexGPT.CLI/YandexGPT.CLI.csproj b/YandexGPT.CLI/YandexGPT.CLI.csproj index 2f4fc77..4d80193 100644 --- a/YandexGPT.CLI/YandexGPT.CLI.csproj +++ b/YandexGPT.CLI/YandexGPT.CLI.csproj @@ -7,4 +7,9 @@ enable + + + + +