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:Update CohereApi.Chat with safetyMode parameter and type changes #28

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

HavenDV
Copy link
Contributor

@HavenDV HavenDV commented Aug 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new safetyMode parameter in the ChatAsync method for enhanced control over safety instructions.
    • Added a new SafetyMode property in the ChatRequest class to manage safety instructions in prompts.
    • Implemented new JSON converters for handling ChatRequestSafetyMode and nullable types.
  • Documentation

    • Improved documentation clarity regarding model compatibility and safety modes across various classes and methods.

Copy link

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes involve updates to the CohereApi.Chat class and related models, including the introduction of a new safetyMode parameter in the ChatAsync method and the addition of a SafetyMode property in the ChatRequest class. Documentation has been enhanced for clarity, and several properties have undergone type changes. New JSON converters for handling ChatRequestSafetyMode and its nullable variant have also been added to facilitate serialization.

Changes

File Path Change Summary
src/libs/Cohere/Generated/Cohere.CohereApi.Chat.g.cs Updated ProcessChatResponseContent documentation; added safetyMode parameter to ChatAsync.
src/libs/Cohere/Generated/Cohere.Models.ChatRequest.g.cs Updated Model default value; added SafetyMode property; reformatted documentation for clarity.
src/libs/Cohere/Generated/Cohere.Models.ChatRequestPromptTruncation.g.cs Enhanced documentation for prompt_truncation enum.
src/libs/Cohere/Generated/Cohere.Models.ChatRequestSafetyMode.g.cs Introduced ChatRequestSafetyMode enum and extensions for string conversion.
src/libs/Cohere/Generated/JsonConverters.ChatRequestSafetyMode.g.cs Added JSON converter for ChatRequestSafetyMode.
src/libs/Cohere/Generated/JsonConverters.ChatRequestSafetyModeNullable.g.cs Added JSON converter for nullable ChatRequestSafetyMode.
src/libs/Cohere/Generated/JsonSerializerContext.g.cs Registered new JSON converters for safety modes.
src/libs/Cohere/Generated/JsonSerializerContextTypes.g.cs Altered property types reflecting updates in data structures.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatAPI
    participant ChatRequest
    participant JSONConverter

    User->>ChatAPI: Call ChatAsync(safetyMode)
    ChatAPI->>ChatRequest: Create request with safetyMode
    ChatRequest->>JSONConverter: Serialize request
    JSONConverter-->>ChatAPI: Return serialized request
    ChatAPI-->>User: Return chat response
Loading

🐇 "Oh what fun, a change so bright,
With safety modes, we hop in delight!
In chats we now can choose with care,
A safer world, we gladly share!
So let us dance and sing with glee,
For every change brings joy to me!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot enabled auto-merge August 30, 2024 01:21
@github-actions github-actions bot merged commit 30d74c7 into main Aug 30, 2024
3 checks passed
@coderabbitai coderabbitai bot changed the title feat:@coderabbitai feat:Update CohereApi.Chat with safetyMode parameter and type changes Aug 30, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c094559 and 0455383.

Files selected for processing (10)
  • src/libs/Cohere/Generated/Cohere.CohereApi.Chat.g.cs (5 hunks)
  • src/libs/Cohere/Generated/Cohere.Models.ChatRequest.g.cs (4 hunks)
  • src/libs/Cohere/Generated/Cohere.Models.ChatRequestPromptTruncation.g.cs (1 hunks)
  • src/libs/Cohere/Generated/Cohere.Models.ChatRequestSafetyMode.g.cs (1 hunks)
  • src/libs/Cohere/Generated/Cohere.Models.ResponseFormat.g.cs (1 hunks)
  • src/libs/Cohere/Generated/JsonConverters.ChatRequestSafetyMode.g.cs (1 hunks)
  • src/libs/Cohere/Generated/JsonConverters.ChatRequestSafetyModeNullable.g.cs (1 hunks)
  • src/libs/Cohere/Generated/JsonSerializerContext.g.cs (1 hunks)
  • src/libs/Cohere/Generated/JsonSerializerContextTypes.g.cs (1 hunks)
  • src/libs/Cohere/openapi.yaml (8 hunks)
