-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
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.
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()); | ||
} |
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.
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.
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.
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) { |
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.
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.
...penai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatRequestSystemMessage.java
Show resolved
Hide resolved
...penai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatRequestSystemMessage.java
Show resolved
Hide resolved
this.content = BinaryData.fromString(content); | ||
this.content = content == null ? null : BinaryData.fromString(content); | ||
this.stringContent = content; | ||
this.chatMessageContentItem = null; |
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.
Should we do this(BinaryData.fromString(content))
so we get branch coverage for the generated constructor as well?
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.
We can't. As the other final
properties can't not be assigned.
This PR includes:
Update ChatRequestMessages class families,
ChatRequestSystemMessage
,ChatRequestAssistantMessage
,ChatRequestToolMessage
classes to be able to support forChatRequestSystemMessage
content: | string | ChatMessageTextContentItem[]ChatRequestAssistantMessage
content: | string | ChatMessageTextContentItem[] | ChatMessageRefusalContentItem[] | null (only Assistant can be null)ChatRequestToolMessage
content: | string | ChatMessageTextContentItem[]Also, re-record all tests