You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// 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.
13
+
/// </summary>
14
+
publicclassEmbeddingEndpoint
15
+
{
16
+
OpenAIAPIApi;
17
+
/// <summary>
18
+
/// This allows you to send request to the recommended model without needing to specify. Every request uses the <see cref="Model.AdaTextEmbedding"/> model
/// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of <see cref="OpenAIAPI"/> as <see cref="OpenAIAPI.Embeddings"/>.
24
+
/// </summary>
25
+
/// <param name="api"></param>
26
+
internalEmbeddingEndpoint(OpenAIAPIapi)
27
+
{
28
+
this.Api=api;
29
+
}
30
+
31
+
/// <summary>
32
+
/// Ask the API to embedd text using the default embedding model <see cref="Model.AdaTextEmbedding"/>
33
+
/// </summary>
34
+
/// <param name="input">Text to be embedded</param>
35
+
/// <returns>Asynchronously returns the embedding result. Look in its <see cref="Data.Embedding"/> property of <see cref="EmbeddingResult.Data"/> to find the vector of floating point numbers</returns>
/// Ask the API to embedd text using a custom request
44
+
/// </summary>
45
+
/// <param name="request">Request to be send</param>
46
+
/// <returns>Asynchronously returns the embedding result. Look in its <see cref="Data.Embedding"/> property of <see cref="EmbeddingResult.Data"/> to find the vector of floating point numbers</returns>
thrownewAuthenticationException("You must provide API authentication. Please refer to https://github.com/OkGoDoIt/OpenAI-API-dotnet#authentication for details.");
thrownewHttpRequestException("Error calling OpenAi API to get completion. HTTP status code: "+response.StatusCode.ToString()+". Request body: "+jsonContent);
/// Represents a request to the Completions API. Matches with the docs at <see href="https://platform.openai.com/docs/api-reference/embeddings">the OpenAI docs</see>
10
+
/// </summary>
11
+
publicclassEmbeddingRequest
12
+
{
13
+
/// <summary>
14
+
/// 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.AdaTextEmbedding"/>.
15
+
/// </summary>
16
+
[JsonIgnore]
17
+
publicModelModel{get;set;}
18
+
19
+
/// <summary>
20
+
/// The id/name of the model
21
+
/// </summary>
22
+
[JsonProperty("model")]
23
+
publicstringModelName=>Model.ModelID;
24
+
25
+
/// <summary>
26
+
/// Main text to be embedded
27
+
/// </summary>
28
+
[JsonProperty("input")]
29
+
publicstringInput{get;set;}
30
+
31
+
/// <summary>
32
+
/// Cretes a new, empty <see cref="EmbeddingRequest"/>
33
+
/// </summary>
34
+
publicEmbeddingRequest()
35
+
{
36
+
37
+
}
38
+
39
+
/// <summary>
40
+
/// Creates a new <see cref="EmbeddingRequest"/> with the specified parameters
41
+
/// </summary>
42
+
/// <param name="model">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.AdaTextEmbedding"/>.</param>
43
+
/// <param name="input">The prompt to transform</param>
/// Entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
14
-
/// </summary>
15
-
publicclassOpenAIAPI
16
-
{
17
-
/// <summary>
18
-
/// The API authentication information to use for API calls
19
-
/// </summary>
20
-
publicAPIAuthenticationAuth{get;set;}
21
-
22
-
/// <summary>
23
-
/// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
24
-
/// </summary>
25
-
/// <param name="apiKeys">The API authentication information to use for API calls, or <see langword="null"/> to attempt to use the <see cref="APIAuthentication.Default"/>, potentially loading from environment vars or from a config file.</param>
26
-
publicOpenAIAPI(APIAuthenticationapiKeys=null)
27
-
{
28
-
this.Auth=apiKeys.ThisOrDefault();
29
-
Completions=newCompletionEndpoint(this);
30
-
Models=newModelsEndpoint(this);
31
-
Search=newSearchEndpoint(this);
32
-
}
33
-
34
-
/// <summary>
35
-
/// 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).
36
-
/// </summary>
37
-
publicCompletionEndpointCompletions{get;}
13
+
/// <summary>
14
+
/// Entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
15
+
/// </summary>
16
+
publicclassOpenAIAPI
17
+
{
18
+
/// <summary>
19
+
/// The API authentication information to use for API calls
20
+
/// </summary>
21
+
publicAPIAuthenticationAuth{get;set;}
22
+
23
+
/// <summary>
24
+
/// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
25
+
/// </summary>
26
+
/// <param name="apiKeys">The API authentication information to use for API calls, or <see langword="null"/> to attempt to use the <see cref="APIAuthentication.Default"/>, potentially loading from environment vars or from a config file.</param>
27
+
publicOpenAIAPI(APIAuthenticationapiKeys=null)
28
+
{
29
+
this.Auth=apiKeys.ThisOrDefault();
30
+
Completions=newCompletionEndpoint(this);
31
+
Models=newModelsEndpoint(this);
32
+
Search=newSearchEndpoint(this);
33
+
Embeddings=newEmbeddingEndpoint(this);
34
+
}
35
+
36
+
/// <summary>
37
+
/// 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).
38
+
/// </summary>
39
+
publicCompletionEndpointCompletions{get;}
40
+
41
+
/// <summary>
42
+
/// The API lets you transform text into 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.
43
+
/// </summary>
44
+
publicEmbeddingEndpointEmbeddings{get;}
38
45
39
46
/// <summary>
40
47
/// The API endpoint for querying available Engines/models
@@ -51,5 +58,5 @@ public OpenAIAPI(APIAuthentication apiKeys = null)
0 commit comments