Skip to content

Commit

Permalink
Merge pull request #53 from jodendaal/CorrectNamingOfVariables
Browse files Browse the repository at this point in the history
Correct naming of variables
  • Loading branch information
jodendaal authored Mar 20, 2023
2 parents f83aae0 + 2fe5990 commit c0b2ad3
Show file tree
Hide file tree
Showing 50 changed files with 559 additions and 545 deletions.
4 changes: 2 additions & 2 deletions examples/Blazor/BlazorApp/Data/ChatInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public class ChatInfo
{
public string Message { get; set; }
public string User { get; set; }
public string Message { get; set; } = "";
public string User { get; set; } = "";
}

}
6 changes: 3 additions & 3 deletions examples/Blazor/BlazorApp/Data/SearchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace BlazorApp.Data
public class SearchModel
{
[Required]
public string SearchText { get; set; }
public string SearchText { get; set; } = "";

[Required]
public int NoOfResults { get; set; } = 2;

[Required]
public int MaxTokens { get; set; } = 200;

public string System { get; set; }
public string System { get; set; } = "";

public string Assistant { get; set; }
public string Assistant { get; set; } = "";
}

}
3 changes: 1 addition & 2 deletions examples/Blazor/BlazorApp/Pages/Chat.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
background-color: rgba(68,70,84,var(--tw-bg-opacity));
color: white;
border: none;
rgba(32,33,35,.5);
border-top-color: rgba(32, 33, 35, 0.5);
border-right-color: rgba(32, 33, 35, 0.5);
border-bottom-color: rgba(32, 33, 35, 0.5);
Expand All @@ -124,7 +123,7 @@
background-color: rgba(68,70,84,var(--tw-bg-opacity));
color: white;
border: none;
rgba(32,33,35,.5);

border-top-color: rgba(32, 33, 35, 0.5);
border-right-color: rgba(32, 33, 35, 0.5);
border-bottom-color: rgba(32, 33, 35, 0.5);
Expand Down
2 changes: 1 addition & 1 deletion examples/Blazor/BlazorApp/Pages/TextCompletion.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
o.MaxTokens = searchModel.MaxTokens;
}))
{
var index = result.Result.Choices[0].Index;
var index = result.Result!.Choices[0].Index;
results[index] += result.Result.Choices[0].Text;

loopCount++;
Expand Down
4 changes: 2 additions & 2 deletions examples/Console/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ static async Task Main(string[] args)
})
.Build();

var openAi = host.Services.GetService<IOpenAIService>();
var openAi = host.Services.GetService<IOpenAIService>()!;
var response = await openAi.TextCompletion.Get("How long until we reach mars?");

if (response.IsSuccess)
{
foreach(var result in response.Result.Choices)
foreach(var result in response.Result!.Choices)
{
Console.WriteLine(result.Text);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Console/ConsoleAppWithPolly/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ static async Task Main(string[] args)
})
.Build();

var openAi = host.Services.GetService<IOpenAIService>();
var openAi = host.Services.GetRequiredService<IOpenAIService>();
var response = await openAi.TextCompletion.Get("How long until we reach mars?");

