-
-
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 new methods for retrieving messages and submitting tool outputs in AI21 API #33
Conversation
WalkthroughThe changes introduce new functionalities to the AI21 API, specifically for retrieving messages from assistant threads and submitting tool outputs. New methods and response models have been added to support these operations, including asynchronous methods for handling HTTP requests and responses. The OpenAPI specification has also been updated to reflect these new endpoints and data structures, enhancing the API's capabilities for managing assistant interactions. Changes
Possibly related PRs
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 13
Outside diff range and nitpick comments (7)
src/libs/AI21/Generated/AI21.Models.GetMessagesResponse.g.cs (1)
1-24
: LGTM! Consider adding meaningful XML documentation comments.The
GetMessagesResponse
class and its properties are well-structured and follow appropriate naming conventions. The use ofJsonPropertyName
,JsonRequired
, andJsonExtensionData
attributes ensures proper serialization and deserialization of the JSON response.To improve code readability and maintainability, consider adding meaningful XML documentation comments for the class and its properties. For example:
/// <summary> /// Represents the response object for retrieving messages from an assistant thread. /// </summary> public sealed partial class GetMessagesResponse { /// <summary> /// Gets or sets the list of message responses. /// </summary> [global::System.Text.Json.Serialization.JsonPropertyName("results")] [global::System.Text.Json.Serialization.JsonRequired] public required global::System.Collections.Generic.IList<global::AI21.MessageResponse> Results { get; set; } /// <summary> /// Gets or sets 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>(); }src/libs/AI21/Generated/AI21.Models.MessageResponse.g.cs (6)
27-32
: Add a description to the XML documentation comment.The
Content
property is correctly defined as a required string. However, the XML documentation comment is missing a description of the property. Consider adding a brief description to provide more context and clarity about the purpose and content of this property.
43-48
: Add a description to the XML documentation comment.The
CreatedAt
property is correctly defined as a requiredDateTime
. However, the XML documentation comment is missing a description of the property. Consider adding a brief description to provide more context and clarity about the purpose and content of this property, such as indicating that it represents the timestamp when the message was created.
50-55
: Add a description to the XML documentation comment.The
UpdatedAt
property is correctly defined as a requiredDateTime
. However, the XML documentation comment is missing a description of the property. Consider adding a brief description to provide more context and clarity about the purpose and content of this property, such as indicating that it represents the timestamp when the message was last updated.
57-62
: Add a description to the XML documentation comment.The
Object
property is correctly defined as a required string. However, the XML documentation comment is missing a description of the property. Consider adding a brief description to provide more context and clarity about the purpose and content of this property, such as indicating the type of object this property represents.
64-69
: Add a description to the XML documentation comment.The
ThreadId
property is correctly defined as a required string. However, the XML documentation comment is missing a description of the property. Consider adding a brief description to provide more context and clarity about the purpose and content of this property, such as indicating that it represents the unique identifier of the thread to which the message belongs.
71-75
: Add a description to the XML documentation comment.The
AssistantId
property is correctly defined as an optional string. However, the XML documentation comment is missing a description of the property. Consider adding a brief description to provide more context and clarity about the purpose and content of this property, such as indicating that it represents the unique identifier of the assistant associated with the message, if applicable.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- src/libs/AI21/Generated/AI21.Ai21Api.GetMessagesStudioV1AssistantThreadsThreadIdMessagesGet.g.cs (1 hunks)
- src/libs/AI21/Generated/AI21.Ai21Api.SubmitToolOutputsStudioV1AssistantThreadsThreadIdRunsRunIdSubmitToolOutputsPost.g.cs (1 hunks)
- src/libs/AI21/Generated/AI21.Models.GetMessagesResponse.g.cs (1 hunks)
- src/libs/AI21/Generated/AI21.Models.MessageResponse.g.cs (1 hunks)
- src/libs/AI21/Generated/AI21.Models.SubmitToolOutputsRequest.g.cs (1 hunks)
- src/libs/AI21/Generated/AI21.Models.SubmitToolOutputsResponse.g.cs (1 hunks)
- src/libs/AI21/Generated/JsonSerializerContextTypes.g.cs (1 hunks)
- src/libs/AI21/openapi.yaml (5 hunks)
Files skipped from review due to trivial changes (1)
- src/libs/AI21/Generated/AI21.Models.SubmitToolOutputsRequest.g.cs
Additional comments not posted (9)
src/libs/AI21/Generated/AI21.Models.SubmitToolOutputsResponse.g.cs (1)
1-18
: LGTM!The
SubmitToolOutputsResponse
class looks good:
- The class is properly defined in the
AI21
namespace.- The
AdditionalProperties
property is correctly defined to capture any additional properties in the JSON response.- The
[JsonExtensionData]
attribute is used correctly to serialize and deserialize the additional properties.- The property is initialized with an empty dictionary, which is a good practice to avoid null reference exceptions.
Overall, the class is well-structured and follows best practices.
src/libs/AI21/Generated/AI21.Models.MessageResponse.g.cs (2)
11-25
: LGTM!The
Role
property is correctly defined as a required string, and the XML documentation comment provides clear and detailed information about the possible values and their meanings.
34-41
: LGTM!The
Id
property is correctly defined as a required string, and the XML documentation comment provides clear and detailed information about the purpose of the property.src/libs/AI21/Generated/AI21.Ai21Api.GetMessagesStudioV1AssistantThreadsThreadIdMessagesGet.g.cs (1)
30-87
: LGTM!The
GetMessagesStudioV1AssistantThreadsThreadIdMessagesGetAsync
method is well-implemented and follows the best practices for making an asynchronous HTTP request and processing the response. The method uses theConfigureAwait(false)
method to avoid capturing the current context and to improve performance. The method also uses theEnsureSuccessStatusCode
method to throw an exception if the response status code is not successful, and the null-coalescing operator??
to throw an exception if the response deserialization fails. The method uses theSourceGenerationContext.Default.GetMessagesResponse
property to get theJsonSerializerOptions
object for deserialization, which is a good practice. The method also uses theref
keyword to pass thethreadId
parameter by reference to thePrepareGetMessagesStudioV1AssistantThreadsThreadIdMessagesGetArguments
method, which is a good practice to avoid unnecessary string allocations. Finally, the method uses theusing
statement to dispose theHttpRequestMessage
andHttpResponseMessage
objects, which is a good practice to avoid memory leaks.src/libs/AI21/Generated/AI21.Ai21Api.SubmitToolOutputsStudioV1AssistantThreadsThreadIdRunsRunIdSubmitToolOutputsPost.g.cs (2)
36-107
: LGTM!The
SubmitToolOutputsStudioV1AssistantThreadsThreadIdRunsRunIdSubmitToolOutputsPostAsync
method follows a standard pattern for making asynchronous HTTP requests and processing responses. It properly handles exceptions and ensures a successful status code before deserializing the response content.
116-130
: LGTM!This overload of the
SubmitToolOutputsStudioV1AssistantThreadsThreadIdRunsRunIdSubmitToolOutputsPostAsync
method provides a convenient way to call the API endpoint without having to create aSubmitToolOutputsRequest
object explicitly. It delegates the call to the other overload, passing the required parameters.src/libs/AI21/Generated/JsonSerializerContextTypes.g.cs (1)
Line range hint
1-760
: Class structure looks good, but ensure the type changes are intentional and thoroughly tested.The
JsonSerializerContextTypes
class appears to be a generated class used for JSON serialization and deserialization. It contains many properties, each representing a different type used in the serialization context.The changes mostly involve modifying the types of these properties, which could have implications on how the data is serialized and deserialized. It's important to ensure that these type changes are intentional, and that they have been thoroughly tested to confirm they don't introduce any breaking changes or unexpected behavior.
Additionally, several new properties have been added at the end of the class, expanding the types that can be serialized. Again, make sure these additions are necessary and have been properly integrated with the rest of the codebase.
To verify the impact of these changes, I suggest running the following script:
src/libs/AI21/openapi.yaml (2)
1353-1376
: LGTM!The new
GET
endpoint for retrieving messages associated with a specific thread is well-defined, with the requiredthread_id
parameter and the appropriate response schema.
Line range hint
2393-2737
: LGTM!The
GetMessagesResponse
andMessageResponse
schema definitions are well-structured and provide a clear representation of the API response. The required fields are properly marked, and the field formats are appropriately used.
public global::AI21.GetMessagesResponse? Type89 { get; set; } | ||
/// <summary> | ||
/// |
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.
Ensure usages of Type89
are updated to handle GetMessagesResponse
.
The type of Type89
has been changed from GetThreadRunResponse
to GetMessagesResponse
. This suggests it is now used for a different purpose. Make sure all code that uses Type89
has been updated to expect and handle the GetMessagesResponse
type instead of GetThreadRunResponse
.
public global::System.Collections.Generic.IList<global::AI21.MessageResponse>? Type90 { get; set; } | ||
/// <summary> | ||
/// |
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.
Major type change for Type90
, refactor usages carefully.
Type90
has undergone a major type change, from RunStatus
to IList<MessageResponse>
. This is a significant change from a single value to a list. All code that uses Type90
will need to be carefully refactored to handle a list of MessageResponse
instead of a single RunStatus
. Take extra care with this change and thoroughly test all affected code paths.
public global::AI21.MessageResponse? Type91 { get; set; } | ||
/// <summary> | ||
/// |
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.
Update usages of Type91
to handle MessageResponse
.
Type91
has been changed from RunOptimization
to MessageResponse
. While this is still a single value, the different type needs to be handled correctly in all places where Type91
is used. Update these usages to expect and handle the MessageResponse
type.
public global::AI21.GetThreadRunResponse? Type92 { get; set; } | ||
/// <summary> | ||
/// |
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.
Update usages of Type92
to handle GetThreadRunResponse
.
The type of Type92
has been changed from HTTPValidationError
to GetThreadRunResponse
, switching between two different response types. Make sure all code that uses Type92
has been updated to expect and handle the GetThreadRunResponse
type.
public global::AI21.RunStatus? Type93 { get; set; } | ||
/// <summary> | ||
/// |
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.
Significant type change for Type93
, carefully refactor usages.
Type93
has been changed from IList<ValidationError>
to RunStatus
, which is a significant change from a list to a single value. All code that uses Type93
will need to be carefully refactored to handle a single RunStatus
instead of a list of ValidationError
. This change requires extra attention and thorough testing.
public global::AI21.ValidationError? Type97 { get; set; } | ||
/// <summary> | ||
/// |
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.
Update usages of Type97
to handle ValidationError
.
The type of Type97
has been changed from Highlight
to ValidationError
. Make sure all code that uses Type97
has been updated to expect and handle the ValidationError
type.
public global::System.Collections.Generic.IList<global::System.AnyOf<string, int?>>? Type98 { get; set; } | ||
/// <summary> | ||
/// |
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.
Type98
changed to complex list type, carefully refactor usages.
Type98
has been changed from LibraryAnswerRequest
, a single request type, to IList<AnyOf<string, int?>>
, a list of a complex AnyOf
type. This is a significant change that will require careful refactoring of all code that uses Type98
. Pay extra attention to correctly handle this list of complex types and thoroughly test the refactored code.
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1J2JumboCompleteResponse2? Type166 { get; set; } | ||
public global::AI21.V1J2GrandeInstructCompleteResponse? Type166 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1GetCustomModelsResponse? Type167 { get; set; } | ||
public global::AI21.V1J2JumboCompleteResponse? Type167 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1CreateCustomModelResponse? Type168 { get; set; } | ||
public global::AI21.V1J2JumboInstructCompleteResponse? Type168 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1GetCustomModelResponse? Type169 { get; set; } | ||
public global::AI21.V1J2LargeCustomModelCompleteResponse? Type169 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1UpdateCustomModelResponse? Type170 { get; set; } | ||
public global::AI21.V1J2GrandeCustomModelCompleteResponse? Type170 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1GetDatasetsResponse? Type171 { get; set; } | ||
public global::AI21.V1J2JumboCompleteResponse2? Type171 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1UploadDatasetResponse? Type172 { get; set; } | ||
public global::AI21.V1GetCustomModelsResponse? Type172 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1GetDatasetResponse? Type173 { get; set; } | ||
public global::AI21.V1CreateCustomModelResponse? Type173 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1DeleteDatasetResponse? Type174 { get; set; } | ||
public global::AI21.V1GetCustomModelResponse? Type174 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1GetDatasetDownloadUrlResponse? Type175 { get; set; } | ||
public global::AI21.V1UpdateCustomModelResponse? Type175 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1ParaphrazeResponse? Type176 { get; set; } | ||
public global::AI21.V1GetDatasetsResponse? Type176 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1EmbedResponse? Type177 { get; set; } | ||
public global::AI21.V1UploadDatasetResponse? Type177 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::System.Collections.Generic.IList<global::AI21.FileResponse>? Type178 { get; set; } | ||
public global::AI21.V1GetDatasetResponse? Type178 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1LibraryManagementResponse? Type179 { get; set; } | ||
public global::AI21.V1DeleteDatasetResponse? Type179 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1AnswerResponse? Type180 { get; set; } | ||
public global::AI21.V1GetDatasetDownloadUrlResponse? Type180 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1TokenizeResponse? Type181 { get; set; } | ||
public global::AI21.V1ParaphrazeResponse? Type181 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1EmbedResponse? Type182 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::System.Collections.Generic.IList<global::AI21.FileResponse>? Type183 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1LibraryManagementResponse? Type184 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1AnswerResponse? Type185 { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public global::AI21.V1TokenizeResponse? Type186 { get; set; } |
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.
Thoroughly review and test all type changes.
The remaining properties (Type99
through Type186
) have undergone similar type changes as the ones reviewed in detail above. These changes include:
- Switching between different single value types
- Changing from single value types to list types and vice versa
- Changing from one complex type to another
For each of these changes, it's crucial to:
- Identify all places in the codebase where these properties are used.
- Refactor the code to correctly handle the new types.
- Thoroughly test the refactored code to ensure it works as expected with the new types.
Pay special attention to changes that involve complex types or switching between single values and lists, as these will require the most significant refactoring.
Also, make sure the newly added properties (Type182
through Type186
) are being used correctly and consistently with the rest of the codebase.
Given the extensive nature of these changes, I highly recommend a comprehensive testing strategy to verify that all affected functionality works correctly with the new types.
SubmitToolOutputsRequest: | ||
title: SubmitToolOutputsRequest | ||
type: object | ||
SubmitToolOutputsResponse: | ||
title: SubmitToolOutputsResponse | ||
type: 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.
Define the request and response schemas.
The SubmitToolOutputsRequest
and SubmitToolOutputsResponse
schemas are currently empty, which makes it unclear what data should be sent in the request and what the API consumer can expect in the response.
To provide a clear contract for the submit_tool_outputs
endpoint, please define the necessary fields and their types in the request and response schemas. Consider including information such as:
-
For
SubmitToolOutputsRequest
:- The structure of the tool outputs being submitted
- Any additional metadata or parameters required for the submission
-
For
SubmitToolOutputsResponse
:- The status of the submission (success/failure)
- Any relevant information or acknowledgment returned by the API
Defining these schemas will help ensure consistency and make it easier for API consumers to interact with the endpoint correctly.
'/studio/v1/assistant/threads/{thread_id}/runs/{run_id}/submit_tool_outputs': | ||
post: | ||
summary: Submit Tool Outputs | ||
operationId: submit_tool_outputs_studio_v1_assistant_threads__thread_id__runs__run_id__submit_tool_outputs_post | ||
parameters: | ||
- name: thread_id | ||
in: path | ||
required: true | ||
schema: | ||
title: Thread Id | ||
type: string | ||
format: uuid | ||
- name: run_id | ||
in: path | ||
required: true | ||
schema: | ||
title: Run Id | ||
type: string | ||
format: uuid | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SubmitToolOutputsRequest' | ||
required: true | ||
responses: | ||
'200': | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SubmitToolOutputsResponse' | ||
'422': | ||
description: Validation Error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/HTTPValidationError' |
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.
Tip
Codebase Verification
Review and update the SubmitToolOutputsRequest
and SubmitToolOutputsResponse
schemas.
The SubmitToolOutputsRequest
and SubmitToolOutputsResponse
schemas are defined but lack detailed properties and required fields. This could lead to issues with API consumers relying on these schemas for validation and data structure.
- Ensure that these schemas are fully defined with necessary properties and constraints to maintain a clear and functional API contract.
Analysis chain
Verify the consistency of the referenced schemas.
The new POST
endpoint for submitting tool outputs is well-defined, with the required thread_id
and run_id
parameters, and the appropriate request body and response schemas.
To ensure the consistency and completeness of the API specification, please verify that the referenced SubmitToolOutputsRequest
and SubmitToolOutputsResponse
schemas are properly defined in the components.schemas
section of the OpenAPI document.
Run the following script to search for the schema definitions:
If the schemas are missing or incomplete, please update the OpenAPI document accordingly to maintain consistency and provide a clear contract for API consumers.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the existence and structure of the referenced schemas.
# Test 1: Search for the request schema definition.
rg --type yaml -A 10 $'SubmitToolOutputsRequest:'
# Test 2: Search for the response schema definition.
rg --type yaml -A 10 $'SubmitToolOutputsResponse:'
Length of output: 1224
Script:
#!/bin/bash
# Description: Extract detailed information about the properties and required fields of the referenced schemas.
# Test 1: Extract detailed information for the request schema.
rg --type yaml -A 20 $'SubmitToolOutputsRequest:' src/libs/AI21/openapi.yaml
# Test 2: Extract detailed information for the response schema.
rg --type yaml -A 20 $'SubmitToolOutputsResponse:' src/libs/AI21/openapi.yaml
Length of output: 1477
Summary by CodeRabbit
Release Notes
New Features
Enhancements
Documentation