Skip to content

Commit

Permalink
Put each service in its own namespace, remove the old search code com…
Browse files Browse the repository at this point in the history
…pletely, and clean up a couple bugs including result Created datetime null value handling
  • Loading branch information
OkGoDoIt committed Feb 3, 2023
1 parent 8f1bac8 commit f85c4ae
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 347 deletions.
5 changes: 3 additions & 2 deletions OpenAI_API/ApiResultBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OpenAI_API.Models;
using System;

namespace OpenAI_API
Expand All @@ -11,13 +12,13 @@ abstract public class ApiResultBase

/// The time when the result was generated
[JsonIgnore]
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime).DateTime;
public DateTime? Created => CreatedUnixTime.HasValue ? (DateTime?)(DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime.Value).DateTime) : null;

/// <summary>
/// The time when the result was generated in unix epoch format
/// </summary>
[JsonProperty("created")]
public int CreatedUnixTime { get; set; }
public long? CreatedUnixTime { get; set; }

/// <summary>
/// Which model was used to generate this result.
Expand Down
3 changes: 2 additions & 1 deletion OpenAI_API/Completions/CompletionEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using OpenAI_API.Models;

namespace OpenAI_API
namespace OpenAI_API.Completions
{
/// <summary>
/// Text generation is the core function of the API. You give the API a prompt, and it generates a completion. The way you “program” the API to do a task is by simply describing the task in plain english or providing a few written examples. This simple approach works for a wide range of use cases, including summarization, translation, grammar correction, question answering, chatbots, composing emails, and much more (see the prompt library for inspiration).
Expand Down
7 changes: 4 additions & 3 deletions OpenAI_API/Completions/CompletionRequest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Newtonsoft.Json;
using OpenAI_API.Models;
using System.Linq;

namespace OpenAI_API
namespace OpenAI_API.Completions
{
/// <summary>
/// Represents a request to the Completions API. Mostly matches the parameters in <see href="https://beta.openai.com/api-ref#create-completion-post">the OpenAI docs</see>, although some have been renames or expanded into single/multiple properties for ease of use.
Expand All @@ -12,7 +13,7 @@ public class CompletionRequest
/// ID of the model to use. You can use <see cref="ModelsEndpoint.GetModelsAsync()"/> to see all of your available models, or use a standard model like <see cref="Model.DavinciText"/>.
/// </summary>
[JsonProperty("model")]
public string Model { get; set; } = OpenAI_API.Model.DavinciText;
public string Model { get; set; } = OpenAI_API.Models.Model.DavinciText;

/// <summary>
/// This is only used for serializing the request into JSON, do not use it directly.
Expand Down Expand Up @@ -165,7 +166,7 @@ public string StopSequence
/// </summary>
public CompletionRequest()
{
this.Model = OpenAI_API.Model.DefaultModel;
this.Model = OpenAI_API.Models.Model.DefaultModel;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenAI_API/Completions/CompletionResult.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace OpenAI_API
namespace OpenAI_API.Completions
{
/// <summary>
/// Represents a completion choice returned by the Completion API.
Expand Down
3 changes: 2 additions & 1 deletion OpenAI_API/Embedding/EmbeddingEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using OpenAI_API.Models;
using System.Threading.Tasks;

namespace OpenAI_API.Embedding
{
Expand Down
3 changes: 2 additions & 1 deletion OpenAI_API/Embedding/EmbeddingRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OpenAI_API.Models;

namespace OpenAI_API.Embedding
{
Expand Down Expand Up @@ -44,7 +45,7 @@ public EmbeddingRequest(Model model, string input)
/// <param name="input">The prompt to transform</param>
public EmbeddingRequest(string input)
{
Model = OpenAI_API.Model.AdaTextEmbedding;
Model = OpenAI_API.Models.Model.AdaTextEmbedding;
this.Input = input;
}
}
Expand Down
6 changes: 3 additions & 3 deletions OpenAI_API/Model/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenAI_API
namespace OpenAI_API.Models
{
/// <summary>
/// Represents a language model
Expand All @@ -30,13 +30,13 @@ public class Model

/// The time when the model was created
[JsonIgnore]
public DateTime Created => DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime).DateTime;
public DateTime? Created => CreatedUnixTime.HasValue ? (DateTime?)(DateTimeOffset.FromUnixTimeSeconds(CreatedUnixTime.Value).DateTime) : null;

/// <summary>
/// The time when the model was created in unix epoch format
/// </summary>
[JsonProperty("created")]
public long CreatedUnixTime { get; set; }
public long? CreatedUnixTime { get; set; }

/// <summary>
/// Permissions for use of the model
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 @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenAI_API
namespace OpenAI_API.Models
{
/// <summary>
/// The API endpoint for querying available models
Expand Down
14 changes: 4 additions & 10 deletions OpenAI_API/OpenAIAPI.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OpenAI_API.Files;
using Newtonsoft.Json;
using OpenAI_API.Completions;
using OpenAI_API.Embedding;
using System;
using OpenAI_API.Files;
using OpenAI_API.Models;

namespace OpenAI_API
{
Expand Down Expand Up @@ -29,7 +29,7 @@ public OpenAIAPI(APIAuthentication apiKeys = null)
this.Auth = apiKeys.ThisOrDefault();
Completions = new CompletionEndpoint(this);
Models = new ModelsEndpoint(this);
//Search = new SearchEndpoint(this);
Files = new FilesEndpoint(this);
Embeddings = new EmbeddingEndpoint(this);
}

Expand All @@ -48,12 +48,6 @@ public OpenAIAPI(APIAuthentication apiKeys = null)
/// </summary>
public ModelsEndpoint Models { get; }

/// <summary>
/// The API lets you do semantic search over documents. This means that you can provide a query, such as a natural language question or a statement, and find documents that answer the question or are semantically related to the statement. The “documents” can be words, sentences, paragraphs or even longer documents. For example, if you provide documents "White House", "hospital", "school" and query "the president", you’ll get a different similarity score for each document. The higher the similarity score, the more semantically similar the document is to the query (in this example, “White House” will be most similar to “the president”).
/// </summary>
[Obsolete("OpenAI no longer supports the Search endpoint")]
public SearchEndpoint Search { get; }

/// <summary>
/// The API lets you do operations with files. You can upload, delete or retrieve files. Files can be used for fine-tuning, search, etc.
/// </summary>
Expand Down
196 changes: 0 additions & 196 deletions OpenAI_API/Search/SearchEndpoint.cs

This file was deleted.

35 changes: 0 additions & 35 deletions OpenAI_API/Search/SearchRequest.cs

This file was deleted.

Loading

0 comments on commit f85c4ae

Please sign in to comment.