From 273e2dc2525dc4a2676d3ec7cb88d9e34907558b Mon Sep 17 00:00:00 2001 From: mirakst Date: Wed, 8 Nov 2023 11:23:09 +0100 Subject: [PATCH] Nuked ApiAccess page and salling API client --- ChatRPG/API/IFoodWasteClient.cs | 21 --------- ChatRPG/API/SallingClient.cs | 55 ----------------------- ChatRPG/Pages/ApiAccess.razor | 78 --------------------------------- ChatRPG/Program.cs | 1 - 4 files changed, 155 deletions(-) delete mode 100644 ChatRPG/API/IFoodWasteClient.cs delete mode 100644 ChatRPG/API/SallingClient.cs delete mode 100644 ChatRPG/Pages/ApiAccess.razor diff --git a/ChatRPG/API/IFoodWasteClient.cs b/ChatRPG/API/IFoodWasteClient.cs deleted file mode 100644 index 9e9b6c7..0000000 --- a/ChatRPG/API/IFoodWasteClient.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace ChatRPG.API; - -public interface IFoodWasteClient -{ - Task> GetFoodwasteResponse(string zip); -} - -public record Offer(string Currency, double Discount, string Ean, DateTime EndTime, DateTime LastUpdate, - double NewPrice, double OriginalPrice, double PercentDiscount, DateTime StartTime, double Stock, string StockUnit); - -public record Product(string Description, string Ean, string Image); - -public record Clearance(Offer Offer, Product Product); - -public record Address(string City, string Country, string Extra, string Street, string Zip); - -public record Hour(DateOnly Date, string Type, DateTime Open, string Close, bool Closed, List CustomerFlow); - -public record Store(Address Address, string Brand, List Coordinates, List Hours, string Name, string Id, string Type); - -public record FoodWasteResponse(List Clearances, Store Store); diff --git a/ChatRPG/API/SallingClient.cs b/ChatRPG/API/SallingClient.cs deleted file mode 100644 index 824a6f4..0000000 --- a/ChatRPG/API/SallingClient.cs +++ /dev/null @@ -1,55 +0,0 @@ -using RestSharp; -using RestSharp.Authenticators; - -namespace ChatRPG.API; - -public class SallingClient : IFoodWasteClient, IDisposable -{ - private const string SallingBaseUrl = "https://api.sallinggroup.com/v1/"; - private readonly ILogger _logger; - private readonly RestClient _client; - - public SallingClient(ILogger logger, IConfiguration configuration) - { - _logger = logger; - - var options = new RestClientOptions(SallingBaseUrl) - { - Authenticator = new JwtAuthenticator(configuration.GetSection("ApiKeys").GetValue("Salling")), - FailOnDeserializationError = false - }; - _client = new RestClient(options); - } - - public async Task> GetFoodwasteResponse(string zip) - { - var request = new RestRequest("food-waste/", Method.Get); - request.AddQueryParameter("zip", zip); - - _logger.LogInformation(""" - Request URL: {Url} - Method: {Method} - Parameters: {Parameters} - """, - SallingBaseUrl + request.Resource, - request.Method, - string.Join(", ", request.Parameters.Select(p => $"{p.Name}={p.Value}")) - ); - - - var response = await _client.ExecuteAsync>(request); - - if (response.ErrorException != null) - { - _logger.LogError($"Error retrieving data from API: {response.ErrorException.Message}"); - } - - return response!.Data; - } - - public void Dispose() - { - _client.Dispose(); - GC.SuppressFinalize(this); - } -} diff --git a/ChatRPG/Pages/ApiAccess.razor b/ChatRPG/Pages/ApiAccess.razor deleted file mode 100644 index ff02604..0000000 --- a/ChatRPG/Pages/ApiAccess.razor +++ /dev/null @@ -1,78 +0,0 @@ -@page "/ApiAccess" -@using ChatRPG.API -@using Microsoft.IdentityModel.Tokens -@using OpenAiGptMessage = ChatRPG.API.OpenAiGptMessage -@inject ILogger Logger -@inject IOpenAiLlmClient OpenAiLlmClient; -@inject IFoodWasteClient FoodWasteClient; - -

ApiAccess

- -

OpenAI GPT 3.5 Turbo

-
- -
-
- - -@if (_openAiResponse is not null) -{ -

Response: @_openAiResponse

-} - -


- -

Salling Food-waste

-
- -
-
- - -@if (_foodWasteResponses is not null) -{ -

Stores in @_zip with food waste information:

- - @foreach (var item in _foodWasteResponses) - { -
-

@item.Store.Name, @item.Store.Address.Street

- @foreach (var clearance in item.Clearances) - { -

Produkt: @clearance.Product.Description

-
Tilbudspris: @clearance.Offer.NewPrice, Originalpris: @clearance.Offer.OriginalPrice
- -
- } -
-
- } -} -@code { - private string _input; - private string _openAiResponse; - private string _zip; - private List _foodWasteResponses; - - private async Task OpenAiInput(Microsoft.AspNetCore.Components.ChangeEventArgs patharg) - { - _input = (string)patharg.Value; - } - - private async Task CallOpenAiApiWithInput() - { - var input = new List { new ("user", _input) }; - - _openAiResponse = await OpenAiLlmClient.GetChatCompletion(input); - } - - private async Task SallingInput(Microsoft.AspNetCore.Components.ChangeEventArgs patharg) - { - _zip = (string)patharg.Value; - } - - private async Task CallFoodWasteApiWithZip() - { - _foodWasteResponses = await FoodWasteClient.GetFoodwasteResponse(_zip); - } -} diff --git a/ChatRPG/Program.cs b/ChatRPG/Program.cs index ebd8236..8931ebe 100644 --- a/ChatRPG/Program.cs +++ b/ChatRPG/Program.cs @@ -26,7 +26,6 @@ .AddSingleton(httpMessageHandlerFactory) .AddSingleton() .AddSingleton() - .AddSingleton() .AddTransient(); builder.Services.Configure(options =>