-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Add /v2/embed endpoint for text and image embeddings in Cohere API #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
public partial class CohereApi | ||
{ | ||
partial void PrepareEmbedv2Arguments( | ||
global::System.Net.Http.HttpClient httpClient, | ||
ref string? xClientName, | ||
global::Cohere.V2EmbedRequest request); | ||
partial void PrepareEmbedv2Request( | ||
global::System.Net.Http.HttpClient httpClient, | ||
global::System.Net.Http.HttpRequestMessage httpRequestMessage, | ||
string? xClientName, | ||
global::Cohere.V2EmbedRequest request); | ||
partial void ProcessEmbedv2Response( | ||
global::System.Net.Http.HttpClient httpClient, | ||
global::System.Net.Http.HttpResponseMessage httpResponseMessage); | ||
|
||
partial void ProcessEmbedv2ResponseContent( | ||
global::System.Net.Http.HttpClient httpClient, | ||
global::System.Net.Http.HttpResponseMessage httpResponseMessage, | ||
ref string content); | ||
|
||
/// <summary> | ||
/// Embed<br/> | ||
/// This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.<br/> | ||
/// Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.<br/> | ||
/// If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](/docs/semantic-search). | ||
/// </summary> | ||
/// <param name="xClientName"></param> | ||
/// <param name="request"></param> | ||
/// <param name="cancellationToken">The token to cancel the operation with</param> | ||
/// <exception cref="global::System.InvalidOperationException"></exception> | ||
public async global::System.Threading.Tasks.Task<global::Cohere.EmbedByTypeResponse> Embedv2Async( | ||
global::Cohere.V2EmbedRequest request, | ||
string? xClientName = default, | ||
global::System.Threading.CancellationToken cancellationToken = default) | ||
{ | ||
PrepareArguments( | ||
client: _httpClient); | ||
PrepareEmbedv2Arguments( | ||
httpClient: _httpClient, | ||
xClientName: ref xClientName, | ||
request: request); | ||
|
||
using var httpRequest = new global::System.Net.Http.HttpRequestMessage( | ||
method: global::System.Net.Http.HttpMethod.Post, | ||
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + "/v2/embed", global::System.UriKind.RelativeOrAbsolute)); | ||
var __httpRequestContentBody = global::System.Text.Json.JsonSerializer.Serialize(request, request.GetType(), JsonSerializerContext); | ||
var __httpRequestContent = new global::System.Net.Http.StringContent( | ||
content: __httpRequestContentBody, | ||
encoding: global::System.Text.Encoding.UTF8, | ||
mediaType: "application/json"); | ||
httpRequest.Content = __httpRequestContent; | ||
|
||
PrepareRequest( | ||
client: _httpClient, | ||
request: httpRequest); | ||
PrepareEmbedv2Request( | ||
httpClient: _httpClient, | ||
httpRequestMessage: httpRequest, | ||
xClientName: xClientName, | ||
request: request); | ||
|
||
using var response = await _httpClient.SendAsync( | ||
request: httpRequest, | ||
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, | ||
cancellationToken: cancellationToken).ConfigureAwait(false); | ||
|
||
ProcessResponse( | ||
client: _httpClient, | ||
response: response); | ||
ProcessEmbedv2Response( | ||
httpClient: _httpClient, | ||
httpResponseMessage: response); | ||
|
||
var __content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); | ||
|
||
ProcessResponseContent( | ||
client: _httpClient, | ||
response: response, | ||
content: ref __content); | ||
ProcessEmbedv2ResponseContent( | ||
httpClient: _httpClient, | ||
httpResponseMessage: response, | ||
content: ref __content); | ||
|
||
try | ||
{ | ||
response.EnsureSuccessStatusCode(); | ||
} | ||
catch (global::System.Net.Http.HttpRequestException ex) | ||
{ | ||
throw new global::System.InvalidOperationException(__content, ex); | ||
} | ||
|
||
return | ||
global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::Cohere.EmbedByTypeResponse), JsonSerializerContext) as global::Cohere.EmbedByTypeResponse ?? | ||
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); | ||
} | ||
|
||
/// <summary> | ||
/// Embed<br/> | ||
/// This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.<br/> | ||
/// Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.<br/> | ||
/// If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](/docs/semantic-search). | ||
/// </summary> | ||
/// <param name="xClientName"></param> | ||
/// <param name="cancellationToken">The token to cancel the operation with</param> | ||
/// <exception cref="global::System.InvalidOperationException"></exception> | ||
public async global::System.Threading.Tasks.Task<global::Cohere.EmbedByTypeResponse> Embedv2Async( | ||
string? xClientName = default, | ||
global::System.Threading.CancellationToken cancellationToken = default) | ||
{ | ||
var request = new global::Cohere.V2EmbedRequest | ||
{ | ||
}; | ||
|
||
return await Embedv2Async( | ||
xClientName: xClientName, | ||
request: request, | ||
cancellationToken: cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
#nullable enable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace Cohere | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
public partial interface ICohereApi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Embed<br/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.<br/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.<br/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](/docs/semantic-search). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="xClientName"></param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="request"></param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="cancellationToken">The token to cancel the operation with</param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <exception cref="global::System.InvalidOperationException"></exception> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
global::System.Threading.Tasks.Task<global::Cohere.EmbedByTypeResponse> Embedv2Async( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
global::Cohere.V2EmbedRequest request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
string? xClientName = default, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
global::System.Threading.CancellationToken cancellationToken = default); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Embed<br/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.<br/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.<br/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](/docs/semantic-search). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="xClientName"></param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <param name="cancellationToken">The token to cancel the operation with</param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <exception cref="global::System.InvalidOperationException"></exception> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
global::System.Threading.Tasks.Task<global::Cohere.EmbedByTypeResponse> Embedv2Async( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
string? xClientName = default, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
global::System.Threading.CancellationToken cancellationToken = default); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+22
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing required The Apply this diff to include the missing parameter: global::System.Threading.Tasks.Task<global::Cohere.EmbedByTypeResponse> Embedv2Async(
+ global::Cohere.V2EmbedRequest request,
string? xClientName = default,
global::System.Threading.CancellationToken cancellationToken = default); Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider consistency in class naming Ensure that the class name |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming the class for clarity
|
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response11 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming the class for clarity The name |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response12 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming the class for clarity The class name |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the need for multiple response classes Having several classes like |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate class naming concern Multiple classes with incremental numbering ( |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Evaluate the necessity of 'Embedv2Response4' class Repeated classes with similar names may lead to confusion. Assess if this class is necessary or if it can be merged with others. |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address potential class duplication Having multiple classes like |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#nullable enable | ||
|
||
namespace Cohere | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public sealed partial class Embedv2Response6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reassess the need for 'Embedv2Response6' class Multiple classes with similar structures and incremental naming suggest duplication. Consider unifying these classes or differentiating them with clear, descriptive names. |
||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public string? Data { get; set; } | ||
|
||
/// <summary> | ||
/// Additional properties that are not explicitly defined in the schema | ||
/// </summary> | ||
[global::System.Text.Json.Serialization.JsonExtensionData] | ||
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the parameterless
Embedv2Async
overload to prevent invalid requestsThe overload of
Embedv2Async
without therequest
parameter creates an emptyV2EmbedRequest
, which may result in an invalid API call since neitherTexts
norImages
is set. Consider removing this overload or providing a valid default request.