-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating embeddings with OpenAI API. (#104)
- Loading branch information
Showing
7 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace ChatGptNet.Models; | ||
|
||
/// <summary> | ||
/// Represents an embedding. | ||
/// </summary> | ||
public class ChatGptEmbedding | ||
{ | ||
/// <summary> | ||
/// Gets or sets the index of the embedding. | ||
/// </summary> | ||
public int Index { get; set; } = 0; | ||
|
||
/// <summary> | ||
/// Gets or sets the source object for this response. | ||
/// </summary> | ||
public string Object { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Gets or sets the embedding data | ||
/// </summary> | ||
public float[] Embedding { get; set; } = Array.Empty<float>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace ChatGptNet.Models; | ||
|
||
/// <summary> | ||
/// Represents an embedding response. | ||
/// </summary> | ||
public class ChatGptEmbeddingResponse | ||
{ | ||
/// <summary> | ||
/// Gets or sets the Id of the response. | ||
/// </summary> | ||
public string Id { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Gets or sets the source object for this response. | ||
/// </summary> | ||
public string Object { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Gets or sets the model name that has been used to generate the response. | ||
/// </summary> | ||
public string Model { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Gets or sets the error occurred during the chat completion execution, if any. | ||
/// </summary> | ||
public ChatGptError? Error { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets information about token usage. | ||
/// </summary> | ||
/// <remarks> | ||
/// The <see cref="Usage"/> property is always <see langword="null"/> when requesting response streaming with <see cref="ChatGptClient.AskStreamAsync(Guid, string, ChatGptParameters?, string?, bool, CancellationToken)"/>. | ||
/// </remarks> | ||
public ChatGptUsage? Usage { get; set; } | ||
|
||
/// <summary> | ||
/// Gets a value that determines if the response was successful. | ||
/// </summary> | ||
[MemberNotNullWhen(false, nameof(Error))] | ||
public bool IsSuccessful => Error is null; | ||
|
||
/// <summary> | ||
/// Array of Embedding objects created by ChatGpt | ||
/// </summary> | ||
public ChatGptEmbedding[] Data { get; set; } = Array.Empty<ChatGptEmbedding>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace ChatGptNet.Models; | ||
|
||
/// <summary> | ||
/// Represents a request for create embeddings request. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://platform.openai.com/docs/api-reference/embeddings/create">Create embeddings (OpenAI)</see> or <see href="https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/embeddings?tabs=console">Embeddings basics (Azure)</see> for more information. | ||
/// </remarks> | ||
internal class ChatGptEmbeddingsRequest | ||
{ | ||
/// <summary> | ||
/// Gets or sets the ID of the model to use. | ||
/// </summary> | ||
public string? Model { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the messages array to generate embeddings for. | ||
/// </summary> | ||
/// <seealso cref="Input"/> | ||
public string[]? Input { get; set; } | ||
|
||
public string? User { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters