You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -239,6 +239,29 @@ for try await result in openAI.chatsStream(query: query) {
239
239
}
240
240
```
241
241
242
+
#### Provider-specific fields
243
+
244
+
When using third-party providers or OpenAI-compatible gateways that expect additional JSON fields, supply them through the optional `vendorParameters` argument that every chat method exposes. The SDK will merge these values at the top level of the payload without touching the officially supported fields.
245
+
246
+
For example, Volcengine's Doubao models expose a `thinking` object that controls deep-thinking behaviour:
247
+
248
+
```swift
249
+
let vendorParameters: [String: JSONValue] = [
250
+
"thinking": .object([
251
+
"type": .string("disabled") // "enabled" and "auto" are also available.
252
+
])
253
+
]
254
+
255
+
let result =tryawait openAI.chats(
256
+
query: query,
257
+
vendorParameters: vendorParameters
258
+
)
259
+
260
+
fortryawait chunk in openAI.chatsStream(query: query, vendorParameters: vendorParameters) {
261
+
// Handle streamed result with the same vendor-specific field applied.
Copy file name to clipboardExpand all lines: Sources/OpenAI/Public/Protocols/OpenAIProtocol.swift
+17-2Lines changed: 17 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -101,9 +101,10 @@ public protocol OpenAIProtocol: OpenAIModern {
101
101
102
102
- Parameters:
103
103
- query: A `ChatQuery` object containing the input parameters for the API request. This includes the lists of message objects for the conversation, the model to be used, and other settings.
104
+
- vendorParameters: Optional provider-specific fields that will be merged into the JSON payload.
104
105
- completion: A closure which receives the result when the API request finishes. The closure's parameter, `Result<ChatResult, Error>`, will contain either the `ChatResult` object with the model's response to the conversation, or an error if the request failed.
This function sends a chat query to the OpenAI API and retrieves chat stream conversation responses. The Chat API enables you to build chatbots or conversational applications using OpenAI's powerful natural language models, like GPT-3. The result is returned by chunks.
@@ -118,10 +119,11 @@ public protocol OpenAIProtocol: OpenAIModern {
118
119
119
120
- Parameters:
120
121
- query: A `ChatQuery` object containing the input parameters for the API request. This includes the lists of message objects for the conversation, the model to be used, and other settings.
122
+
- vendorParameters: Optional provider-specific fields that will be merged into the JSON payload.
121
123
- onResult: A closure which receives the result when the API request finishes. The closure's parameter, `Result<ChatStreamResult, Error>`, will contain either the `ChatStreamResult` object with the model's response to the conversation, or an error if the request failed.
122
124
- completion: A closure that is being called when all chunks are delivered or uncrecoverable error occured
This function sends a model query to the OpenAI API and retrieves a model instance, providing owner information. The Models API in this usage enables you to gather detailed information on the model in question, like GPT-3.
@@ -406,3 +408,16 @@ public protocol OpenAIProtocol: OpenAIModern {
0 commit comments