From 8794b5354a0286e8ac0461a2467e30eb53567dbb Mon Sep 17 00:00:00 2001 From: LGXerxes Date: Wed, 10 Jul 2024 15:12:32 +0200 Subject: [PATCH 1/3] added ParallelToolCalls to ChatCompletionRequest with helper functions --- chat.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chat.go b/chat.go index a1eb11720..9e71b8b0b 100644 --- a/chat.go +++ b/chat.go @@ -218,6 +218,18 @@ type ChatCompletionRequest struct { ToolChoice any `json:"tool_choice,omitempty"` // Options for streaming response. Only set this when you set stream: true. StreamOptions *StreamOptions `json:"stream_options,omitempty"` + // Disable the default behavior of parallel tool calls. + ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"` +} + +func ParallelOptionFalse() *bool { + b := false + return &b +} + +func ParallelOptionTrue() *bool { + b := true + return &b } type StreamOptions struct { From cc1ea0be5d56ee9739dc8354df362be9cf8a0335 Mon Sep 17 00:00:00 2001 From: LGXerxes Date: Wed, 10 Jul 2024 15:39:24 +0200 Subject: [PATCH 2/3] added tests for coverage --- chat_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chat_test.go b/chat_test.go index 520bf5ca4..1a1c44bd5 100644 --- a/chat_test.go +++ b/chat_test.go @@ -527,3 +527,21 @@ func TestFinishReason(t *testing.T) { } } } + +func TestParallelOption(t *testing.T) { + ccr := openai.ChatCompletionRequest{} + + if ccr.ParallelToolCalls != nil { + t.Error("ParallelToolCalls should be default") + } + ccr.ParallelToolCalls = openai.ParallelOptionFalse() + + if *ccr.ParallelToolCalls != false { + t.Error("ParallelToolCalls should be false") + } + + ccr.ParallelToolCalls = openai.ParallelOptionTrue() + if *ccr.ParallelToolCalls != true { + t.Error("ParallelToolCalls should be true") + } +} From c0fbbb6e1aef2da91cbf3c96a5d9d4b3f43be37d Mon Sep 17 00:00:00 2001 From: LGXerxes Date: Fri, 12 Jul 2024 08:55:50 +0200 Subject: [PATCH 3/3] changed ParallelToolCalls to any --- chat.go | 14 ++------------ chat_test.go | 18 ------------------ 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/chat.go b/chat.go index 9e71b8b0b..eb494f41f 100644 --- a/chat.go +++ b/chat.go @@ -218,18 +218,8 @@ type ChatCompletionRequest struct { ToolChoice any `json:"tool_choice,omitempty"` // Options for streaming response. Only set this when you set stream: true. StreamOptions *StreamOptions `json:"stream_options,omitempty"` - // Disable the default behavior of parallel tool calls. - ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"` -} - -func ParallelOptionFalse() *bool { - b := false - return &b -} - -func ParallelOptionTrue() *bool { - b := true - return &b + // Disable the default behavior of parallel tool calls by setting it: false. + ParallelToolCalls any `json:"parallel_tool_calls,omitempty"` } type StreamOptions struct { diff --git a/chat_test.go b/chat_test.go index 1a1c44bd5..520bf5ca4 100644 --- a/chat_test.go +++ b/chat_test.go @@ -527,21 +527,3 @@ func TestFinishReason(t *testing.T) { } } } - -func TestParallelOption(t *testing.T) { - ccr := openai.ChatCompletionRequest{} - - if ccr.ParallelToolCalls != nil { - t.Error("ParallelToolCalls should be default") - } - ccr.ParallelToolCalls = openai.ParallelOptionFalse() - - if *ccr.ParallelToolCalls != false { - t.Error("ParallelToolCalls should be false") - } - - ccr.ParallelToolCalls = openai.ParallelOptionTrue() - if *ccr.ParallelToolCalls != true { - t.Error("ParallelToolCalls should be true") - } -}