PullRequestInc / go-gpt3

An OpenAI GPT-3 API client enabling Go/Golang programs to interact with the gpt3 APIs.
MIT License
393 stars 65 forks source link

Setting the Temperature in the CompletionRequest #5

Closed BrianMwangi21 closed 2 years ago

BrianMwangi21 commented 2 years ago

Hi there,

So I am trying to add the Temperature in the CompletionRequest as shown below : Temperature: float32(0.45),

However, when I try to run the file, the error I receive is the following : cannot use float32(0.45) (type float32) as type *float32 in field value

Can someone help me the value that is expected in the Temperature field ? Thanks.

3l0w commented 2 years ago

you can do the trick like that:

declare a method to get the float32 pointer

func floatPtr(f float32) *float32 {
    return &f
}

and then:

Temperature: floatPtr(0.45)
tylermann commented 2 years ago

Thanks @3l0w.

Yes this requires a pointer parameter because the "empty" value for a float of "0" has a different meaning than a nil pointer. There is a helper for this for ints but would be nice to add for floats too but you can certainly write your own function as mentioned above.

You can assign to a local variable before and then pass the pointer like this:

temperature := 0.45
Temperature: &temperature,