Skip to content

Commit f85c4ae

Browse files
committed
Put each service in its own namespace, remove the old search code completely, and clean up a couple bugs including result Created datetime null value handling
1 parent 8f1bac8 commit f85c4ae

17 files changed

+51
-347
lines changed

OpenAI_API/ApiResultBase.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using OpenAI_API.Models;
23
using System;
34

45
namespace OpenAI_API
@@ -11,13 +12,13 @@ abstract public class ApiResultBase
1112

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

1617
/// <summary>
1718
/// The time when the result was generated in unix epoch format
1819
/// </summary>
1920
[JsonProperty("created")]
20-
public int CreatedUnixTime { get; set; }
21+
public long? CreatedUnixTime { get; set; }
2122

2223
/// <summary>
2324
/// Which model was used to generate this result.

OpenAI_API/Completions/CompletionEndpoint.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
using System.Collections.Generic;
33
using System.Net.Http;
44
using System.Threading.Tasks;
5+
using OpenAI_API.Models;
56

6-
namespace OpenAI_API
7+
namespace OpenAI_API.Completions
78
{
89
/// <summary>
910
/// 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).

OpenAI_API/Completions/CompletionRequest.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using Newtonsoft.Json;
2+
using OpenAI_API.Models;
23
using System.Linq;
34

4-
namespace OpenAI_API
5+
namespace OpenAI_API.Completions
56
{
67
/// <summary>
78
/// 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.
@@ -12,7 +13,7 @@ public class CompletionRequest
1213
/// 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"/>.
1314
/// </summary>
1415
[JsonProperty("model")]
15-
public string Model { get; set; } = OpenAI_API.Model.DavinciText;
16+
public string Model { get; set; } = OpenAI_API.Models.Model.DavinciText;
1617

1718
/// <summary>
1819
/// This is only used for serializing the request into JSON, do not use it directly.
@@ -165,7 +166,7 @@ public string StopSequence
165166
/// </summary>
166167
public CompletionRequest()
167168
{
168-
this.Model = OpenAI_API.Model.DefaultModel;
169+
this.Model = OpenAI_API.Models.Model.DefaultModel;
169170
}
170171

171172
/// <summary>

OpenAI_API/Completions/CompletionResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Newtonsoft.Json;
22
using System.Collections.Generic;
33

4-
namespace OpenAI_API
4+
namespace OpenAI_API.Completions
55
{
66
/// <summary>
77
/// Represents a completion choice returned by the Completion API.

OpenAI_API/Embedding/EmbeddingEndpoint.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using OpenAI_API.Models;
2+
using System.Threading.Tasks;
23

34
namespace OpenAI_API.Embedding
45
{

OpenAI_API/Embedding/EmbeddingRequest.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using OpenAI_API.Models;
23

34
namespace OpenAI_API.Embedding
45
{
@@ -44,7 +45,7 @@ public EmbeddingRequest(Model model, string input)
4445
/// <param name="input">The prompt to transform</param>
4546
public EmbeddingRequest(string input)
4647
{
47-
Model = OpenAI_API.Model.AdaTextEmbedding;
48+
Model = OpenAI_API.Models.Model.AdaTextEmbedding;
4849
this.Input = input;
4950
}
5051
}

OpenAI_API/Model/Model.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.Generic;
44
using System.Threading.Tasks;
55

6-
namespace OpenAI_API
6+
namespace OpenAI_API.Models
77
{
88
/// <summary>
99
/// Represents a language model
@@ -30,13 +30,13 @@ public class Model
3030

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

3535
/// <summary>
3636
/// The time when the model was created in unix epoch format
3737
/// </summary>
3838
[JsonProperty("created")]
39-
public long CreatedUnixTime { get; set; }
39+
public long? CreatedUnixTime { get; set; }
4040

4141
/// <summary>
4242
/// Permissions for use of the model

OpenAI_API/Model/ModelsEndpoint.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44

5-
namespace OpenAI_API
5+
namespace OpenAI_API.Models
66
{
77
/// <summary>
88
/// The API endpoint for querying available models

OpenAI_API/OpenAIAPI.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using OpenAI_API.Files;
2-
using Newtonsoft.Json;
1+
using OpenAI_API.Completions;
32
using OpenAI_API.Embedding;
4-
using System;
3+
using OpenAI_API.Files;
4+
using OpenAI_API.Models;
55

66
namespace OpenAI_API
77
{
@@ -29,7 +29,7 @@ public OpenAIAPI(APIAuthentication apiKeys = null)
2929
this.Auth = apiKeys.ThisOrDefault();
3030
Completions = new CompletionEndpoint(this);
3131
Models = new ModelsEndpoint(this);
32-
//Search = new SearchEndpoint(this);
32+
Files = new FilesEndpoint(this);
3333
Embeddings = new EmbeddingEndpoint(this);
3434
}
3535

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

51-
/// <summary>
52-
/// 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”).
53-
/// </summary>
54-
[Obsolete("OpenAI no longer supports the Search endpoint")]
55-
public SearchEndpoint Search { get; }
56-
5751
/// <summary>
5852
/// The API lets you do operations with files. You can upload, delete or retrieve files. Files can be used for fine-tuning, search, etc.
5953
/// </summary>

OpenAI_API/Search/SearchEndpoint.cs

-196
This file was deleted.

OpenAI_API/Search/SearchRequest.cs

-35
This file was deleted.

0 commit comments

Comments
 (0)