Skip to content

Commit

Permalink
fix: Fixed issue with enum header parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 22, 2024
1 parent 5bdf470 commit 7bd430b
Show file tree
Hide file tree
Showing 205 changed files with 7,335 additions and 1,713 deletions.
847 changes: 591 additions & 256 deletions specs/cohere.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/libs/AutoSDK/Sources/Sources.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ public static string GenerateMethod(
{endPoint.Parameters
.Where(x => x is { Location: ParameterLocation.Header, IsRequired: true })
.Select(x => $@"
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation(""{x.Id}"", {x.ParameterName});").Inject()}
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation(""{x.Id}"", {x.ParameterName}{(x.Type.IsEnum ? ".ToValueString()" : "")});").Inject()}
{endPoint.Parameters
.Where(x => x is { Location: ParameterLocation.Header, IsRequired: false })
.Select(x => $@"
if ({x.ParameterName} != default)
{{
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation(""{x.Id}"", {x.ParameterName});
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation(""{x.Id}"", {x.ParameterName}{(x.Type.IsEnum ? "?.ToValueString() ?? string.Empty" : "")});
}}").Inject()}
{(endPoint.Settings.JsonSerializerType == JsonSerializerType.NewtonsoftJson ? endPoint.Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public partial class Api
partial void PrepareChatArguments(
global::System.Net.Http.HttpClient httpClient,
ref string? xClientName,
ref global::G.ChatAccepts? accepts,
global::G.ChatRequest request);
partial void PrepareChatRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string? xClientName,
global::G.ChatAccepts? accepts,
global::G.ChatRequest request);
partial void ProcessChatResponse(
global::System.Net.Http.HttpClient httpClient,
Expand All @@ -27,15 +29,17 @@ partial void ProcessChatResponseContent(
/// <summary>
/// Chat<br/>
/// Generates a text response to a user message.<br/>
/// To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
/// To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
/// </summary>
/// <param name="xClientName"></param>
/// <param name="accepts"></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::G.OneOf<global::G.NonStreamedChatResponse, global::G.StreamedChatResponse?>> ChatAsync(
global::G.ChatRequest request,
string? xClientName = default,
global::G.ChatAccepts? accepts = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));
Expand All @@ -45,13 +49,23 @@ partial void ProcessChatResponseContent(
PrepareChatArguments(
httpClient: _httpClient,
xClientName: ref xClientName,
accepts: ref accepts,
request: request);

if (xClientName != default)
{
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-Client-Name", xClientName);
}
if (accepts != default)
{
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accepts", accepts?.ToValueString() ?? string.Empty);
}

var acceptsValue = accepts switch
{
global::G.ChatAccepts.TextEventStream => "text/event-stream",
_ => throw new global::System.NotImplementedException("Enum value not implemented."),
};
var __pathBuilder = new PathBuilder(
path: "/v1/chat",
baseUri: _httpClient.BaseAddress);
Expand All @@ -73,6 +87,7 @@ partial void ProcessChatResponseContent(
httpClient: _httpClient,
httpRequestMessage: httpRequest,
xClientName: xClientName,
accepts: accepts,
request: request);

using var response = await _httpClient.SendAsync(
Expand Down Expand Up @@ -115,15 +130,16 @@ partial void ProcessChatResponseContent(
/// <summary>
/// Chat<br/>
/// Generates a text response to a user message.<br/>
/// To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
/// To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
/// </summary>
/// <param name="xClientName"></param>
/// <param name="accepts"></param>
/// <param name="message">
/// Text input for the model to respond to.<br/>
/// Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments
/// </param>
/// <param name="model">
/// Defaults to `command-r-plus`.<br/>
/// Defaults to `command-r-plus-08-2024`.<br/>
/// The name of a compatible [Cohere model](https://docs.cohere.com/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/docs/chat-fine-tuning) model.<br/>
/// Compatible Deployments: Cohere Platform, Private Deployments
/// </param>
Expand Down Expand Up @@ -155,7 +171,9 @@ partial void ProcessChatResponseContent(
/// With `prompt_truncation` set to "AUTO", some elements from `chat_history` and `documents` will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be changed and ranked by relevance.<br/>
/// With `prompt_truncation` set to "AUTO_PRESERVE_ORDER", some elements from `chat_history` and `documents` will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be preserved as they are inputted into the API.<br/>
/// With `prompt_truncation` set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a `TooManyTokens` error will be returned.<br/>
/// Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker/Bedrock, Private Deployments
/// Compatible Deployments: <br/>
/// - AUTO: Cohere Platform Only<br/>
/// - AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker/Bedrock, Private Deployments
/// </param>
/// <param name="connectors">
/// Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one.<br/>
Expand Down Expand Up @@ -275,12 +293,19 @@ partial void ProcessChatResponseContent(
/// Forces the chat to be single step. Defaults to `false`.
/// </param>
/// <param name="responseFormat">
/// Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models.<br/>
/// Configuration for forcing the model output to adhere to the specified format. Supported on [Command R 03-2024](https://docs.cohere.com/docs/command-r), [Command R+ 04-2024](https://docs.cohere.com/docs/command-r-plus) and newer models.<br/>
/// The model can be forced into outputting JSON objects (with up to 5 levels of nesting) by setting `{ "type": "json_object" }`.<br/>
/// A [JSON Schema](https://json-schema.org/) can optionally be provided, to ensure a specific structure.<br/>
/// **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length.<br/>
/// **Limitation**: The parameter is not supported in RAG mode (when any of `connectors`, `documents`, `tools`, `tool_results` are provided).
/// </param>
/// <param name="safetyMode">
/// Used to select the [safety instruction](/docs/safety-modes) inserted into the prompt. Defaults to `CONTEXTUAL`.<br/>
/// When `NONE` is specified, the safety instruction will be omitted.<br/>
/// Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters.<br/>
/// **Note**: This parameter is only compatible with models [Command R 08-2024](/docs/command-r#august-2024-release), [Command R+ 08-2024](/docs/command-r-plus#august-2024-release) and newer.<br/>
/// Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments
/// </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::G.OneOf<global::G.NonStreamedChatResponse, global::G.StreamedChatResponse?>> ChatAsync(
Expand All @@ -293,6 +318,7 @@ partial void ProcessChatResponseContent(
double frequencyPenalty,
double presencePenalty,
string? xClientName = default,
global::G.ChatAccepts? accepts = default,
string? model = default,
bool? stream = default,
string? preamble = default,
Expand All @@ -309,6 +335,7 @@ partial void ProcessChatResponseContent(
global::System.Collections.Generic.IList<global::G.ToolResult>? toolResults = default,
bool? forceSingleStep = default,
global::G.ResponseFormat? responseFormat = default,
global::G.ChatRequestSafetyMode? safetyMode = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new global::G.ChatRequest
Expand Down Expand Up @@ -337,10 +364,12 @@ partial void ProcessChatResponseContent(
ToolResults = toolResults,
ForceSingleStep = forceSingleStep,
ResponseFormat = responseFormat,
SafetyMode = safetyMode,
};

return await ChatAsync(
xClientName: xClientName,
accepts: accepts,
request: request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ partial void ProcessChatv2ResponseContent(
/// <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::G.OneOf<global::G.NonStreamedChatResponse2, global::G.StreamedChatResponse2?>> Chatv2Async(
public async global::System.Threading.Tasks.Task<global::G.OneOf<global::G.ChatResponse, global::G.StreamedChatResponseV2?>> Chatv2Async(
global::G.Chatv2Request request,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ partial void ProcessChatv2ResponseContent(
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.OneOf<global::G.NonStreamedChatResponse2, global::G.StreamedChatResponse2?>?>(__content, JsonSerializerOptions) ??
global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.OneOf<global::G.ChatResponse, global::G.StreamedChatResponseV2?>?>(__content, JsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}

Expand All @@ -115,9 +115,11 @@ partial void ProcessChatv2ResponseContent(
/// A list of available tools (functions) that the model may suggest invoking before producing a text response.<br/>
/// When `tools` is passed (without `tool_results`), the `text` content in the response will be empty and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty.
/// </param>
/// <param name="citationMode">
/// Defaults to `"accurate"`.<br/>
/// Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results, `"fast"` results or no results.
/// <param name="documents">
/// A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.
/// </param>
/// <param name="citationOptions">
/// Options for controlling citation generation.
/// </param>
/// <param name="responseFormat">
/// Configuration for forcing the model output to adhere to the specified format. Supported on [Command R](https://docs.cohere.com/docs/command-r), [Command R+](https://docs.cohere.com/docs/command-r-plus) and newer models.<br/>
Expand All @@ -126,6 +128,13 @@ partial void ProcessChatv2ResponseContent(
/// **Note**: When using `{ "type": "json_object" }` your `message` should always explicitly instruct the model to generate a JSON (eg: _"Generate a JSON ..."_) . Otherwise the model may end up getting stuck generating an infinite stream of characters and eventually run out of context length.<br/>
/// **Limitation**: The parameter is not supported in RAG mode (when any of `connectors`, `documents`, `tools`, `tool_results` are provided).
/// </param>
/// <param name="safetyMode">
/// Used to select the [safety instruction](/docs/safety-modes) inserted into the prompt. Defaults to `CONTEXTUAL`.<br/>
/// When `NONE` is specified, the safety instruction will be omitted.<br/>
/// Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters.<br/>
/// **Note**: This parameter is only compatible with models [Command R 08-2024](/docs/command-r#august-2024-release), [Command R+ 08-2024](/docs/command-r-plus#august-2024-release) and newer.<br/>
/// Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments
/// </param>
/// <param name="maxTokens">
/// The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations.
/// </param>
Expand Down Expand Up @@ -163,12 +172,14 @@ partial void ProcessChatv2ResponseContent(
/// </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::G.OneOf<global::G.NonStreamedChatResponse2, global::G.StreamedChatResponse2?>> Chatv2Async(
public async global::System.Threading.Tasks.Task<global::G.OneOf<global::G.ChatResponse, global::G.StreamedChatResponseV2?>> Chatv2Async(
string model,
global::System.Collections.Generic.IList<global::G.ChatMessage2> messages,
global::System.Collections.Generic.IList<global::G.Tool2>? tools = default,
global::G.Chatv2RequestCitationMode? citationMode = default,
global::G.ResponseFormat2? responseFormat = default,
global::System.Collections.Generic.IList<global::G.ChatMessageV2> messages,
global::System.Collections.Generic.IList<global::G.ToolV2>? tools = default,
global::System.Collections.Generic.IList<global::G.OneOf<string, global::G.Document>>? documents = default,
global::G.CitationOptions? citationOptions = default,
global::G.ResponseFormatV2? responseFormat = default,
global::G.Chatv2RequestSafetyMode? safetyMode = default,
int? maxTokens = default,
global::System.Collections.Generic.IList<string>? stopSequences = default,
float? temperature = default,
Expand All @@ -184,8 +195,10 @@ partial void ProcessChatv2ResponseContent(
Model = model,
Messages = messages,
Tools = tools,
CitationMode = citationMode,
Documents = documents,
CitationOptions = citationOptions,
ResponseFormat = responseFormat,
SafetyMode = safetyMode,
MaxTokens = maxTokens,
StopSequences = stopSequences,
Temperature = temperature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ partial void ProcessEmbedResponseContent(
/// - `"search_document"`: Used for embeddings stored in a vector database for search use-cases.<br/>
/// - `"search_query"`: Used for embeddings of search queries run against a vector DB to find relevant documents.<br/>
/// - `"classification"`: Used for embeddings passed through a text classifier.<br/>
/// - `"clustering"`: Used for the embeddings run through a clustering algorithm.
/// - `"clustering"`: Used for the embeddings run through a clustering algorithm.<br/>
/// - `"image"`: Used for embeddings with image input.
/// </param>
/// <param name="embeddingTypes">
/// Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types.<br/>
Expand Down
Loading

0 comments on commit 7bd430b

Please sign in to comment.