openai/openai-go

Public

mirrored from https://github.com/openai/openai-goAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
jacob/file-param-example

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/param/field.go

27lines · modecode

1package param
2
3import "fmt"
4
5type FieldLike interface{ field() }
6
7// Field is a wrapper used for all values sent to the API,
8// to distinguish zero values from null or omitted fields.
9//
10// It also allows sending arbitrary deserializable values.
11//
12// To instantiate a Field, use the helpers exported from
13// the package root: `F()`, `Null()`, `Raw()`, etc.
14type Field[T any] struct {
15 FieldLike
16 Value T
17 Null bool
18 Present bool
19 Raw any
20}
21
22func (f Field[T]) String() string {
23 if s, ok := any(f.Value).(fmt.Stringer); ok {
24 return s.String()
25 }
26 return fmt.Sprintf("%v", f.Value)
27}
28