betalgo / openai

OpenAI .NET sdk - Azure OpenAI, ChatGPT, Whisper, and DALL-E
https://betalgo.github.io/openai/
MIT License
2.89k stars 521 forks source link

Temperature on AudioCreateTranscriptionRequest is not working. #484

Closed carlosmixz closed 8 months ago

carlosmixz commented 8 months ago

When you call the AudioCreateTranscriptionRequest and set the temperature param, thats give a float error on a JSON

        Dim FilenameMinArquivo = "Audio.mp3"
        Dim Request As New AudioCreateTranscriptionRequest With {
                                                        .FileName = FilenameMinArquivo,
                                                        .File = sampleFile,
                                                        .Temperature = 0.2,
                                                        .Model = Models.WhisperV1,
                                                        .ResponseFormat = StaticValues.AudioStatics.ResponseFormat.Srt}

        Dim GerarResult = Gpt3.Audio.CreateTranscription(Request)

        While Not GerarResult.IsCompleted
            EsperaMS(16)
        End While

        If GerarResult.Result.Successful Then

            If Convertido Then
                File.Delete(Filename)
            End If

            If GerarResult.Result.Text.StartsWith("{") Then
                Throw New Exception(GerarResult.Result.Text)
            End If

            Return GerarResult.Result.Text

        Else
            Throw New Exception(GerarResult.Result.Error.Message)
        End If

image

The expected is a diferent transcription

Desktop (please complete the following information):

kayhantolga commented 8 months ago

Hi, I don't have knowledge of VB, but the code works fine with C#. I asked ChatGPT about your issue and shared the answer below, which may help you. Feel free to let me know if this doesn't solve your issue. User what is the value type of Temperature here?

 Dim FilenameMinArquivo = "Audio.mp3"
        Dim Request As New AudioCreateTranscriptionRequest With {
                                                        .FileName = FilenameMinArquivo,
                                                        .File = sampleFile,
                                                        .Temperature = 0.2,
                                                        .Model = Models.WhisperV1,
                                                        .ResponseFormat = StaticValues.AudioStatics.ResponseFormat.Srt}

        Dim GerarResult = Gpt3.Audio.CreateTranscription(Request)

        While Not GerarResult.IsCompleted
            EsperaMS(16)
        End While

        If GerarResult.Result.Successful Then

            If Convertido Then
                File.Delete(Filename)
            End If

            If GerarResult.Result.Text.StartsWith("{") Then
                Throw New Exception(GerarResult.Result.Text)
            End If

            Return GerarResult.Result.Text

        Else
            Throw New Exception(GerarResult.Result.Error.Message)
        End If

ChatGPT In the provided code snippet, the Temperature property is being used as part of an AudioCreateTranscriptionRequest object. The value type of Temperature here is Double. This is inferred from the assignment of 0.2 to the Temperature property. In .NET (and VB.NET, as this code appears to be), decimal literals without any suffix are treated as Double by default, which is a floating-point numeric type capable of holding both very small and very large numbers.

User how can I make it float ChatGPT To explicitly make the Temperature property a Float in VB.NET, you would typically use the F or f suffix on the numeric literal to denote a Single (the VB.NET term for a floating-point value that is less precise and smaller in range than a Double). However, VB.NET does not use the F or f suffix like C# does. Instead, VB.NET uses type conversion functions or specifies the type directly if necessary.

In your case, since VB.NET does not directly support a suffix to make literals a Single, you would ensure that the Temperature property itself is declared to accept Single values, or you would explicitly convert the value to Single when assigning it, like so:

vb.net Copy code .Temperature = CSng(0.2) CSng is a VB.NET function that converts an expression to a Single. This ensures that the Temperature is explicitly treated as a Float (or Single in VB.NET terminology). However, it's important to note that this conversion should match the expected type of the Temperature property in your AudioCreateTranscriptionRequest class. If the property is defined to accept Double, you might need to adjust the class definition to accept Single instead, if you specifically need to use Single for some reason.

Here's how you might adjust the class definition, assuming you have access and can change it:

Public Class AudioCreateTranscriptionRequest
    Public Property FileName As String
    Public Property File As Object ' Assuming sampleFile is of an object type
    Public Property Temperature As Single ' Changed from Double to Single
    Public Property Model As Models
    Public Property ResponseFormat As StaticValues.AudioStatics.ResponseFormat
End Class

Changing the property type to Single will enforce that Temperature is always a float when instances of AudioCreateTranscriptionRequest are created or manipulated.

carlosmixz commented 8 months ago

I'm using the nuget lib, because of this i dont have the acess to change the property type, but it apears "single?" when i put the mouse over. In VB.NET the conversions works automatically, in this case, wathever the type of the number set in .temperature =, its change to single, anyway i tried to make the "CSng(0.2)", and it not worked.