Skip to content

Commit

Permalink
Update readme, fix signing key, fix typos and spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
OkGoDoIt committed Feb 3, 2023
1 parent 0876a15 commit b66b7b6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion OpenAI_API/Completions/CompletionEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CompletionEndpoint : EndpointBase
public CompletionRequest DefaultCompletionRequestArgs { get; set; } = new CompletionRequest() { Model = Model.DavinciText };

/// <summary>
/// The name of the enpoint, which is the final path segment in the API URL. For example, "completions".
/// The name of the endpoint, which is the final path segment in the API URL. For example, "completions".
/// </summary>
protected override string Endpoint { get { return "completions"; } }

Expand Down
4 changes: 2 additions & 2 deletions OpenAI_API/EndpointBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace OpenAI_API
{
/// <summary>
/// A base object for any OpenAI API enpoint, encompassing common functionality
/// A base object for any OpenAI API endpoint, encompassing common functionality
/// </summary>
public abstract class EndpointBase
{
Expand All @@ -33,7 +33,7 @@ internal EndpointBase(OpenAIAPI api)
}

/// <summary>
/// The name of the enpoint, which is the final path segment in the API URL. Must be overriden in a derived class.
/// The name of the endpoint, which is the final path segment in the API URL. Must be overriden in a derived class.
/// </summary>
protected abstract string Endpoint { get; }

Expand Down
2 changes: 1 addition & 1 deletion OpenAI_API/Files/FilesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FilesEndpoint : EndpointBase
internal FilesEndpoint(OpenAIAPI api) : base(api) { }

/// <summary>
/// The name of the enpoint, which is the final path segment in the API URL. For example, "files".
/// The name of the endpoint, which is the final path segment in the API URL. For example, "files".
/// </summary>
protected override string Endpoint { get { return "files"; } }

Expand Down
2 changes: 1 addition & 1 deletion OpenAI_API/Model/ModelsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OpenAI_API.Models
public class ModelsEndpoint : EndpointBase
{
/// <summary>
/// The name of the enpoint, which is the final path segment in the API URL. For example, "models".
/// The name of the endpoint, which is the final path segment in the API URL. For example, "models".
/// </summary>
protected override string Endpoint { get { return "models"; } }

Expand Down
12 changes: 5 additions & 7 deletions OpenAI_API/OpenAI_API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
<RepositoryUrl>https://github.com/OkGoDoIt/OpenAI-API-dotnet</RepositoryUrl>
<PackageTags>OpenAI, AI, ML, API</PackageTags>
<Title>OpenAI API</Title>
<PackageReleaseNotes>Updated to work with the current API as of January 12, 2023. Deprecate the Search endpoint as OpenAI has removed that API. This version includes breaking changes around specifying models to keep up with OpenAI API changes. If you had any code which used the old "engines", that will need to be updated to "models". Support for insertion, edits, and embedding is coming soon.</PackageReleaseNotes>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>D:\OneDrive - Roger Pincombe\Assets\rsa keys\okgodoit-signing.pfx</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<PackageReleaseNotes>Updated to work with the current API as of February 2, 2023. Added Files and Embedding endpoints. Removed the Search endpoint as OpenAI has removed that API.</PackageReleaseNotes>
<PackageId>OpenAI</PackageId>
<Version>1.3.0</Version>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<FileVersion>1.3.0.0</FileVersion>
<Version>1.4.0</Version>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
</PropertyGroup>

<ItemGroup>
Expand Down
54 changes: 48 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ A simple C# .NET wrapper library to use with OpenAI's GPT-3 API. More context [
## Status
Updated to work with the current API as of February 2, 2023. Added Files and Embedding endpoints. Removed the Search endpoint as OpenAI has removed that API.

Thank you [@GotMike](https://github.com/gotmike), [@metjuperry](https://github.com/metjuperry), and [@Alexei000](https://github.com/Alexei000) for your contributions!
Thank you [@GotMike](https://github.com/gotmike), [@gmilano](https://github.com/gmilano), [@metjuperry](https://github.com/metjuperry), and [@Alexei000](https://github.com/Alexei000) for your contributions!

## Quick Example

```csharp
var api = new OpenAI_API.OpenAIAPI();

var result = await api.Completions.CreateCompletionAsync("One Two Three One Two", temperature: 0.1);
Console.WriteLine(result.ToString());
var result = await api.Completions.GetCompletion("One Two Three One Two");
Console.WriteLine(result);
// should print something starting with "Three"
```

Expand Down Expand Up @@ -66,7 +66,7 @@ OpenAIAPI api = new OpenAIAPI(new APIAuthentication("YOUR_API_KEY","org-yourOrgH
The Completion API is accessed via `OpenAIAPI.Completions`:

```csharp
CreateCompletionAsync(CompletionRequest request)
async Task<CompletionResult> CreateCompletionAsync(CompletionRequest request)

// for example
var result = await api.Completions.CreateCompletionAsync(new CompletionRequest("One Two Three One Two", model: Model.CurieText, temperature: 0.1));
Expand All @@ -92,17 +92,59 @@ await foreach (var token in api.Completions.StreamCompletionEnumerableAsync(new

Or if using classic .NET framework or C# <8.0:
```csharp
StreamCompletionAsync(CompletionRequest request, Action<CompletionResult> resultHandler)
async Task StreamCompletionAsync(CompletionRequest request, Action<CompletionResult> resultHandler)

// for example
await api.Completions.StreamCompletionAsync(
new CompletionRequest("My name is Roger and I am a principal software engineer at Salesforce. This is my resume:", Model.DavinciText, 200, 0.5, presencePenalty: 0.1, frequencyPenalty: 0.1),
res => ResumeTextbox.Text += res.ToString());
```

### Embeddings
The Embedding API is accessed via `OpenAIAPI.Embeddings`:

```csharp
async Task<EmbeddingResult> CreateEmbeddingAsync(EmbeddingRequest request)

// for example
var result = await api.Embeddings.CreateEmbeddingAsync(new EmbeddingRequest("A test text for embedding", model: Model.AdaTextEmbedding));
// or
var result = await api.Completions.CreateCompletionAsync("A test text for embedding");
```

The embedding result contains a lot of metadata, the actual vector of floats is in result.Data[].Embedding.

For simplicity, you can directly ask for the vector of floats and disgard the extra metadata with `api.Embeddings.GetEmbeddingsAsync("test text here")`

### Files (for fine-tuning)
The Files API endpoint is accessed via `OpenAIAPI.Files`:

```csharp
// uploading
async Task<File> UploadFileAsync(string filePath, string purpose = "fine-tune")

// for example
var response = await api.Files.UploadFileAsync("fine-tuning-data.jsonl");
Console.Write(response.Id); //the id of the uploaded file
// listing
async Task<List<File>> GetFilesAsync()

// for example
var response = await api.Files.GetFilesAsync();
foreach (var file in response)
{
Console.WriteLine(file.Name)
}
```

There are also methods to get file contents, delete a file, etc.

The fine-tuning endpoint itself has not yet been implemented, but will be added soon.

## Documentation

Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to ping me on Twitter [@OkGoDoIt](https://twitter.com/OkGoDoIt) if you have any questions. Better documentation may come later.
Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to open an issue here if you have any questions. Better documentation may come later.

## License
![CC-0 Public Domain](https://licensebuttons.net/p/zero/1.0/88x31.png)
Expand Down

0 comments on commit b66b7b6

Please sign in to comment.