-
-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from betalgo/dev
Version 6.3.0
- Loading branch information
Showing
13 changed files
with
244 additions
and
24 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,47 @@ | ||
using OpenAI.GPT3.Interfaces; | ||
using OpenAI.GPT3.ObjectModels; | ||
using OpenAI.GPT3.ObjectModels.RequestModels; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Numerics; | ||
|
||
namespace OpenAI.Playground.TestHelpers | ||
{ | ||
internal static class EmbeddingTestHelper | ||
{ | ||
public static async Task RunSimpleEmbeddingTest(IOpenAIService sdk) | ||
{ | ||
ConsoleExtensions.WriteLine("Simple Embedding test is starting:", ConsoleColor.Cyan); | ||
|
||
try | ||
{ | ||
ConsoleExtensions.WriteLine("Embedding Test:", ConsoleColor.DarkCyan); | ||
var embeddingResult = await sdk.Embeddings.Create(new EmbeddingCreateRequest() | ||
{ | ||
Input = new List<string> { "The quick brown fox jumped over the lazy dog." }, | ||
Model = Models.TextSearchAdaDocV1 | ||
}); | ||
|
||
if (embeddingResult.Successful) | ||
{ | ||
Console.WriteLine(embeddingResult.Data.FirstOrDefault()); | ||
} | ||
else | ||
{ | ||
if (embeddingResult.Error == null) | ||
{ | ||
throw new Exception("Unknown Error"); | ||
} | ||
|
||
Console.WriteLine($"{embeddingResult.Error.Code}: {embeddingResult.Error.Message}"); | ||
} | ||
|
||
Console.WriteLine(embeddingResult.Data.FirstOrDefault()); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
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,17 @@ | ||
using OpenAI.GPT3.ObjectModels.RequestModels; | ||
using OpenAI.GPT3.ObjectModels.ResponseModels; | ||
|
||
namespace OpenAI.GPT3.Interfaces; | ||
|
||
/// <summary> | ||
/// Creates an embedding vector representing the input text. | ||
/// </summary> | ||
public interface IEmbedding | ||
{ | ||
/// <summary> | ||
/// Creates a new embedding for the provided input and parameters. | ||
/// </summary> | ||
/// <param name="createEmbeddingModel"></param> | ||
/// <returns></returns> | ||
Task<EmbeddingCreateResponse> Create(EmbeddingCreateRequest createEmbeddingModel); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using OpenAI.GPT3.Extensions; | ||
using OpenAI.GPT3.Interfaces; | ||
using OpenAI.GPT3.ObjectModels.RequestModels; | ||
using OpenAI.GPT3.ObjectModels.ResponseModels; | ||
|
||
namespace OpenAI.GPT3.Managers; | ||
|
||
public partial class OpenAIService : IEmbedding | ||
{ | ||
public async Task<EmbeddingCreateResponse> Create(EmbeddingCreateRequest createEmbeddingRequest) | ||
{ | ||
return await _httpClient.PostAndReadAsAsync<EmbeddingCreateResponse>(_endpointProvider.CreateEmbedding(), createEmbeddingRequest); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
OpenAI.SDK/ObjectModels/RequestModels/EmbeddingCreateRequest.cs
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,37 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Text.Json.Serialization; | ||
using OpenAI.GPT3.Interfaces; | ||
|
||
namespace OpenAI.GPT3.ObjectModels.RequestModels | ||
{ | ||
//TODO Update Usage of link (see cref) | ||
//TODO add model validation | ||
//TODO check what is string or array for prompt,.. | ||
public record EmbeddingCreateRequest : IModelValidate | ||
{ | ||
/// <summary> | ||
/// Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs | ||
/// in a single request, pass an array of strings or array of token arrays. Each input must not exceed 2048 tokens in | ||
/// length. | ||
/// Unless your are embedding code, we suggest replacing newlines (`\n`) in your input with a single space, as we have | ||
/// observed inferior results when newlines are present. | ||
/// </summary> | ||
/// <see cref="https://beta.openai.com/docs/api-reference/embeddings/create#embeddings/create-input" /> | ||
[JsonPropertyName("input")] | ||
public List<string>? Input { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your | ||
/// available models, or see our [Model overview](/docs/models/overview) for descriptions of them. | ||
/// </summary> | ||
/// <see cref="https://beta.openai.com/docs/api-reference/embeddings/create#embeddings/create-model" /> | ||
[JsonPropertyName("model")] | ||
public string? Model { get; set; } | ||
|
||
public IEnumerable<ValidationResult> Validate() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
OpenAI.SDK/ObjectModels/ResponseModels/EmbeddingCreateResponse.cs
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,18 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenAI.GPT3.ObjectModels.ResponseModels | ||
{ | ||
public record EmbeddingCreateResponse : BaseResponse | ||
{ | ||
[JsonPropertyName("model")] public string Model { get; set; } | ||
|
||
[JsonPropertyName("data")] public List<EmbeddingResponse> Data { get; set; } | ||
} | ||
|
||
public record EmbeddingResponse | ||
{ | ||
[JsonPropertyName("index")] public int? Index { get; set; } | ||
|
||
[JsonPropertyName("embedding")] public List<double> Embedding { 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