Skip to content

Commit 7602083

Browse files
authored
Merge pull request #118 from betalgo/dev
v6.7.0
2 parents fb14509 + 6a437a4 commit 7602083

22 files changed

+568
-57
lines changed
Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
<UserSecretsId>c7a3a51e-4319-4038-b522-9ed24fd5ef66</UserSecretsId>
9-
<LangVersion>latest</LangVersion>
10-
</PropertyGroup>
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<UserSecretsId>c7a3a51e-4319-4038-b522-9ed24fd5ef66</UserSecretsId>
9+
<LangVersion>latest</LangVersion>
10+
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="6.0.0" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
15-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
16-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
18-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
19-
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
20-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
21-
</ItemGroup>
12+
<ItemGroup>
13+
<None Remove="SampleData\TokenizerSample.txt" />
14+
</ItemGroup>
2215

23-
<ItemGroup>
24-
<ProjectReference Include="..\OpenAI.SDK\OpenAI.GPT3.csproj" />
25-
</ItemGroup>
16+
<ItemGroup>
17+
<Content Include="SampleData\TokenizerSample.txt">
18+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
19+
</Content>
20+
</ItemGroup>
2621

27-
<ItemGroup>
28-
<None Update="ApiSettings.json">
29-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30-
</None>
31-
<None Update="SampleData\TokenizerSample.txt">
32-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33-
</None>
34-
<None Update="SampleData\FineTuningSample1.jsonl">
35-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36-
</None>
37-
<None Update="SampleData\image_edit_mask.png">
38-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
39-
</None>
40-
<None Update="SampleData\image_edit_original.png">
41-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
42-
</None>
43-
<None Update="SampleData\SentimentAnalysisSample.jsonl">
44-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
45-
</None>
46-
</ItemGroup>
22+
<ItemGroup>
23+
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="6.0.0" />
24+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
25+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
26+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
27+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
28+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
29+
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
30+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
31+
</ItemGroup>
4732

48-
</Project>
33+
<ItemGroup>
34+
<ProjectReference Include="..\OpenAI.SDK\OpenAI.GPT3.csproj" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<None Update="ApiSettings.json">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</None>
41+
<None Update="SampleData\FineTuningSample1.jsonl">
42+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
43+
</None>
44+
<None Update="SampleData\image_edit_mask.png">
45+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46+
</None>
47+
<None Update="SampleData\image_edit_original.png">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</None>
50+
<None Update="SampleData\SentimentAnalysisSample.jsonl">
51+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
52+
</None>
53+
</ItemGroup>
54+
55+
</Project>

OpenAI.Playground/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@
3131
var serviceProvider = serviceCollection.BuildServiceProvider();
3232
var sdk = serviceProvider.GetRequiredService<IOpenAIService>();
3333