Files skipped from review due to trivial changes (2)
  • src/libs/Cohere/Generated/Cohere.Models.ChatRequestPromptTruncation.g.cs
  • src/libs/Cohere/Generated/Cohere.Models.ResponseFormat.g.cs
Additional comments not posted (35)
src/libs/Cohere/Generated/JsonSerializerContext.g.cs (2)

94-94: LGTM!

The addition of ChatRequestSafetyModeJsonConverter is straightforward and follows the existing pattern.


95-95: LGTM!

The addition of ChatRequestSafetyModeNullableJsonConverter is straightforward and follows the existing pattern.

src/libs/Cohere/Generated/Cohere.Models.ChatRequest.g.cs (5)

20-20: LGTM!

The update to the Model property documentation to reflect the new default value command-r-plus-08-2024 is straightforward.


67-69: LGTM!

The reformatting of the prompt_truncation property documentation improves readability and understanding of the compatibility details.


235-235: LGTM!

The update to the ForceSingleStep property documentation enhances clarity by specifying the supported models and their release dates.


245-254: LGTM!

The addition of the SafetyMode property is well-documented and follows the existing pattern.


Line range hint 333-333: LGTM!

The addition of the SafetyMode property to the class constructor is consistent with the rest of the properties.

src/libs/Cohere/Generated/Cohere.CohereApi.Chat.g.cs (5)

116-116: LGTM!

The update to the model parameter documentation to reflect the new default value command-r-plus-08-2024 is straightforward.


148-150: LGTM!

The reformatting of the promptTruncation parameter documentation improves readability and understanding of the compatibility details.


269-275: LGTM!

The addition of the safetyMode parameter is well-documented and follows the existing pattern.


304-304: LGTM!

The addition of the safetyMode parameter to the method signature is consistent with the rest of the parameters.


333-333: LGTM!

The addition of the SafetyMode property to the class constructor is consistent with the rest of the properties.

src/libs/Cohere/Generated/JsonSerializerContextTypes.g.cs (15)

1140-1141: Verify the correctness and consistency of the type change for Type281.

The type has been changed from GenerateRequestTruncate? to GenerateRequest?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type281:


1168-1169: Verify the correctness and consistency of the type change for Type288.

The type has been changed from ClassifyRequest? to System.OneOf<string, Cohere.RerankDocument>?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type288:


1152-1153: Verify the correctness and consistency of the type change for Type284.

The type has been changed from EmbedRequestTruncate? to EmbedRequest?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type284:


1124-1125: Verify the correctness and consistency of the type change for Type277.

The type has been changed from Chatv2Request? to ChatRequestSafetyMode?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type277:


1136-1137: Verify the correctness and consistency of the type change for Type280.

The type has been changed from GenerateRequest? to Chatv2RequestCitationMode?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type280:

Verification successful

Type change for Type280 is isolated and consistent.

The type change from GenerateRequest? to Chatv2RequestCitationMode? for Type280 does not affect any other part of the codebase, as there are no other occurrences of Type280. This change is isolated and should not cause any issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type280` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type280'

Length of output: 603


Script:

#!/bin/bash
# Comprehensive search for all occurrences of `Type280` in the codebase to verify its usage.
rg --type cs 'Type280'

Length of output: 159


1148-1149: Verify the correctness and consistency of the type change for Type283.

The type has been changed from EmbedRequest? to GenerateRequestReturnLikelihoods?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type283:

Verification successful

No references found for Type283 in the codebase.

The property Type283 with the type GenerateRequestReturnLikelihoods? is not used elsewhere in the codebase, suggesting that the type change does not impact other parts of the code. This indicates no immediate issues with the change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type283` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type283'

Length of output: 607


Script:

#!/bin/bash
# Description: Search for all occurrences of `Type283` in the codebase to verify its usage.

# Test: Find all references to `Type283`. Expect: Consistent usage with the new type.
rg --type cs 'Type283'

Length of output: 166