if (response.IsSuccess)
{
foreach (var result in response.Result.Choices)
foreach (var result in response.Result!.Choices)
{
Console.WriteLine(result.Text);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/WebApp/WebApplication/Pages/GenerateImage.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class GenerateImageModel : PageModel
private readonly IOpenAIService _openAIService;

public List<string> Results { get; set; } = new List<string>();
public string ErrorMessage { get; set; }
public string? ErrorMessage { get; set; }
public GenerateImageModel(ILogger<GenerateImageModel> logger,IOpenAIService openAIService)
{
_logger = logger;
Expand All @@ -33,7 +33,7 @@ public async Task OnPost()
});
if(response.IsSuccess)
{
Results = response.Result.Data.Select(i=> i.Url).ToList();
Results = response.Result!.Data.Select(i=> i.Url).ToList();
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions examples/WebApp/WebApplication/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IndexModel : PageModel
private readonly IOpenAIService _openAIService;

public List<string> Results { get; set; } = new List<string>();
public string ErrorMessage { get; set; }
public string ErrorMessage { get; set; } = "";
public IndexModel(ILogger<IndexModel> logger,IOpenAIService openAIService)
{
_logger = logger;
Expand All @@ -36,7 +36,7 @@ public async Task OnPost()
});
if(response.IsSuccess)
{
Results = response.Result.Choices.Select(i=> i.Text).ToList();
Results = response.Result!.Choices.Select(i=> i.Text).ToList();
}
else
{
Expand Down
12 changes: 7 additions & 5 deletions src/OpenAI.Net.Integration.Tests/AudioService_Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ internal class AudioService_Translations : BaseTest
public async Task GetTranslation(string model,bool isSuccess, HttpStatusCode statusCode)
{

var request = new CreateTranslationRequest(FileContentInfo.Load(@"Audio\Translation.m4a"));
request.Model = model;
var request = new CreateTranslationRequest(FileContentInfo.Load(@"Audio\Translation.m4a"))
{
Model = model
};

var response = await OpenAIService.Audio.GetTranslation(request);

Expand All @@ -22,9 +24,9 @@ public async Task GetTranslation(string model,bool isSuccess, HttpStatusCode sta
Assert.That(response.Result?.Text?.Contains("Programming") ?? false, Is.EqualTo(isSuccess), "Should contain the word Programming");
}

[TestCase(ModelTypes.Whisper1, true, HttpStatusCode.OK, TestName = "GetTranslationWithExtension_When_Success")]
[TestCase("invalid_model", false, HttpStatusCode.NotFound, TestName = "GetTranslationWithExtension_When_Fail")]
public async Task GetTranslationWithExtension(string model, bool isSuccess, HttpStatusCode statusCode)
[TestCase(true, HttpStatusCode.OK, TestName = "GetTranslationWithExtension_When_Success")]
[TestCase(false, HttpStatusCode.NotFound, TestName = "GetTranslationWithExtension_When_Fail")]
public async Task GetTranslationWithExtension(bool isSuccess, HttpStatusCode statusCode)
{

var response = await OpenAIService.Audio.GetTranslation(@"Audio\Translation.m4a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Get(string model, bool isSuccess, HttpStatusCode statusCode)
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (isSuccess)
{
Assert.That(response.Result?.Choices.FirstOrDefault().Message.Content, Is.EqualTo("\n\nThis is a test."), "Choices are not mapped correctly");
Assert.That(response.Result!.Choices.FirstOrDefault()!.Message.Content, Is.EqualTo("\n\nThis is a test."), "Choices are not mapped correctly");
}
}

Expand All @@ -53,7 +53,7 @@ public async Task GetWithListExtension(string model, bool isSuccess, HttpStatusC
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (isSuccess)
{
Assert.That(response.Result?.Choices.FirstOrDefault().Message.Content.Contains("Globe Life Field"), Is.EqualTo(true), "Incorrect answer");
Assert.That(response.Result?.Choices?.FirstOrDefault()?.Message.Content.Contains("Globe Life Field"), Is.EqualTo(true), "Incorrect answer");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public async Task GetStream()
var message = Message.Create(ChatRoleType.User, prompt);
var request = new ChatCompletionRequest(message);

await foreach(var t in OpenAIService.Chat.GetStream(request))
await foreach(var response in OpenAIService.Chat.GetStream(request))
{
Console.WriteLine(t?.Result?.Choices[0].Delta?.Content);
Assert.True(t.IsSuccess, "Failed to get chat stream", t.ErrorMessage);
Console.WriteLine(response?.Result?.Choices[0].Delta?.Content);
Assert.True(response?.IsSuccess, "Failed to get chat stream", response?.ErrorMessage);
}
}

Expand All @@ -29,10 +29,10 @@ public async Task GetStreamWithListExtension()
Message.Create(ChatRoleType.User, "Where was it played?")
};

await foreach (var t in OpenAIService.Chat.GetStream(messages))
await foreach (var response in OpenAIService.Chat.GetStream(messages))
{
Console.WriteLine(t?.Result?.Choices[0].Delta?.Content);
Assert.True(t.IsSuccess, "Failed to get chat stream", t.ErrorMessage);
Console.WriteLine(response?.Result?.Choices[0].Delta?.Content);
Assert.True(response?.IsSuccess, "Failed to get chat stream", response?.ErrorMessage);
}
}
}
Expand Down
88 changes: 44 additions & 44 deletions src/OpenAI.Net.Integration.Tests/ImageService_Edit.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
using OpenAI.Net.Models;
using OpenAI.Net.Models.Requests;
using System.Net;

namespace OpenAI.Net.Integration.Tests
{
internal class ImageService_Edit : BaseTest
{
[TestCase(true, HttpStatusCode.OK, "256x256", TestName = "Edit_When_Success")]
[TestCase(false, HttpStatusCode.BadRequest, "32x32", TestName = "Edit_When_Invalid_Size_Fail")]
public async Task Edit(bool isSuccess,HttpStatusCode statusCode, string size)
{

var image = FileContentInfo.Load(@"Images\RGBAImage.png");
var request = new ImageEditRequest("A cute baby sea otter with hat", image) { N = 1, Size = size};

var response = await OpenAIService.Images.Edit(request);

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data?.Count() == 1, Is.EqualTo(isSuccess), "Data is not mapped correctly");
Assert.That(response.Result?.Data?[0].Url?.Contains("https://"), isSuccess ? Is.EqualTo(isSuccess) : Is.EqualTo(null), "Choice text not set");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true), "Error message not returned");
}

[TestCase(true, HttpStatusCode.OK, "256x256",TestName = "EditWithMask_When_Success")]
[TestCase(false, HttpStatusCode.BadRequest, "32x32", TestName = "EditWithMask_When_Invalid_Size_Fail")]
public async Task EditWithMask(bool isSuccess, HttpStatusCode statusCode, string size)
{

var image = FileContentInfo.Load(@"Images\BabyCat.png");
var mask = FileContentInfo.Load(@"Images\RGBAImage.png");
var request = new ImageEditRequest("A cute baby sea otter with hat", image) { N = 1, Size = size, Mask = mask };

var response = await OpenAIService.Images.Edit(request);

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data?.Count() == 1, Is.EqualTo(isSuccess), "Data is not mapped correctly");
Assert.That(response.Result?.Data?[0].Url?.Contains("https://"), isSuccess ? Is.EqualTo(isSuccess) : Is.EqualTo(null), "Choice text not set");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true), "Error message not returned");
}
}
}
using OpenAI.Net.Models;
using OpenAI.Net.Models.Requests;
using System.Net;