34+
// CHAT GPT
35+
// |-----------------------------------------------------------------------|
36+
// | o \ o / _ o __| \ / |__ o _ \ o / o |
37+
// | /|\ | /\ ___\o \o | o/ o/__ /\ | /|\ |
38+
// | / \ / \ | \ /) | ( \ /o\ / ) | (\ / | / \ / \ |
39+
// |-----------------------------------------------------------------------|
40+
await ChatCompletionTestHelper.RunSimpleChatCompletionTest(sdk);
41+
await ChatCompletionTestHelper.RunSimpleCompletionStreamTest(sdk);
42+
43+
3444
//await ModelTestHelper.FetchModelsTest(sdk);
3545
//await EditTestHelper.RunSimpleEditCreateTest(sdk);
3646
//await ImageTestHelper.RunSimpleCreateImageTest(sdk);
3747
//await ImageTestHelper.RunSimpleCreateImageEditTest(sdk);
3848
//await ImageTestHelper.RunSimpleCreateImageVariationTest(sdk);
3949
//await ModerationTestHelper.CreateModerationTest(sdk);
40-
await CompletionTestHelper.RunSimpleCompletionTest(sdk);
50+
//await CompletionTestHelper.RunSimpleCompletionTest(sdk);
4151
//await CompletionTestHelper.RunSimpleCompletionTest2(sdk);
4252
//await CompletionTestHelper.RunSimpleCompletionTest3(sdk);
4353
//await CompletionTestHelper.RunSimpleCompletionStreamTest(sdk);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using OpenAI.GPT3.Interfaces;
2+
using OpenAI.GPT3.ObjectModels;
3+
using OpenAI.GPT3.ObjectModels.RequestModels;
4+
5+
namespace OpenAI.Playground.TestHelpers;
6+
7+
internal static class ChatCompletionTestHelper
8+
{
9+
public static async Task RunSimpleChatCompletionTest(IOpenAIService sdk)
10+
{
11+
ConsoleExtensions.WriteLine("Chat Completion Testing is starting:", ConsoleColor.Cyan);
12+
13+
try
14+
{
15+
ConsoleExtensions.WriteLine("Chat Completion Test:", ConsoleColor.DarkCyan);
16+
var completionResult = await sdk.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
17+
{
18+
Messages = new List<ChatMessage>
19+
{
20+
ChatMessage.FromSystem("You are a helpful assistant."),
21+
ChatMessage.FromUser("Who won the world series in 2020?"),
22+
ChatMessage.FromAssistance("The Los Angeles Dodgers won the World Series in 2020."),
23+
ChatMessage.FromUser("Where was it played?")
24+
},
25+
MaxTokens = 50,
26+
Model = Models.ChatGpt3_5Turbo
27+
});
28+
29+
if (completionResult.Successful)
30+
{
31+
Console.WriteLine(completionResult.Choices.First().Message.Content);
32+
}
33+
else
34+
{
35+
if (completionResult.Error == null)
36+
{
37+
throw new Exception("Unknown Error");
38+
}
39+
40+
Console.WriteLine($"{completionResult.Error.Code}: {completionResult.Error.Message}");
41+
}
42+
}
43+
catch (Exception e)
44+
{
45+
Console.WriteLine(e);
46+
throw;
47+
}
48+
}
49+
50+
public static async Task RunSimpleCompletionStreamTest(IOpenAIService sdk)
51+
{
52+
ConsoleExtensions.WriteLine("Chat Completion Stream Testing is starting:", ConsoleColor.Cyan);
53+
try
54+
{
55+
ConsoleExtensions.WriteLine("Chat Completion Stream Test:", ConsoleColor.DarkCyan);
56+
var completionResult = sdk.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
57+
{
58+
Messages = new List<ChatMessage>
59+
{
60+
new(StaticValues.ChatMessageRoles.System, "You are a helpful assistant."),
61+
new(StaticValues.ChatMessageRoles.User, "Who won the world series in 2020?"),
62+
new(StaticValues.ChatMessageRoles.System, "The Los Angeles Dodgers won the World Series in 2020."),
63+
new(StaticValues.ChatMessageRoles.User, "Tell me a story about The Los Angeles Dodgers")
64+
},
65+
MaxTokens = 150,
66+
Model = Models.ChatGpt3_5Turbo
67+
});
68+
69+
await foreach (var completion in completionResult)
70+
{
71+
if (completion.Successful)
72+
{
73+
Console.Write(completion.Choices.First().Message.Content);
74+
}
75+
else
76+
{
77+
if (completion.Error == null)
78+
{
79+
throw new Exception("Unknown Error");
80+
}
81+
82+
Console.WriteLine($"{completion.Error.Code}: {completion.Error.Message}");
83+
}
84+
}
85+
86+
Console.WriteLine("");
87+
Console.WriteLine("Complete");
88+
}
89+
catch (Exception e)
90+
{
91+
Console.WriteLine(e);
92+
throw;
93+
}
94+
}
95+
}

OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public string ImageVariationCreate()
115115
return $"{Prefix}/images/variations{QueryString}";
116116
}
117117

118+
public string ChatCompletionCreate()
119+
{
120+
return $"{Prefix}/chat/completions{QueryString}";
121+
}
122+
118123
private string Files()
119124
{
120125
return $"{Prefix}/files{QueryString}";

OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ internal interface IOpenAiEndpointProvider
2121
string ImageCreate();
2222
string ImageEditCreate();
2323
string ImageVariationCreate();
24+
string ChatCompletionCreate();
2425
}

OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public string CompletionCreate()
2424
return $"/{_apiVersion}/completions";
2525
}
2626

