mirror of
https://github.com/openai/openai-go.git
synced 2026-04-01 09:07:22 +09:00
chore(utils): add internal resp to param utility
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package paramutil
|
||||
|
||||
import "github.com/openai/openai-go/packages/param"
|
||||
import (
|
||||
"github.com/openai/openai-go/packages/param"
|
||||
"github.com/openai/openai-go/packages/resp"
|
||||
)
|
||||
|
||||
func AddrIfPresent[T comparable](v param.Opt[T]) *T {
|
||||
if v.IsPresent() {
|
||||
@@ -8,3 +11,12 @@ func AddrIfPresent[T comparable](v param.Opt[T]) *T {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ToOpt[T comparable](v T, meta resp.Field) param.Opt[T] {
|
||||
if meta.IsPresent() {
|
||||
return param.NewOpt(v)
|
||||
} else if meta.IsExplicitNull() {
|
||||
return param.NullOpt[T]()
|
||||
}
|
||||
return param.Opt[T]{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user