Skip to content

Refactor Options #406

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

Closed

Conversation

youngmoneee
Copy link
Contributor

In the original code, Builders and Setters were used concurrently.
This approach could compromise object immutability in multi-threaded environments,
potentially leading to undesirable side effects.

To mitigate this, Setters have been removed to enhance and ensure object immutability.

  • Remove setters
  • Add a builder method that references existing objects
  • Enhance the immutability of collections returned by getters
  • Add test code reflecting the changes

remove setter
Remove setters from the object, and separate creation and usage
to enable safe usage in a multi-threaded environment.
add test code for the modified changes
@tzolov tzolov modified the milestones: 1.0.0-M1, 0.8.1 Mar 6, 2024

/**
* @author Christian Tzolov
*/
public interface FunctionCallingOptions {
public interface FunctionCallingOptions extends ChatOptions {
Copy link
Member

Choose a reason for hiding this comment

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

FunctionCallingOptions not extending ChatOptions was intentional in order to provide support finer grained support of what features can be opted into. Also, the code didn't compile after this change, so be sure to do a compilation of the total project before submitting a PR please.

@@ -25,14 +25,8 @@ public interface ChatOptions extends ModelOptions {

Float getTemperature();

void setTemperature(Float temperature);
Copy link
Member

Choose a reason for hiding this comment

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

removing these setters also required to remove the @Override annotations on all implementing classes. As a result the project didn't compile. Please make sure the changes you make compile before sending a PR.


Integer newTopK = 222;

ChatOptions newOptions = ChatOptionsBuilder.builder(options)
Copy link
Member

Choose a reason for hiding this comment

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

This sort of copy constructor for the builder is interesting, but please put in a separate PR

assertThat(options.getFunctions().contains(func));

// Immutable
options.getFunctionCallbacks().add(cb);
Copy link
Member

Choose a reason for hiding this comment

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

If we want the created options class to be immutable then we should create a non modifiable collection and throw an exception. We would also need to ensure that all the other options classes behave the same way.

@markpollack
Copy link
Member

I've created #407 and #408 to discuss changes to how builders behave across the code base.

@markpollack
Copy link
Member

merged only the setter removal as 3938cc8

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.

3 participants