27+
public string ChatCompletionCreate()
28+
{
29+
return $"/{_apiVersion}/chat/completions";
30+
}
31+
2732
public string EditCreate()
2833
{
2934
return $"/{_apiVersion}/edits";
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using OpenAI.GPT3.ObjectModels;
2+
using OpenAI.GPT3.ObjectModels.RequestModels;
3+
using OpenAI.GPT3.ObjectModels.ResponseModels;
4+
5+
namespace OpenAI.GPT3.Interfaces;
6+
7+
/// <summary>
8+
/// Given a chat conversation, the model will return a chat completion response.
9+
/// </summary>
10+
public interface IChatCompletionService
11+
{
12+
/// <summary>
13+
/// Creates a completion for the chat message
14+
/// </summary>
15+
/// <param name="modelId">ID of the model to use. Currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported.</param>
16+
/// <param name="chatCompletionCreate"></param>
17+
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
18+
/// <returns></returns>
19+
Task<ChatCompletionCreateResponse> CreateCompletion(ChatCompletionCreateRequest chatCompletionCreate, string? modelId = null, CancellationToken cancellationToken = default);
20+
21+
/// <summary>
22+
/// Creates a new completion for the provided prompt and parameters and returns a stream of CompletionCreateRequests
23+
/// </summary>
24+
/// <param name="modelId">The ID of the model to use for this request</param>
25+
/// <param name="chatCompletionCreate"></param>
26+
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
27+
/// <returns></returns>
28+
IAsyncEnumerable<ChatCompletionCreateResponse> CreateCompletionAsStream(ChatCompletionCreateRequest chatCompletionCreate, string? modelId = null, CancellationToken cancellationToken = default);
29+
30+
/// <summary>
31+
/// Creates a new completion for the provided prompt and parameters
32+
/// </summary>
33+
/// <param name="createCompletionModel"></param>
34+
/// <param name="modelId">The ID of the model to use for this request</param>
35+
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
36+
/// <returns></returns>
37+
Task<ChatCompletionCreateResponse> Create(ChatCompletionCreateRequest chatCompletionCreate, Models.Model modelId, CancellationToken cancellationToken = default)
38+
{
39+
return CreateCompletion(chatCompletionCreate, modelId.EnumToString(), cancellationToken);
40+
}
41+
}

OpenAI.SDK/Interfaces/IFileService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public interface IFileService
2727
/// <param name="fileName">Name of file</param>
2828
/// <param name="purpose">
2929
/// The intended purpose of the uploaded documents.
30-
/// Use "fine-tune" for <a href="https://platform.openai.com/docs/api-reference/fine-tunes">Fine-tuning</a>. This allows us
30+
/// Use "fine-tune" for <a href="https://platform.openai.com/docs/api-reference/fine-tunes">Fine-tuning</a>. This
31+
/// allows us
3132
/// to validate the format of the uploaded file.
3233
/// </param>
3334
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>

OpenAI.SDK/Interfaces/IModelService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ namespace OpenAI.GPT3.Interfaces;
44

55
/// <summary>
66
/// List and describe the various models available in the API. You can refer to the
7-
/// <a href="https://platform.openai.com/docs/models">Models</a> documentation to understand what models are available and
7+
/// <a href="https://platform.openai.com/docs/models">Models</a> documentation to understand what models are available
8+
/// and
89
/// the differences between them.
910
/// </summary>
1011
public interface IModelService

OpenAI.SDK/Interfaces/IOpenAIService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public interface IOpenAIService
44
{
55
/// <summary>
66
/// List and describe the various models available in the API. You can refer to the
7-
/// <a href="https://platform.openai.com/docs/models">Models</a> documentation to understand what models are available and
7+
/// <a href="https://platform.openai.com/docs/models">Models</a> documentation to understand what models are available
8+
/// and
89
/// the differences between them.
910
/// </summary>
1011
public IModelService Models { get; }
@@ -39,6 +40,11 @@ public interface IOpenAIService
3940
/// </summary>
4041
public IEditService Edit { get; }
4142

43+
/// <summary>
44+
/// Given a chat conversation, the model will return a chat completion response.
45+
/// </summary>
46+
public IChatCompletionService ChatCompletion { get; }
47+
4248

4349
/// <summary>
4450
/// Set default model

0 commit comments

Comments
 (0)