1128-1129: Verify the correctness and consistency of the type change for Type278.

The type has been changed from System.Collections.Generic.IList<Tool2>? to Chatv2Request?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type278:

Verification successful

No impact from the type change for Type278 due to lack of usage.

The property Type278 is only declared in the JsonSerializerContextTypes.g.cs file and is not used elsewhere in the codebase. This suggests that the type change does not currently affect other parts of the code.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type278` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type278'

Length of output: 623


Script:

#!/bin/bash
# Description: Search for all occurrences of `Type278` in the codebase to verify its usage.

# Test: Find all instances of `Type278` to ensure the new type is used correctly.
rg --type cs 'Type278'

Length of output: 147


1132-1133: Verify the correctness and consistency of the type change for Type279.

The type has been changed from Chatv2RequestCitationMode? to System.Collections.Generic.IList<Tool2>?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type279:

Verification successful

The type change for Type279 is consistent and appropriate.

The change to System.Collections.Generic.IList<global::Cohere.Tool2>? aligns with other usages of Tool2 in the codebase, indicating that the modification is consistent with the overall data model. No further issues were found regarding this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type279` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type279'

Length of output: 635


Script:

#!/bin/bash
# Description: Search for the definition and usage of `Tool2` to understand its role in the codebase.

# Test: Find the definition of `Tool2` and its usage.
rg --type cs 'class Tool2' -A 5
rg --type cs 'Tool2' -A 5

Length of output: 20808


1156-1157: Verify the correctness and consistency of the type change for Type285.

The type has been changed from RerankRequest? to EmbedRequestTruncate?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type285:

Verification successful

No references found for Type285 in the codebase.

The change from RerankRequest? to EmbedRequestTruncate? does not impact other parts of the codebase as Type285 is not referenced elsewhere. Ensure that this property is meant to be unused or verify if it should be utilized in other parts of the code.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type285` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type285'

Length of output: 596


Script:

#!/bin/bash
# Description: Search for references to `Type285` in the codebase to verify its usage.

# Test: Find all references to `Type285` to ensure consistent usage of the new type.
rg --type cs 'Type285'

Length of output: 154


1164-1165: Verify the correctness and consistency of the type change for Type287.

The type has been changed from System.OneOf<string, Cohere.RerankDocument>? to System.Collections.Generic.IList<System.OneOf<string, Cohere.RerankDocument>>?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type287:

Verification successful

No issues found with the type change for Type287.

The property Type287 is not referenced elsewhere in the codebase, suggesting it may be newly introduced or not yet integrated. The change to a list type does not impact existing functionality. Ensure that any future usage aligns with the new type.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type287` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type287'

Length of output: 693


Script:

#!/bin/bash
# Description: Search for references to `Type287` in the codebase to verify its usage.

# Test: Find all references to `Type287` to ensure the change to a list type is handled correctly.
rg --type cs 'Type287'

Length of output: 220


1180-1181: Verify the correctness and consistency of the type change for Type291.

The type has been changed from CreateDatasetRequest? to ClassifyRequestTruncate?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type291:

Verification successful

Type change for Type291 is isolated and consistent.

The type change from CreateDatasetRequest? to ClassifyRequestTruncate? for Type291 is isolated to its definition and does not affect other parts of the codebase, as there are no other occurrences of Type291. This change is consistent and does not require further updates.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type291` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type291'

Length of output: 606


Script:

#!/bin/bash
# Description: Search for all occurrences of `Type291` in the codebase to verify its usage.

# Test: Find all usages of `Type291` to ensure consistency with the new type.
rg --type cs 'Type291'

Length of output: 157


1176-1177: Verify the correctness and consistency of the type change for Type290.

The type has been changed from ClassifyRequestTruncate? to System.Collections.Generic.IList<ClassifyExample>?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type290:


1144-1145: Verify the correctness and consistency of the type change for Type282.

The type has been changed from GenerateRequestReturnLikelihoods? to GenerateRequestTruncate?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type282:


1160-1161: Verify the correctness and consistency of the type change for Type286.

The type has been changed from System.Collections.Generic.IList<System.OneOf<string, Cohere.RerankDocument>>? to RerankRequest?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type286:

Verification successful

The type change for Type286 is consistent and appropriate.

The change from System.Collections.Generic.IList<System.OneOf<string, Cohere.RerankDocument>>? to RerankRequest? aligns with the usage of RerankRequest in the API, indicating that it is a suitable and consistent update. The absence of additional references to Type286 suggests it is used internally or in a generated context.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type286` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type286'

