@@ -92,6 +92,7 @@ func CreateToolCalls(
9292 tools []openaiserverapi.Tool ,
9393 toolChoice openaiserverapi.ToolChoice ,
9494 config * Configuration ,
95+ random * Random ,
9596) ([]openaiserverapi.ToolCall , int , error ) {
9697 generateCalls := func (availableTools []openaiserverapi.Tool , minCalls int ) ([]openaiserverapi.ToolCall , int , error ) {
9798 if len (availableTools ) == 0 {
@@ -102,7 +103,7 @@ func CreateToolCalls(
102103 numberOfCalls := minCalls
103104 if len (availableTools ) > minCalls {
104105 // Randomly decide how many tools to call, between minCalls and the total available.
105- numberOfCalls = RandomInt (minCalls , len (availableTools ))
106+ numberOfCalls = random . RandomInt (minCalls , len (availableTools ))
106107 }
107108
108109 if numberOfCalls == 0 {
@@ -114,11 +115,11 @@ func CreateToolCalls(
114115 // Randomly choose which tool to call. We may call the same tool more than once.
115116 index := 0
116117 if len (availableTools ) > 1 {
117- index = RandomInt (0 , len (availableTools )- 1 )
118+ index = random . RandomInt (0 , len (availableTools )- 1 )
118119 }
119120 chosenTool := availableTools [index ]
120121
121- args , err := generateToolArguments (chosenTool , config )
122+ args , err := generateToolArguments (chosenTool , config , random )
122123 if err != nil {
123124 return nil , 0 , err
124125 }
@@ -133,7 +134,7 @@ func CreateToolCalls(
133134 TokenizedArguments : Tokenize (string (argsJson )),
134135 Name : & chosenTool .Function .Name ,
135136 },
136- ID : "chatcmpl-tool-" + RandomNumericString (10 ),
137+ ID : "chatcmpl-tool-" + random . RandomNumericString (10 ),
137138 Type : "function" ,
138139 Index : i ,
139140 }
@@ -188,18 +189,18 @@ func getRequiredAsMap(property map[string]any) map[string]struct{} {
188189 return required
189190}
190191
191- func generateToolArguments (tool openaiserverapi.Tool , config * Configuration ) (map [string ]any , error ) {
192+ func generateToolArguments (tool openaiserverapi.Tool , config * Configuration , random * Random ) (map [string ]any , error ) {
192193 arguments := make (map [string ]any )
193194 properties , _ := tool .Function .Parameters ["properties" ].(map [string ]any )
194195
195196 required := getRequiredAsMap (tool .Function .Parameters )
196197
197198 for param , property := range properties {
198199 _ , paramIsRequired := required [param ]
199- if ! paramIsRequired && ! RandomBool (config .ToolCallNotRequiredParamProbability ) {
200+ if ! paramIsRequired && ! random . RandomBool (config .ToolCallNotRequiredParamProbability ) {
200201 continue
201202 }
202- arg , err := createArgument (property , config )
203+ arg , err := createArgument (property , config , random )
203204 if err != nil {
204205 return nil , err
205206 }
@@ -209,7 +210,7 @@ func generateToolArguments(tool openaiserverapi.Tool, config *Configuration) (ma
209210 return arguments , nil
210211}
211212
212- func createArgument (property any , config * Configuration ) (any , error ) {
213+ func createArgument (property any , config * Configuration , random * Random ) (any , error ) {
213214 propertyMap , _ := property .(map [string ]any )
214215 paramType := propertyMap ["type" ]
215216
@@ -218,20 +219,20 @@ func createArgument(property any, config *Configuration) (any, error) {
218219 if ok {
219220 enumArray , ok := enum .([]any )
220221 if ok && len (enumArray ) > 0 {
221- index := RandomInt (0 , len (enumArray )- 1 )
222+ index := random . RandomInt (0 , len (enumArray )- 1 )
222223 return enumArray [index ], nil
223224 }
224225 }
225226
226227 switch paramType {
227228 case "string" :
228- return getStringArgument (), nil
229+ return getStringArgument (random ), nil
229230 case "integer" :
230- return RandomInt (config .MinToolCallIntegerParam , config .MaxToolCallIntegerParam ), nil
231+ return random . RandomInt (config .MinToolCallIntegerParam , config .MaxToolCallIntegerParam ), nil
231232 case "number" :
232- return RandomFloat (config .MinToolCallNumberParam , config .MaxToolCallNumberParam ), nil
233+ return random . RandomFloat (config .MinToolCallNumberParam , config .MaxToolCallNumberParam ), nil
233234 case "boolean" :
234- return FlipCoin (), nil
235+ return random . FlipCoin (), nil
235236 case "array" :
236237 items := propertyMap ["items" ]
237238 itemsMap := items .(map [string ]any )
@@ -246,10 +247,10 @@ func createArgument(property any, config *Configuration) (any, error) {
246247 if minItems > maxItems {
247248 return nil , fmt .Errorf ("minItems (%d) is greater than maxItems(%d)" , minItems , maxItems )
248249 }
249- numberOfElements := RandomInt (minItems , maxItems )
250+ numberOfElements := random . RandomInt (minItems , maxItems )
250251 array := make ([]any , numberOfElements )
251252 for i := range numberOfElements {
252- elem , err := createArgument (itemsMap , config )
253+ elem , err := createArgument (itemsMap , config , random )
253254 if err != nil {
254255 return nil , err
255256 }
@@ -262,10 +263,10 @@ func createArgument(property any, config *Configuration) (any, error) {
262263 object := make (map [string ]interface {})
263264 for fieldName , fieldProperties := range objectProperties {
264265 _ , fieldIsRequired := required [fieldName ]
265- if ! fieldIsRequired && ! RandomBool (config .ObjectToolCallNotRequiredParamProbability ) {
266+ if ! fieldIsRequired && ! random . RandomBool (config .ObjectToolCallNotRequiredParamProbability ) {
266267 continue
267268 }
268- fieldValue , err := createArgument (fieldProperties , config )
269+ fieldValue , err := createArgument (fieldProperties , config , random )
269270 if err != nil {
270271 return nil , err
271272 }
@@ -277,8 +278,8 @@ func createArgument(property any, config *Configuration) (any, error) {
277278 }
278279}
279280
280- func getStringArgument () string {
281- index := RandomInt (0 , len (fakeStringArguments )- 1 )
281+ func getStringArgument (random * Random ) string {
282+ index := random . RandomInt (0 , len (fakeStringArguments )- 1 )
282283 return fakeStringArguments [index ]
283284}
284285
0 commit comments