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
When calling OpenAI-compatible gateways that expect additional JSON fields, supply them through the optional `vendorParameters` argument on chat APIs. The SDK merges these values into the top-level payload without disturbing the documented schema.
368
+
369
+
For example, Volcengine's Deepseek models expose a `thinking` object that controls deep-thinking behaviour:
370
+
371
+
```swift
372
+
let vendorParameters: [String: JSONValue] = [
373
+
"thinking": .object([
374
+
"type": .string("disabled") // "enabled" and "auto" are also available.
375
+
])
376
+
]
377
+
378
+
let result =tryawait openAI.chats(
379
+
query: query,
380
+
vendorParameters: vendorParameters
381
+
)
382
+
383
+
fortryawait chunk in openAI.chatsStream(query: query, vendorParameters: vendorParameters) {
384
+
// Handle streamed result with the same vendor-specific field applied.
385
+
}
386
+
```
387
+
365
388
## Function calling
366
389
367
390
See [OpenAI Platform Guide: Function calling](https://platform.openai.com/docs/guides/function-calling?api-mode=responses) for more details.
@@ -371,7 +394,6 @@ See [OpenAI Platform Guide: Function calling](https://platform.openai.com/docs/g
371
394
<summary>Chat Completions API Examples</summary>
372
395
373
396
### Function calling with get_weather function
374
-
375
397
```swift
376
398
let openAI =OpenAI(apiToken: "...")
377
399
// Declare functions which model might decide to call.
Copy file name to clipboardExpand all lines: Sources/OpenAI/Public/Protocols/OpenAIProtocol.swift
+21-10Lines changed: 21 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -97,9 +97,10 @@ public protocol OpenAIProtocol: OpenAIModern {
97
97
98
98
- Parameters:
99
99
- 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.
100
+
- vendorParameters: Optional provider-specific fields that will be merged into the JSON payload.
100
101
- 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.
@@ -115,15 +116,12 @@ public protocol OpenAIProtocol: OpenAIModern {
115
116
```
116
117
117
118
- Parameters:
118
-
- 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.
119
-
- 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.
120
-
- completion: A closure that is being called when all chunks are delivered or uncrecoverable error occured.
121
-
122
-
- Returns: An object that references the streaming session.
123
-
124
-
- Note: This method creates and configures separate session object specifically for streaming. In order for it to work properly and don't leak memory you should hold a reference to the returned value, and when you're done - call cancel() on it.
- 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.
120
+
- vendorParameters: Optional provider-specific fields that will be merged into the JSON payload.
121
+
- 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
+
- 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.
@@ -451,3 +449,16 @@ public protocol OpenAIProtocol: OpenAIModern {
0 commit comments