Skip to content
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

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions src/libs/Cohere/Generated/Cohere.CohereApi.Embedv2.g.cs
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);
}
Comment on lines +113 to +125
Copy link

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 requests

The overload of Embedv2Async without the request parameter creates an empty V2EmbedRequest, which may result in an invalid API call since neither Texts nor Images is set. Consider removing this overload or providing a valid default request.

}
}
35 changes: 35 additions & 0 deletions src/libs/Cohere/Generated/Cohere.ICohereApi.Embedv2.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required request parameter in method signature

The Embedv2Async method overload defined on lines 31-33 is missing the V2EmbedRequest parameter. This parameter is essential for providing the request data to the API call. Without it, the method cannot function correctly.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// <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);
/// <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(
global::Cohere.V2EmbedRequest request,
string? xClientName = default,
global::System.Threading.CancellationToken cancellationToken = default);

}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider consistency in class naming

Ensure that the class name Embedv2Response aligns with existing naming conventions and accurately reflects the class's purpose. If there are multiple response classes for embedding, consider more descriptive names to differentiate them.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response10.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the class for clarity

Embedv2Response10 may not adequately describe the class's purpose. Consider choosing a more descriptive name that reflects its functionality.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response11.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the class for clarity

The name Embedv2Response11 may not convey clear intent. A more descriptive class name would enhance readability.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response12.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the class for clarity

The class name Embedv2Response12 may not be sufficiently descriptive. Renaming it to reflect its role could improve maintainability.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response2.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify the need for multiple response classes

Having several classes like Embedv2Response, Embedv2Response2, etc., might cause confusion. Assess whether these classes serve distinct purposes or if they can be consolidated into a single, well-named class.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response3.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate class naming concern

Multiple classes with incremental numbering (Embedv2Response3, etc.) may indicate duplicate or placeholder classes. Consider unifying these classes or providing descriptive names to reflect their unique purposes.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response4.g.cs
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
Copy link

Choose a reason for hiding this comment

The 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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response5.g.cs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address potential class duplication

Having multiple classes like Embedv2Response5 may not be necessary. Review if these classes can be consolidated.

{
/// <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>();
}
}
23 changes: 23 additions & 0 deletions src/libs/Cohere/Generated/Cohere.Models.Embedv2Response6.g.cs
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
Copy link

Choose a reason for hiding this comment

The 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>();
}
}
Loading
Loading