namespace OpenAI.Net.Integration.Tests
{
internal class ImageService_Edit : BaseTest
{
[TestCase(true, HttpStatusCode.OK, "256x256", TestName = "Edit_When_Success")]
[TestCase(false, HttpStatusCode.BadRequest, "32x32", TestName = "Edit_When_Invalid_Size_Fail")]
public async Task Edit(bool isSuccess,HttpStatusCode statusCode, string size)
{

var image = FileContentInfo.Load(@"Images\RGBAImage.png");
var request = new ImageEditRequest("A cute baby sea otter with hat", image) { N = 1, Size = size};

var response = await OpenAIService.Images.Edit(request);

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data?.Count() == 1, Is.EqualTo(isSuccess), "Data is not mapped correctly");
Assert.That(response.Result?.Data?[0].Url?.Contains("https://"), isSuccess ? Is.EqualTo(isSuccess) : Is.EqualTo(null), "Choice text not set");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true), "Error message not returned");
}

[TestCase(true, HttpStatusCode.OK, "256x256",TestName = "EditWithMask_When_Success")]
[TestCase(false, HttpStatusCode.BadRequest, "32x32", TestName = "EditWithMask_When_Invalid_Size_Fail")]
public async Task EditWithMask(bool isSuccess, HttpStatusCode statusCode, string size)
{

var image = FileContentInfo.Load(@"Images\BabyCat.png");
var mask = FileContentInfo.Load(@"Images\RGBAImage.png");
var request = new ImageEditRequest("A cute baby sea otter with hat", image) { N = 1, Size = size, Mask = mask };

var response = await OpenAIService.Images.Edit(request);

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data?.Count() == 1, Is.EqualTo(isSuccess), "Data is not mapped correctly");
Assert.That(response.Result?.Data?[0].Url?.Contains("https://"), isSuccess ? Is.EqualTo(isSuccess) : Is.EqualTo(null), "Choice text not set");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true), "Error message not returned");
}
}
}
30 changes: 15 additions & 15 deletions src/OpenAI.Net.Integration.Tests/TextCompletionService_Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public async Task Get(string model,bool isSuccess, HttpStatusCode statusCode, bo

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
Assert.That(response.Result?.Choices?.Length == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (echo.HasValue && isSuccess)
{
var containsPrompt = response.Result.Choices[0].Text.Contains("Say this is a test");
Assert.IsTrue(containsPrompt, "Prompt not returned when Echo was true");
Assert.That(containsPrompt, Is.True, "Prompt not returned when Echo was true");
}
else if(isSuccess)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ public async Task GetExtension(string model, bool isSuccess, HttpStatusCode stat

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
Assert.That(response.Result?.Choices?.Length == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (echo.HasValue && isSuccess)
{
Assert.That(response.Result.Choices[0].Text.Contains("Say this is a test"), Is.EqualTo(echo), "Prompt not returned when Echo was true");
Expand All @@ -69,10 +69,10 @@ public async Task GetExtension(string model, bool isSuccess, HttpStatusCode stat
}


[TestCase(ModelTypes.TextDavinci003, true, HttpStatusCode.OK, null, TestName = "GetList_When_Success")]
[TestCase("invalid_model", false, HttpStatusCode.NotFound, false, TestName = "GetList_When_Fail")]
public async Task GetListExtension(string model, bool isSuccess, HttpStatusCode statusCode, bool? echo)
{
[TestCase(ModelTypes.TextDavinci003, true, HttpStatusCode.OK, TestName = "GetList_When_Success")]
[TestCase("invalid_model", false, HttpStatusCode.NotFound, TestName = "GetList_When_Fail")]
public async Task GetListExtension(string model, bool isSuccess, HttpStatusCode statusCode)
{
var request = new TextCompletionRequest(model, "Say this is a test");

var prompts = new List<string>()
Expand All @@ -84,13 +84,13 @@ public async Task GetListExtension(string model, bool isSuccess, HttpStatusCode
var response = await OpenAIService.TextCompletion.Get(model, prompts, (o) => {
o.MaxTokens = 1024;
o.BestOf = 2;
});


Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response?.Result?.Choices?.Count() == 2, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
//NB Note thatn when using array as input, echo does not seem to work.
}
});
Assert.Multiple(() =>
{
Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response?.Result?.Choices?.Length == 2, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ public async Task Test_ToMultipartFormDataContent()
var stringData = await formDataContent.ReadAsStringAsync();
var fileName = formDataContent.Headers?.ContentDisposition?.FileName?.Replace(@"""", "");

Assert.NotNull(stringData);
Assert.NotNull(bytes.Length > 1);
Assert.NotNull(formDataContent);
Assert.That(stringData, Is.Not.Null);
Assert.That(bytes.Length > 1, Is.True);
Assert.That(formDataContent, Is.Not.Null);
Assert.That(stringData.Contains(@"Content-Disposition: form-data; name=image; filename=""@image.png"";"),Is.EqualTo(true));
Assert.That(stringData.Contains(@"Content-Disposition: form-data; name=mask; filename=""@image2.png"";"), Is.EqualTo(true));
Assert.That(stringData.Contains(@"Content-Disposition: form-data; name=prompt"), Is.EqualTo(true));
Expand All @@ -229,15 +229,15 @@ public async Task Test_ToHttpContent()
var testNull = ObjectExtensions.ToHttpContent(null);
var testNullRead = await testNull.ReadAsStringAsync();

Assert.NotNull(bytesContent);
Assert.That(bytesContent, Is.Not.Null);
Assert.That(bytesContent.GetType(), Is.EqualTo(typeof(ByteArrayContent)));
Assert.That(bytesRead, Is.EqualTo(bytesValue));

Assert.NotNull(stringContent);
Assert.That(stringContent, Is.Not.Null);
Assert.That(stringContent.GetType(), Is.EqualTo(typeof(StringContent)));
Assert.That(stringRead, Is.EqualTo(stringValue));

Assert.NotNull(testNull);
Assert.That(testNull, Is.Not.Null);
Assert.That(testNull.GetType(), Is.EqualTo(typeof(StringContent)));
Assert.That(testNullRead, Is.EqualTo(""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public void ImageInfoToFileContent()

var fileContent = imageInfo.Base64ToFileContent();

Assert.NotNull(fileContent);
Assert.NotNull(fileContent.FileName);
Assert.NotNull(fileContent.FileContent);
Assert.That(fileContent, Is.Not.Null);
Assert.That(fileContent.FileName, Is.Not.Null);
Assert.That(fileContent.FileContent, Is.Not.Null);
}
}
}
Loading

0 comments on commit c0b2ad3

Please sign in to comment.