11/*
2- * Copyright 2023-2024 the original author or authors.
2+ * Copyright 2023-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1717package org .springframework .ai .moonshot ;
1818
1919import java .util .ArrayList ;
20+ import java .util .HashMap ;
2021import java .util .HashSet ;
2122import java .util .List ;
2223import java .util .Map ;
24+ import java .util .Objects ;
2325import java .util .Set ;
2426
2527import com .fasterxml .jackson .annotation .JsonIgnore ;
@@ -141,7 +143,7 @@ public class MoonshotChatOptions implements FunctionCallingOptions {
141143 private Boolean proxyToolCalls ;
142144
143145 @ JsonIgnore
144- private Map <String , Object > toolContext ;
146+ private Map <String , Object > toolContext = new HashMap <>() ;
145147
146148 public static Builder builder () {
147149 return new Builder ();
@@ -281,6 +283,7 @@ public void setToolContext(Map<String, Object> toolContext) {
281283 }
282284
283285 @ Override
286+ @ SuppressWarnings ("unchecked" )
284287 public MoonshotChatOptions copy () {
285288 return builder ().model (this .model )
286289 .maxTokens (this .maxTokens )
@@ -289,130 +292,46 @@ public MoonshotChatOptions copy() {
289292 .N (this .n )
290293 .presencePenalty (this .presencePenalty )
291294 .frequencyPenalty (this .frequencyPenalty )
292- .stop (this .stop )
295+ .stop (this .stop != null ? new ArrayList <>( this . stop ) : null )
293296 .user (this .user )
294- .tools (this .tools )
297+ .tools (this .tools != null ? new ArrayList <>( this . tools ) : null )
295298 .toolChoice (this .toolChoice )
296- .functionCallbacks (this .functionCallbacks )
297- .functions (this .functions )
299+ .functionCallbacks (this .functionCallbacks != null ? new ArrayList <>( this . functionCallbacks ) : null )
300+ .functions (this .functions != null ? new HashSet <>( this . functions ) : null )
298301 .proxyToolCalls (this .proxyToolCalls )
299- .toolContext (this .toolContext )
302+ .toolContext (this .toolContext != null ? new HashMap <>( this . toolContext ) : null )
300303 .build ();
301304 }
302305
303306 @ Override
304307 public int hashCode () {
305- final int prime = 31 ;
306- int result = 1 ;
307- result = prime * result + ((this .model == null ) ? 0 : this .model .hashCode ());
308- result = prime * result + ((this .frequencyPenalty == null ) ? 0 : this .frequencyPenalty .hashCode ());
309- result = prime * result + ((this .maxTokens == null ) ? 0 : this .maxTokens .hashCode ());
310- result = prime * result + ((this .n == null ) ? 0 : this .n .hashCode ());
311- result = prime * result + ((this .presencePenalty == null ) ? 0 : this .presencePenalty .hashCode ());
312- result = prime * result + ((this .stop == null ) ? 0 : this .stop .hashCode ());
313- result = prime * result + ((this .temperature == null ) ? 0 : this .temperature .hashCode ());
314- result = prime * result + ((this .topP == null ) ? 0 : this .topP .hashCode ());
315- result = prime * result + ((this .user == null ) ? 0 : this .user .hashCode ());
316- result = prime * result + ((this .proxyToolCalls == null ) ? 0 : this .proxyToolCalls .hashCode ());
317- result = prime * result + ((this .toolContext == null ) ? 0 : this .toolContext .hashCode ());
318- return result ;
308+ return Objects .hash (model , maxTokens , temperature , topP , n , presencePenalty , frequencyPenalty , stop , tools ,
309+ toolChoice , functionCallbacks , functions , user , proxyToolCalls , toolContext );
319310 }
320311
321312 @ Override
322- public boolean equals (Object obj ) {
323- if (this == obj ) {
313+ public boolean equals (Object o ) {
314+ if (this == o ) {
324315 return true ;
325316 }
326- if (obj == null ) {
317+ if (!( o instanceof MoonshotChatOptions other ) ) {
327318 return false ;
328319 }
329- if (getClass () != obj .getClass ()) {
330- return false ;
331- }
332- MoonshotChatOptions other = (MoonshotChatOptions ) obj ;
333- if (this .model == null ) {
334- if (other .model != null ) {
335- return false ;
336- }
337- }
338- else if (!this .model .equals (other .model )) {
339- return false ;
340- }
341- if (this .frequencyPenalty == null ) {
342- if (other .frequencyPenalty != null ) {
343- return false ;
344- }
345- }
346- else if (!this .frequencyPenalty .equals (other .frequencyPenalty )) {
347- return false ;
348- }
349- if (this .maxTokens == null ) {
350- if (other .maxTokens != null ) {
351- return false ;
352- }
353- }
354- else if (!this .maxTokens .equals (other .maxTokens )) {
355- return false ;
356- }
357- if (this .n == null ) {
358- if (other .n != null ) {
359- return false ;
360- }
361- }
362- else if (!this .n .equals (other .n )) {
363- return false ;
364- }
365- if (this .presencePenalty == null ) {
366- if (other .presencePenalty != null ) {
367- return false ;
368- }
369- }
370- else if (!this .presencePenalty .equals (other .presencePenalty )) {
371- return false ;
372- }
373- if (this .stop == null ) {
374- if (other .stop != null ) {
375- return false ;
376- }
377- }
378- else if (!this .stop .equals (other .stop )) {
379- return false ;
380- }
381- if (this .temperature == null ) {
382- if (other .temperature != null ) {
383- return false ;
384- }
385- }
386- else if (!this .temperature .equals (other .temperature )) {
387- return false ;
388- }
389- if (this .topP == null ) {
390- if (other .topP != null ) {
391- return false ;
392- }
393- }
394- else if (!this .topP .equals (other .topP )) {
395- return false ;
396- }
397- if (this .user == null ) {
398- return other .user == null ;
399- }
400- else if (!this .user .equals (other .user )) {
401- return false ;
402- }
403- if (this .proxyToolCalls == null ) {
404- return other .proxyToolCalls == null ;
405- }
406- else if (!this .proxyToolCalls .equals (other .proxyToolCalls )) {
407- return false ;
408- }
409- if (this .toolContext == null ) {
410- return other .toolContext == null ;
411- }
412- else if (!this .toolContext .equals (other .toolContext )) {
413- return false ;
414- }
415- return true ;
320+ return Objects .equals (this .model , other .model )
321+ && Objects .equals (this .maxTokens , other .maxTokens )
322+ && Objects .equals (this .temperature , other .temperature )
323+ && Objects .equals (this .topP , other .topP )
324+ && Objects .equals (this .n , other .n )
325+ && Objects .equals (this .presencePenalty , other .presencePenalty )
326+ && Objects .equals (this .frequencyPenalty , other .frequencyPenalty )
327+ && Objects .equals (this .stop , other .stop )
328+ && Objects .equals (this .tools , other .tools )
329+ && Objects .equals (this .toolChoice , other .toolChoice )
330+ && Objects .equals (this .functionCallbacks , other .functionCallbacks )
331+ && Objects .equals (this .functions , other .functions )
332+ && Objects .equals (this .user , other .user )
333+ && Objects .equals (this .proxyToolCalls , other .proxyToolCalls )
334+ && Objects .equals (this .toolContext , other .toolContext );
416335 }
417336
418337 public static class Builder {
0 commit comments