Skip to content

Commit 6acf519

Browse files
authored
Consistent style for OpenAI section of SDK (#114)
1 parent ff0eedf commit 6acf519

19 files changed

+394
-332
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -4584,7 +4584,11 @@ Contributions are welcome! This library uses the MIT license.
45844584
45854585
- In codable representations, fields that are required by the API should be above fields that
45864586
are optional. Within the two groups (required and optional) all fields should be
4587-
alphabetically ordered.
4587+
alphabetically ordered. Separate the two groups with a mark to aid users of ctrl-6:
4588+
4589+
```swift
4590+
// MARK: Optional properties
4591+
```
45884592
45894593
- Decodables should all have optional properties. Why? We don't want to fail decoding in live
45904594
apps if the provider changes something out from under us (which can happen purposefully due
@@ -4608,6 +4612,7 @@ Contributions are welcome! This library uses the MIT license.
46084612
// ... other fields ...
46094613
}
46104614
4615+
// MARK: -
46114616
extension ProviderResponseBody {
46124617
public enum Status: String, Decodable {
46134618
case succeeded
@@ -4636,6 +4641,9 @@ Contributions are welcome! This library uses the MIT license.
46364641
balloon line count with implementation detail that a user of the top level type has no
46374642
interest in.
46384643
4644+
You may also wonder why we include the `// MARK: -` line. This is makes parsing the ctrl-6
4645+
dropdown easier on the eyes.
4646+
46394647
- If you are implementing an API contract that could reuse a provider's nested structure, and
46404648
it's reasonable to suppose that the two objects will change together, then pull the nested
46414649
struct into its own file and give it a longer prefix. The example above would become:

Sources/AIProxy/AIProxy.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import UIKit
88
public struct AIProxy {
99

1010
/// The current sdk version
11-
public static let sdkVersion = "0.75.0"
11+
public static let sdkVersion = "0.75.2"
1212

1313
/// - Parameters:
1414
/// - partialKey: Your partial key is displayed in the AIProxy dashboard when you submit your provider's key.

Sources/AIProxy/OpenAI/OpenAIAudioCodables.swift

-188
This file was deleted.

Sources/AIProxy/OpenAI/OpenAIChatCompletionRequestBody.swift

+13-19
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import Foundation
1010
/// Chat completion request body. Docstrings are taken from this reference:
1111
/// https://platform.openai.com/docs/api-reference/chat/create
1212
public struct OpenAIChatCompletionRequestBody: Encodable {
13-
// Required
14-
15-
// The required section should be in alphabetical order. This section is an exception,
16-
// because we have existing callers that I don't want to break.
1713

1814
/// ID of the model to use. See the model endpoint compatibility table for details on which models work
1915
/// with the Chat API:
@@ -23,7 +19,7 @@ public struct OpenAIChatCompletionRequestBody: Encodable {
2319
/// A list of messages comprising the conversation so far
2420
public let messages: [Message]
2521

26-
// Optional
22+
// MARK: Optional properties
2723

2824
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
2925
/// See more information here: https://platform.openai.com/docs/guides/text-generation
@@ -115,11 +111,10 @@ public struct OpenAIChatCompletionRequestBody: Encodable {
115111
public let user: String?
116112

117113
private enum CodingKeys: String, CodingKey {
118-
// required
119-
case messages
120114
case model
115+
case messages
121116

122-
// optional
117+
// Optional properties
123118
case frequencyPenalty = "frequency_penalty"
124119
case logitBias = "logit_bias"
125120
case logprobs
@@ -194,7 +189,7 @@ public struct OpenAIChatCompletionRequestBody: Encodable {
194189
}
195190
}
196191

197-
// MARK: - RequestBody.Message
192+
// MARK: -
198193
extension OpenAIChatCompletionRequestBody {
199194
/// https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages
200195
public enum Message: Encodable {
@@ -300,7 +295,7 @@ extension OpenAIChatCompletionRequestBody {
300295
}
301296
}
302297

303-
// MARK: - RequestBody.Message.MessageContent
298+
// MARK: -
304299
extension OpenAIChatCompletionRequestBody.Message {
305300
public enum MessageContent<
306301
SingleType: Encodable,
@@ -318,7 +313,7 @@ extension OpenAIChatCompletionRequestBody.Message {
318313
}
319314
}
320315

321-
// MARK: - RequestBody.Message.ContentPart
316+
// MARK: -
322317
extension OpenAIChatCompletionRequestBody.Message {
323318
public enum ContentPart: Encodable {
324319
/// The text content.
@@ -368,7 +363,7 @@ extension OpenAIChatCompletionRequestBody.Message {
368363
}
369364
}
370365

371-
// MARK: - RequestBody.Message.UserContent.Part.ImageDetail
366+
// MARK: -
372367
extension OpenAIChatCompletionRequestBody.Message.ContentPart {
373368
public enum ImageDetail: String, Encodable {
374369
case auto
@@ -377,7 +372,7 @@ extension OpenAIChatCompletionRequestBody.Message.ContentPart {
377372
}
378373
}
379374

380-
// MARK: - RequestBody.Message.ToolCall
375+
// MARK: -
381376
extension OpenAIChatCompletionRequestBody.Message {
382377
public struct ToolCall: Encodable {
383378
/// The ID of the tool call.
@@ -399,7 +394,7 @@ extension OpenAIChatCompletionRequestBody.Message {
399394
}
400395
}
401396

402-
// MARK: - RequestBody.Message.ToolCall.Function
397+
// MARK: -
403398
extension OpenAIChatCompletionRequestBody.Message.ToolCall {
404399
/// Represents the 'Function' object at `messages > assistant message > tool_calls > function`
405400
/// https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages
@@ -421,8 +416,7 @@ extension OpenAIChatCompletionRequestBody.Message.ToolCall {
421416
}
422417
}
423418

424-
425-
// MARK: - RequestBody.ResponseFormat
419+
// MARK: -
426420
extension OpenAIChatCompletionRequestBody {
427421
/// An object specifying the format that the model must output. Compatible with GPT-4o, GPT-4o mini, GPT-4
428422
/// Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106.
@@ -502,7 +496,7 @@ extension OpenAIChatCompletionRequestBody {
502496
}
503497
}
504498

505-
// MARK: - RequestBody.StreamOptions
499+
// MARK: -
506500
extension OpenAIChatCompletionRequestBody {
507501
public struct StreamOptions: Encodable {
508502
/// If set, an additional chunk will be streamed before the data: [DONE] message.
@@ -517,7 +511,7 @@ extension OpenAIChatCompletionRequestBody {
517511
}
518512
}
519513

520-
// MARK: - RequestBody.Tool
514+
// MARK: -
521515
extension OpenAIChatCompletionRequestBody {
522516
public enum Tool: Encodable {
523517

@@ -582,7 +576,7 @@ extension OpenAIChatCompletionRequestBody {
582576
}
583577
}
584578

585-
// MARK: - RequestBody.ToolChoice
579+
// MARK: -
586580
extension OpenAIChatCompletionRequestBody {
587581
/// Controls which (if any) tool is called by the model.
588582
public enum ToolChoice: Encodable {

0 commit comments

Comments
 (0)