openai/openai-go
Publicmirrored from https://github.com/openai/openai-goAvailable
shared/shared.go
206lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | package shared |
| 4 | |
| 5 | import ( |
| 6 | "github.com/openai/openai-go/internal/apijson" |
| 7 | "github.com/openai/openai-go/internal/param" |
| 8 | ) |
| 9 | |
| 10 | type ErrorObject struct { |
| 11 | Code string `json:"code,required,nullable"` |
| 12 | Message string `json:"message,required"` |
| 13 | Param string `json:"param,required,nullable"` |
| 14 | Type string `json:"type,required"` |
| 15 | JSON errorObjectJSON `json:"-"` |
| 16 | } |
| 17 | |
| 18 | // errorObjectJSON contains the JSON metadata for the struct [ErrorObject] |
| 19 | type errorObjectJSON struct { |
| 20 | Code apijson.Field |
| 21 | Message apijson.Field |
| 22 | Param apijson.Field |
| 23 | Type apijson.Field |
| 24 | raw string |
| 25 | ExtraFields map[string]apijson.Field |
| 26 | } |
| 27 | |
| 28 | func (r *ErrorObject) UnmarshalJSON(data []byte) (err error) { |
| 29 | return apijson.UnmarshalRoot(data, r) |
| 30 | } |
| 31 | |
| 32 | func (r errorObjectJSON) RawJSON() string { |
| 33 | return r.raw |
| 34 | } |
| 35 | |
| 36 | type FunctionDefinition struct { |
| 37 | // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain |
| 38 | // underscores and dashes, with a maximum length of 64. |
| 39 | Name string `json:"name,required"` |
| 40 | // A description of what the function does, used by the model to choose when and |
| 41 | // how to call the function. |
| 42 | Description string `json:"description"` |
| 43 | // The parameters the functions accepts, described as a JSON Schema object. See the |
| 44 | // [guide](https://platform.openai.com/docs/guides/function-calling) for examples, |
| 45 | // and the |
| 46 | // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for |
| 47 | // documentation about the format. |
| 48 | // |
| 49 | // Omitting `parameters` defines a function with an empty parameter list. |
| 50 | Parameters FunctionParameters `json:"parameters"` |
| 51 | // Whether to enable strict schema adherence when generating the function call. If |
| 52 | // set to true, the model will follow the exact schema defined in the `parameters` |
| 53 | // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn |
| 54 | // more about Structured Outputs in the |
| 55 | // [function calling guide](docs/guides/function-calling). |
| 56 | Strict bool `json:"strict,nullable"` |
| 57 | JSON functionDefinitionJSON `json:"-"` |
| 58 | } |
| 59 | |
| 60 | // functionDefinitionJSON contains the JSON metadata for the struct |
| 61 | // [FunctionDefinition] |
| 62 | type functionDefinitionJSON struct { |
| 63 | Name apijson.Field |
| 64 | Description apijson.Field |
| 65 | Parameters apijson.Field |
| 66 | Strict apijson.Field |
| 67 | raw string |
| 68 | ExtraFields map[string]apijson.Field |
| 69 | } |
| 70 | |
| 71 | func (r *FunctionDefinition) UnmarshalJSON(data []byte) (err error) { |
| 72 | return apijson.UnmarshalRoot(data, r) |
| 73 | } |
| 74 | |
| 75 | func (r functionDefinitionJSON) RawJSON() string { |
| 76 | return r.raw |
| 77 | } |
| 78 | |
| 79 | type FunctionDefinitionParam struct { |
| 80 | // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain |
| 81 | // underscores and dashes, with a maximum length of 64. |
| 82 | Name param.Field[string] `json:"name,required"` |
| 83 | // A description of what the function does, used by the model to choose when and |
| 84 | // how to call the function. |
| 85 | Description param.Field[string] `json:"description"` |
| 86 | // The parameters the functions accepts, described as a JSON Schema object. See the |
| 87 | // [guide](https://platform.openai.com/docs/guides/function-calling) for examples, |
| 88 | // and the |
| 89 | // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for |
| 90 | // documentation about the format. |
| 91 | // |
| 92 | // Omitting `parameters` defines a function with an empty parameter list. |
| 93 | Parameters param.Field[FunctionParameters] `json:"parameters"` |
| 94 | // Whether to enable strict schema adherence when generating the function call. If |
| 95 | // set to true, the model will follow the exact schema defined in the `parameters` |
| 96 | // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn |
| 97 | // more about Structured Outputs in the |
| 98 | // [function calling guide](docs/guides/function-calling). |
| 99 | Strict param.Field[bool] `json:"strict"` |
| 100 | } |
| 101 | |
| 102 | func (r FunctionDefinitionParam) MarshalJSON() (data []byte, err error) { |
| 103 | return apijson.MarshalRoot(r) |
| 104 | } |
| 105 | |
| 106 | type FunctionParameters map[string]interface{} |
| 107 | |
| 108 | type ResponseFormatJSONObjectParam struct { |
| 109 | // The type of response format being defined: `json_object` |
| 110 | Type param.Field[ResponseFormatJSONObjectType] `json:"type,required"` |
| 111 | } |
| 112 | |
| 113 | func (r ResponseFormatJSONObjectParam) MarshalJSON() (data []byte, err error) { |
| 114 | return apijson.MarshalRoot(r) |
| 115 | } |
| 116 | |
| 117 | func (r ResponseFormatJSONObjectParam) ImplementsChatCompletionNewParamsResponseFormatUnion() {} |
| 118 | |
| 119 | // The type of response format being defined: `json_object` |
| 120 | type ResponseFormatJSONObjectType string |
| 121 | |
| 122 | const ( |
| 123 | ResponseFormatJSONObjectTypeJSONObject ResponseFormatJSONObjectType = "json_object" |
| 124 | ) |
| 125 | |
| 126 | func (r ResponseFormatJSONObjectType) IsKnown() bool { |
| 127 | switch r { |
| 128 | case ResponseFormatJSONObjectTypeJSONObject: |
| 129 | return true |
| 130 | } |
| 131 | return false |
| 132 | } |
| 133 | |
| 134 | type ResponseFormatJSONSchemaParam struct { |
| 135 | JSONSchema param.Field[ResponseFormatJSONSchemaJSONSchemaParam] `json:"json_schema,required"` |
| 136 | // The type of response format being defined: `json_schema` |
| 137 | Type param.Field[ResponseFormatJSONSchemaType] `json:"type,required"` |
| 138 | } |
| 139 | |
| 140 | func (r ResponseFormatJSONSchemaParam) MarshalJSON() (data []byte, err error) { |
| 141 | return apijson.MarshalRoot(r) |
| 142 | } |
| 143 | |
| 144 | func (r ResponseFormatJSONSchemaParam) ImplementsChatCompletionNewParamsResponseFormatUnion() {} |
| 145 | |
| 146 | type ResponseFormatJSONSchemaJSONSchemaParam struct { |
| 147 | // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores |
| 148 | // and dashes, with a maximum length of 64. |
| 149 | Name param.Field[string] `json:"name,required"` |
| 150 | // A description of what the response format is for, used by the model to determine |
| 151 | // how to respond in the format. |
| 152 | Description param.Field[string] `json:"description"` |
| 153 | // The schema for the response format, described as a JSON Schema object. |
| 154 | Schema param.Field[map[string]interface{}] `json:"schema"` |
| 155 | // Whether to enable strict schema adherence when generating the output. If set to |
| 156 | // true, the model will always follow the exact schema defined in the `schema` |
| 157 | // field. Only a subset of JSON Schema is supported when `strict` is `true`. To |
| 158 | // learn more, read the |
| 159 | // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). |
| 160 | Strict param.Field[bool] `json:"strict"` |
| 161 | } |
| 162 | |
| 163 | func (r ResponseFormatJSONSchemaJSONSchemaParam) MarshalJSON() (data []byte, err error) { |
| 164 | return apijson.MarshalRoot(r) |
| 165 | } |
| 166 | |
| 167 | // The type of response format being defined: `json_schema` |
| 168 | type ResponseFormatJSONSchemaType string |
| 169 | |
| 170 | const ( |
| 171 | ResponseFormatJSONSchemaTypeJSONSchema ResponseFormatJSONSchemaType = "json_schema" |
| 172 | ) |
| 173 | |
| 174 | func (r ResponseFormatJSONSchemaType) IsKnown() bool { |
| 175 | switch r { |
| 176 | case ResponseFormatJSONSchemaTypeJSONSchema: |
| 177 | return true |
| 178 | } |
| 179 | return false |
| 180 | } |
| 181 | |
| 182 | type ResponseFormatTextParam struct { |
| 183 | // The type of response format being defined: `text` |
| 184 | Type param.Field[ResponseFormatTextType] `json:"type,required"` |
| 185 | } |
| 186 | |
| 187 | func (r ResponseFormatTextParam) MarshalJSON() (data []byte, err error) { |
| 188 | return apijson.MarshalRoot(r) |
| 189 | } |
| 190 | |
| 191 | func (r ResponseFormatTextParam) ImplementsChatCompletionNewParamsResponseFormatUnion() {} |
| 192 | |
| 193 | // The type of response format being defined: `text` |
| 194 | type ResponseFormatTextType string |
| 195 | |
| 196 | const ( |
| 197 | ResponseFormatTextTypeText ResponseFormatTextType = "text" |
| 198 | ) |
| 199 | |
| 200 | func (r ResponseFormatTextType) IsKnown() bool { |
| 201 | switch r { |
| 202 | case ResponseFormatTextTypeText: |
| 203 | return true |
| 204 | } |
| 205 | return false |
| 206 | } |
| 207 | |