Skip to content

Commit

Permalink
Dependency Injection (#7)
Browse files Browse the repository at this point in the history
* Added IChatGPTClient interface method for:
StreamFineTuneEventsAsync
DownloadImageAsync

* Refined azure function deployment process.

* Securing storage account.

* bicep updates

* Tweaking bicep template and testing deployment.

* Loosening bicep storage security.

* Enabled DI with ChatGPTClient.

* Added and testing Dependency Injection.
Validated bicep deployment scripts.
Incremented to version 1.2.0

* Disabled public blob access on the storage container.
  • Loading branch information
johniwasz committed Jan 8, 2023
1 parent 9d3a437 commit 35dd892
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 329 deletions.
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

# Whetstone.ChatGPT

A simple light-weight library that wraps ChatGPT API completions.

This library includes quality of life improvements:

- including support for __CancellationTokens__
- documentation comments
- conversions of Unix Epoch time to DateTime, etc.
- __IChatGPTClient__ interface for use with dependency injection
- Streaming completion responses and fine tune events
A simple light-weight library that wraps ChatGPT API completions with support for dependency injection.

Supported features include:

Expand All @@ -21,6 +13,35 @@ Supported features include:
- Images
- Embeddings
- Moderations
- Response streaming

[Examples](https://github.com/johniwasz/whetstone.chatgpt/tree/main/src/examples) include:

- Command line bot
- Azure Function Twitter Webhook that responds to DMs

## Dependency Injection Quickstart

```C#
services.Configure<ChatGPTCredentials>(options =>
{
options.ApiKey = "YOURAPIKEY";
options.Organization = "YOURORGANIZATIONID";
});
```

Use:
```C#
services.AddHttpClient();
```
OR:
```C#
services.AddHttpClient<IChatGPTClient, ChatGPTClient>();
```
Configure `IChatGPTClient` service:
```C#
services.AddScoped<IChatGPTClient, ChatGPTClient>();
```

## Completion

Expand Down
7 changes: 2 additions & 5 deletions src/Whetstone.ChatGPT.Test/ImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public async Task GenerateImageAsync()
ChatGPTCreateImageRequest imageRequest = new()
{
Prompt = "A sail boat",
Size = CreatedImageSize.Size1024,
Size = CreatedImageSize.Size256,
ResponseFormat = CreatedImageFormat.Url
};


using (ChatGPTClient client = (ChatGPTClient)ChatGPTTestUtilties.GetClient())
using (IChatGPTClient client = ChatGPTTestUtilties.GetClient())
{
ChatGPTImageResponse? imageResponse = await client.CreateImageAsync(imageRequest);

Expand All @@ -43,9 +43,6 @@ public async Task GenerateImageAsync()

Assert.True(imageBytes.Length > 0);
File.WriteAllBytes("sailboat.png", imageBytes);



}
}

Expand Down
Loading

0 comments on commit 35dd892

Please sign in to comment.