Skip to content

Commit 074a9ae

Browse files
committed
Add and update Interfaces (for mock testing, etc) and update version to 1.6
1 parent 1adcae8 commit 074a9ae

File tree

13 files changed

+126
-72
lines changed

13 files changed

+126
-72
lines changed

OpenAI_API/Chat/ChatEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace OpenAI_API.Chat
1111
/// <summary>
1212
/// ChatGPT API endpoint. Use this endpoint to send multiple messages and carry on a conversation.
1313
/// </summary>
14-
public class ChatEndpoint : EndpointBase
14+
public class ChatEndpoint : EndpointBase, IChatEndpoint
1515
{
1616
/// <summary>
1717
/// This allows you to set default parameters for every request, for example to set a default temperature or max tokens. For every request, if you do not have a parameter set on the request but do have it set here as a default, the request will automatically pick up the default value.

OpenAI_API/Chat/IChatEndpoint.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using OpenAI_API.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
namespace OpenAI_API.Chat
7+
{
8+
/// <summary>
9+
/// An interface for <see cref="ChatEndpoint"/>, for ease of mock testing, etc
10+
/// </summary>
11+
public interface IChatEndpoint
12+
{
13+
ChatRequest DefaultChatRequestArgs { get; set; }
14+
15+
Task<ChatResult> CreateChatCompletionAsync(ChatRequest request);
16+
Task<ChatResult> CreateChatCompletionAsync(ChatRequest request, int numOutputs = 5);
17+
Task<ChatResult> CreateChatCompletionAsync(IList<ChatMessage> messages, Model model = null, double? temperature = null, double? top_p = null, int? numOutputs = null, int? max_tokens = null, double? frequencyPenalty = null, double? presencePenalty = null, IReadOnlyDictionary<string, float> logitBias = null, params string[] stopSequences);
18+
Task<ChatResult> CreateChatCompletionAsync(params ChatMessage[] messages);
19+
Task<ChatResult> CreateChatCompletionAsync(params string[] userMessages);
20+
Conversation CreateConversation();
21+
Task StreamChatAsync(ChatRequest request, Action<ChatResult> resultHandler);
22+
IAsyncEnumerable<ChatResult> StreamChatEnumerableAsync(ChatRequest request);
23+
IAsyncEnumerable<ChatResult> StreamChatEnumerableAsync(IList<ChatMessage> messages, Model model = null, double? temperature = null, double? top_p = null, int? numOutputs = null, int? max_tokens = null, double? frequencyPenalty = null, double? presencePenalty = null, IReadOnlyDictionary<string, float> logitBias = null, params string[] stopSequences);
24+
Task StreamCompletionAsync(ChatRequest request, Action<int, ChatResult> resultHandler);
25+
}
26+
}

OpenAI_API/Completions/ICompletionEndpoint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
namespace OpenAI_API.Completions
77
{
8-
/// <summary>
9-
/// 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).
10-
/// </summary>
11-
public interface ICompletionEndpoint
8+
/// <summary>
9+
/// An interface for <see cref="CompletionEndpoint"/>, for ease of mock testing, etc
10+
/// </summary>
11+
public interface ICompletionEndpoint
1212
{
1313
/// <summary>
1414
/// This allows you to set default parameters for every request, for example to set a default temperature or max tokens. For every request, if you do not have a parameter set on the request but do have it set here as a default, the request will automatically pick up the default value.

OpenAI_API/Embedding/IEmbeddingEndpoint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace OpenAI_API.Embedding
44
{
5-
/// <summary>
6-
/// OpenAI’s text embeddings measure the relatedness of text strings by generating an embedding, which is a vector (list) of floating point numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.
7-
/// </summary>
8-
public interface IEmbeddingEndpoint
5+
/// <summary>
6+
/// An interface for <see cref="EmbeddingEndpoint"/>, for ease of mock testing, etc
7+
/// </summary>
8+
public interface IEmbeddingEndpoint
99
{
1010
/// <summary>
1111
/// This allows you to send request to the recommended model without needing to specify. Every request uses the <see cref="Model.AdaTextEmbedding"/> model

OpenAI_API/Files/IFilesEndpoint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
namespace OpenAI_API.Files
55
{
6-
/// <summary>
7-
/// The API endpoint for operations List, Upload, Delete, Retrieve files
8-
/// </summary>
9-
public interface IFilesEndpoint
6+
/// <summary>
7+
/// An interface for <see cref="FilesEndpoint"/>, for ease of mock testing, etc
8+
/// </summary>
9+
public interface IFilesEndpoint
1010
{
1111
/// <summary>
1212
/// Get the list of all files

OpenAI_API/IOpenAIAPI.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace OpenAI_API
77
{
8-
/// <summary>
9-
/// Entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
10-
/// </summary>
11-
public interface IOpenAIAPI
8+
/// <summary>
9+
/// An interface for <see cref="OpenAIAPI"/>, for ease of mock testing, etc
10+
/// </summary>
11+
public interface IOpenAIAPI
1212
{
1313
/// <summary>
1414
/// Base url for OpenAI
1515
/// for OpenAI, should be "https://api.openai.com/{0}/{1}"
16-
/// for Azure, should be "https://(your-resource-name).openai.azure.com/openai/deployments/(deployment-id)/{1}?api-version={0}"
16+
/// for Azure, should be "https://(your-resource-name.openai.azure.com/openai/deployments/(deployment-id)/{1}?api-version={0}"
1717
/// </summary>
1818
string ApiUrlFormat { get; set; }
1919

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Threading.Tasks;
2+
3+
namespace OpenAI_API.Images
4+
{
5+
/// <summary>
6+
/// An interface for <see cref="ImageGenerationEndpoint"/>, for ease of mock testing, etc
7+
/// </summary>
8+
public interface IImageGenerationEndpoint
9+
{
10+
Task<ImageResult> CreateImageAsync(ImageGenerationRequest request);
11+
Task<ImageResult> CreateImageAsync(string input);
12+
}
13+
}

OpenAI_API/Images/ImageGenerationEndpoint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
namespace OpenAI_API.Images
88
{
9-
/// <summary>
9+
/// <summary>
1010
/// Given a prompt and/or an input image, the model will generate a new image.
1111
/// </summary>
12-
public class ImageGenerationEndpoint : EndpointBase
13-
{
12+
public class ImageGenerationEndpoint : EndpointBase, IImageGenerationEndpoint
13+
{
1414
/// <summary>
1515
/// The name of the endpoint, which is the final path segment in the API URL. For example, "image".
1616
/// </summary>

OpenAI_API/Model/IModelsEndpoint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
namespace OpenAI_API.Models
55
{
6-
/// <summary>
7-
/// The API endpoint for querying available models
8-
/// </summary>
9-
public interface IModelsEndpoint
6+
/// <summary>
7+
/// An interface for <see cref="ModelsEndpoint"/>, for ease of mock testing, etc
8+
/// </summary>
9+
public interface IModelsEndpoint
1010
{
1111
/// <summary>
1212
/// Get details about a particular Model from the API, specifically properties such as <see cref="Model.OwnedBy"/> and permissions.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
3+
namespace OpenAI_API.Moderation
4+
{
5+
/// <summary>
6+
/// An interface for <see cref="ModerationEndpoint"/>, for ease of mock testing, etc
7+
/// </summary>
8+
public interface IModerationEndpoint
9+
{
10+
ModerationRequest DefaultModerationRequestArgs { get; set; }
11+
12+
Task<ModerationResult> CallModerationAsync(ModerationRequest request);
13+
Task<ModerationResult> CallModerationAsync(string input);
14+
}
15+
}

0 commit comments

Comments
 (0)