Length of output: 662


Script:

#!/bin/bash
# Search for the usage of `RerankRequest` to understand its role in the codebase.
rg --type cs -A 5 $'RerankRequest'

# Search for any references to `Type286` in other parts of the codebase to confirm its usage and consistency.
rg --type cs -A 5 $'Type286'

Length of output: 5644


1172-1173: Verify the correctness and consistency of the type change for Type289.

The type has been changed from System.Collections.Generic.IList<ClassifyExample>? to ClassifyRequest?. Ensure that this change is appropriate and consistent with the rest of the codebase.

Run the following script to verify the usage of Type289:

Verification successful

The type change for Type289 is consistent and appropriate.

The change from System.Collections.Generic.IList<ClassifyExample>? to ClassifyRequest? aligns with the usage of ClassifyRequest in the codebase, particularly in API-related operations. This refactoring likely aims to encapsulate the request data more effectively. No inconsistencies or issues were found related to this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Type289` in the codebase.

# Test: Search for the property usage. Expect: Consistent usage of the new type.
rg --type cs -A 5 $'Type289'

Length of output: 635


Script:

#!/bin/bash
# Description: Search for references to `ClassifyRequest` to gather more context on its usage.

# Test: Search for references to `ClassifyRequest`.
rg --type cs 'ClassifyRequest'

Length of output: 5465

src/libs/Cohere/openapi.yaml (8)

35-63: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.


72-92: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.


101-128: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.


137-137: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.


146-165: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.


174-182: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.


192-200: LGTM!

The addition of the safety_mode parameter is a significant enhancement, allowing users to select from various safety instructions. The description provides clear guidance on its usage.


6939-6939: LGTM!

The changes improve the readability and clarity of the descriptions, which is beneficial for developers using the API.

Comment on lines +39 to +47
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Cohere.ChatRequestSafetyMode value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value));
}
Copy link

Choose a reason for hiding this comment

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

Move null check to method parameter validation.

The null check for the writer can be moved to the method parameter validation for better readability.

Apply this diff to move the null check to the method parameter validation:

public override void Write(
    global::System.Text.Json.Utf8JsonWriter writer,
    global::Cohere.ChatRequestSafetyMode value,
    global::System.Text.Json.JsonSerializerOptions options)
{
    if (writer == null) throw new global::System.ArgumentNullException(nameof(writer));

    writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value));
}
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
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Cohere.ChatRequestSafetyMode value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));
writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value));
}
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Cohere.ChatRequestSafetyMode value,
global::System.Text.Json.JsonSerializerOptions options)
{
if (writer == null) throw new global::System.ArgumentNullException(nameof(writer));
writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value));
}

Comment on lines +9 to +35
public override global::Cohere.ChatRequestSafetyMode Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::Cohere.ChatRequestSafetyMode)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
Copy link

Choose a reason for hiding this comment

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

Improve readability and exception handling.

The switch statement can be replaced with a more concise pattern matching. The default case should throw a JsonException instead of ArgumentOutOfRangeException for better context.

Apply this diff to improve readability and exception handling:

public override global::Cohere.ChatRequestSafetyMode Read(
    ref global::System.Text.Json.Utf8JsonReader reader,
    global::System.Type typeToConvert,
    global::System.Text.Json.JsonSerializerOptions options)
{
    return reader.TokenType switch
    {
        global::System.Text.Json.JsonTokenType.String => global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(reader.GetString()) ?? default,
        global::System.Text.Json.JsonTokenType.Number => (global::Cohere.ChatRequestSafetyMode)reader.GetInt32(),
        _ => throw new global::System.Text.Json.JsonException($"Unexpected token parsing ChatRequestSafetyMode. Expected String or Number, got {reader.TokenType}."),
    };
}
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
public override global::Cohere.ChatRequestSafetyMode Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(stringValue) ?? default;
}
break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::Cohere.ChatRequestSafetyMode)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}
return default;
public override global::Cohere.ChatRequestSafetyMode Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
return reader.TokenType switch
{
global::System.Text.Json.JsonTokenType.String => global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(reader.GetString()) ?? default,
global::System.Text.Json.JsonTokenType.Number => (global::Cohere.ChatRequestSafetyMode)reader.GetInt32(),
_ => throw new global::System.Text.Json.JsonException($"Unexpected token parsing ChatRequestSafetyMode. Expected String or Number, got {reader.TokenType}."),
};
}

Comment on lines +39 to +54
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Cohere.ChatRequestSafetyMode? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value.Value));
}
}
Copy link

Choose a reason for hiding this comment

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

Move null check to method parameter validation.

The null check for the writer can be moved to the method parameter validation for better readability.

Apply this diff to move the null check to the method parameter validation:

public override void Write(
    global::System.Text.Json.Utf8JsonWriter writer,
    global::Cohere.ChatRequestSafetyMode? value,
    global::System.Text.Json.JsonSerializerOptions options)
{
    if (writer == null) throw new global::System.ArgumentNullException(nameof(writer));

    if (value == null)
    {
        writer.WriteNullValue();
    }
    else
    {
        writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value.Value));
    }
}
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
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Cohere.ChatRequestSafetyMode? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));
if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value.Value));
}
}
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Cohere.ChatRequestSafetyMode? value,
global::System.Text.Json.JsonSerializerOptions options)
{
if (writer == null) throw new global::System.ArgumentNullException(nameof(writer));
if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::Cohere.ChatRequestSafetyModeExtensions.ToValueString(value.Value));
}
}

Comment on lines +9 to +35
public override global::Cohere.ChatRequestSafetyMode? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::Cohere.ChatRequestSafetyMode)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
Copy link

Choose a reason for hiding this comment

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

Improve readability and exception handling.

The switch statement can be replaced with a more concise pattern matching. The default case should throw a JsonException instead of ArgumentOutOfRangeException for better context.

Apply this diff to improve readability and exception handling:

public override global::Cohere.ChatRequestSafetyMode? Read(
    ref global::System.Text.Json.Utf8JsonReader reader,
    global::System.Type typeToConvert,
    global::System.Text.Json.JsonSerializerOptions options)
{
    return reader.TokenType switch
    {
        global::System.Text.Json.JsonTokenType.String => global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(reader.GetString()),
        global::System.Text.Json.JsonTokenType.Number => (global::Cohere.ChatRequestSafetyMode)reader.GetInt32(),
        _ => throw new global::System.Text.Json.JsonException($"Unexpected token parsing ChatRequestSafetyMode. Expected String or Number, got {reader.TokenType}."),
    };
}
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
public override global::Cohere.ChatRequestSafetyMode? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(stringValue);
}
break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::Cohere.ChatRequestSafetyMode)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}
return default;
public override global::Cohere.ChatRequestSafetyMode? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
return reader.TokenType switch
{
global::System.Text.Json.JsonTokenType.String => global::Cohere.ChatRequestSafetyModeExtensions.ToEnum(reader.GetString()),
global::System.Text.Json.JsonTokenType.Number => (global::Cohere.ChatRequestSafetyMode)reader.GetInt32(),
_ => throw new global::System.Text.Json.JsonException($"Unexpected token parsing ChatRequestSafetyMode. Expected String or Number, got {reader.TokenType}."),
};
}

Comment on lines +13 to +26
public enum ChatRequestSafetyMode
{
/// <summary>
///
/// </summary>
CONTEXTUAL,
/// <summary>
///
/// </summary>
STRICT,
/// <summary>
///
/// </summary>
NONE,
Copy link

Choose a reason for hiding this comment

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

Add meaningful descriptions to enum values.

The enum values have empty summaries. Add meaningful descriptions to improve documentation.

Apply this diff to add meaningful descriptions:

/// <summary>
/// Contextual safety mode.
/// </summary>
CONTEXTUAL,
/// <summary>
/// Strict safety mode.
/// </summary>
STRICT,
/// <summary>
/// No safety mode.
/// </summary>
NONE,
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
public enum ChatRequestSafetyMode
{
/// <summary>
///
/// </summary>
CONTEXTUAL,
/// <summary>
///
/// </summary>
STRICT,
/// <summary>
///
/// </summary>
NONE,
public enum ChatRequestSafetyMode
{
/// <summary>
/// Contextual safety mode.
/// </summary>
CONTEXTUAL,
/// <summary>
/// Strict safety mode.
/// </summary>
STRICT,
/// <summary>
/// No safety mode.
/// </summary>
NONE,

Comment on lines +32 to +59
public static class ChatRequestSafetyModeExtensions
{
/// <summary>
/// Converts an enum to a string.
/// </summary>
public static string ToValueString(this ChatRequestSafetyMode value)
{
return value switch
{
ChatRequestSafetyMode.CONTEXTUAL => "CONTEXTUAL",
ChatRequestSafetyMode.STRICT => "STRICT",
ChatRequestSafetyMode.NONE => "NONE",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
};
}
/// <summary>
/// Converts an string to a enum.
/// </summary>
public static ChatRequestSafetyMode? ToEnum(string value)
{
return value switch
{
"CONTEXTUAL" => ChatRequestSafetyMode.CONTEXTUAL,
"STRICT" => ChatRequestSafetyMode.STRICT,
"NONE" => ChatRequestSafetyMode.NONE,
_ => null,
};
}
Copy link

Choose a reason for hiding this comment

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

Improve error handling in ToEnum method.

The ToEnum method should throw an exception for invalid values instead of returning null.

Apply this diff to improve error handling:

public static ChatRequestSafetyMode ToEnum(string value)
{
    return value switch
    {
        "CONTEXTUAL" => ChatRequestSafetyMode.CONTEXTUAL,
        "STRICT" => ChatRequestSafetyMode.STRICT,
        "NONE" => ChatRequestSafetyMode.NONE,
        _ => throw new global::System.ArgumentException($"Invalid value for ChatRequestSafetyMode: {value}"),
    };
}
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
public static class ChatRequestSafetyModeExtensions
{
/// <summary>
/// Converts an enum to a string.
/// </summary>
public static string ToValueString(this ChatRequestSafetyMode value)
{
return value switch
{
ChatRequestSafetyMode.CONTEXTUAL => "CONTEXTUAL",
ChatRequestSafetyMode.STRICT => "STRICT",
ChatRequestSafetyMode.NONE => "NONE",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
};
}
/// <summary>
/// Converts an string to a enum.
/// </summary>
public static ChatRequestSafetyMode? ToEnum(string value)
{
return value switch
{
"CONTEXTUAL" => ChatRequestSafetyMode.CONTEXTUAL,
"STRICT" => ChatRequestSafetyMode.STRICT,
"NONE" => ChatRequestSafetyMode.NONE,
_ => null,
};
}
public static class ChatRequestSafetyModeExtensions
{
/// <summary>
/// Converts an enum to a string.
/// </summary>
public static string ToValueString(this ChatRequestSafetyMode value)
{
return value switch
{
ChatRequestSafetyMode.CONTEXTUAL => "CONTEXTUAL",
ChatRequestSafetyMode.STRICT => "STRICT",
ChatRequestSafetyMode.NONE => "NONE",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
};
}
/// <summary>
/// Converts an string to a enum.
/// </summary>
public static ChatRequestSafetyMode ToEnum(string value)
{
return value switch
{
"CONTEXTUAL" => ChatRequestSafetyMode.CONTEXTUAL,
"STRICT" => ChatRequestSafetyMode.STRICT,
"NONE" => ChatRequestSafetyMode.NONE,
_ => throw new global::System.ArgumentException($"Invalid value for ChatRequestSafetyMode: {value}"),
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant