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

[OpenAI] Update ChatRequestMessage class family and unit tests #41928

Merged
merged 4 commits into from
Sep 25, 2024

Conversation

mssfang
Copy link
Member

@mssfang mssfang commented Sep 19, 2024

This PR includes:

Update ChatRequestMessages class families, ChatRequestSystemMessage, ChatRequestAssistantMessage, ChatRequestToolMessage classes to be able to support for

  • ChatRequestSystemMessage content: | string | ChatMessageTextContentItem[]
  • ChatRequestAssistantMessage content: | string | ChatMessageTextContentItem[] | ChatMessageRefusalContentItem[] | null (only Assistant can be null)
  • ChatRequestToolMessage content: | string | ChatMessageTextContentItem[]

Also, re-record all tests

Copy link
Member

@jpalvarezl jpalvarezl left a comment

Choose a reason for hiding this comment

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

Sorry for the comment spread, I am approving because this looks really good :) Thanks! Just to summarize my comments that I believe would be good to apply to all ChatRequest*Message types:

  • Make the constructor accepting BinaryData private
  • Use this(BinaryData.from...); where possible to get branch coverage
  • Don't throw in the fromJson methods, even though they shouldn't generally be called for these types, we might corner ourselves by being too strict in this scenario (i.e., lack of support parity between Azure and non-Azure request message types, in the future)

} else {
throw new IllegalStateException("Unexpected 'content' type found when deserializing"
+ " ChatRequestAssistantMessage JSON object: " + reader.currentToken());
}
Copy link
Member

@jpalvarezl jpalvarezl Sep 25, 2024

Choose a reason for hiding this comment

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

I think we may want to be less strict here, specially if at some point we don't have parity with non-Azure OpenAI. WDYT? Also, this might be a non issue, since this class seems to be used only for request and will therefore never be deserialized.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer to be strict as we know other token types should not be serialized. I would leave it as it is for now and we can update it later when "parity with Non-Azure OpenAI" raised.

*/
@Generated
public ChatRequestAssistantMessage(BinaryData content) {
Copy link
Member

Choose a reason for hiding this comment

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

We may want to make this constructor private, seeing that you have already added a couple of convenience ctxs with types that are more user friendly.

this.content = BinaryData.fromString(content);
this.content = content == null ? null : BinaryData.fromString(content);
this.stringContent = content;
this.chatMessageContentItem = null;
Copy link
Member

Choose a reason for hiding this comment

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

Should we do this(BinaryData.fromString(content)) so we get branch coverage for the generated constructor as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't. As the other final properties can't not be assigned.

@mssfang mssfang merged commit 354c393 into Azure:OpenAI-2024-08-01 Sep 25, 2024
19 of 20 checks passed
@mssfang mssfang deleted the OpenAI-ApplyChanges branch September 25, 2024 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants