Skip to content

Commit b1e8673

Browse files
authored
fix for non-English systems
In systems configured to use "," (comma) as decimal separator, such as with the Italian regional settings, number of type Double such as the temperature are converted to strings like "0,5" instead of "0.5". OpenAI API doesn't accept "," as decimal separator, and therefore the HTTP call fails. This commit fixes this bug.
1 parent 1f706c9 commit b1e8673

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

clsOpenAIRequest.cls

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Private mlngMaxTokens As Long
4242
Private mdblTopP As Double
4343
Private mdblTemperature As Double
4444
Private mdblFrequencyPenalty As Double
45-
Private mdlPresencePenalty As Double
45+
Private mdblPresencePenalty As Double
4646
Private mstrPrompt As String
4747
Private mlngImageWidth As Long
4848
Private mlngImageHeight As Long
@@ -115,7 +115,7 @@ Public Property Let FrequencyPenalty(ByVal value As Double)
115115
End Property
116116

117117
Public Property Let PresencePenalty(ByVal value As Double)
118-
mdlPresencePenalty = value
118+
mdblPresencePenalty = value
119119
End Property
120120

121121
Public Property Get ImageHeight() As Long
@@ -168,7 +168,7 @@ End Property
168168

169169

170170
Public Function GetChatSendToAPIJsonString() As String
171-
GetChatSendToAPIJsonString = "{""model"": """ & mstrModel & """, " & mobjMessages.GetAllMessages & ", ""max_tokens"": " & mlngMaxTokens & ", ""top_p"": " & mdblTopP & ", ""temperature"": " & mdblTemperature & ", ""frequency_penalty"": " & mdblFrequencyPenalty & ", ""presence_penalty"": " & mdlPresencePenalty & "}"
171+
GetChatSendToAPIJsonString = "{""model"": """ & mstrModel & """, " & mobjMessages.GetAllMessages & ", ""max_tokens"": " & mlngMaxTokens & ", ""top_p"": " & DblToEnglishStr(mdblTopP) & ", ""temperature"": " & DblToEnglishStr(mdblTemperature) & ", ""frequency_penalty"": " & DblToEnglishStr(mdblFrequencyPenalty) & ", ""presence_penalty"": " & mdblPresencePenalty & "}"
172172
End Function
173173

174174

@@ -182,3 +182,18 @@ End Function
182182
Public Function GetImageDimensionLabel() As String
183183
GetImageDimensionLabel = Chr(34) & CStr(mlngImageWidth) & "x" & CStr(mlngImageHeight) & Chr(34)
184184
End Function
185+
186+
187+
Private Function DblToEnglishStr(dblNumber As Double) As String
188+
'Purpose: Normalize formatting of number with decimals to English format
189+
190+
' Convert the double to string using system's regional settings
191+
Dim strNumber As String
192+
strNumber = CStr(dblNumber)
193+
194+
' Replace comma with period if system uses comma as decimal separator (eg. Italian format)
195+
strNumber = Replace(strNumber, ",", ".")
196+
197+
' Return the formatted string
198+
DblToEnglishStr = strNumber
199+
End Function

0 commit comments

Comments
 (0)