Skip to content

Commit b40ed0b

Browse files
🎷 [UPDATE] Tool choice added.
1 parent 7741f71 commit b40ed0b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Sources/ACMOpenAI/Requests/Chat/ACMOAIChatRequest.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public extension ACMOAIChatRequest {
3838
public var user: String?
3939

4040
/// Init function for creating request
41-
public init(model: String, messages: [ACMChatMessageModel], tools: [ACMToolsModel]? = nil, temperature: Double? = nil, top_p: Double? = nil, n: Int? = nil, stream: Bool? = nil, stop: [String]? = nil, max_tokens: Int? = nil, presence_penalty: Double? = nil, frequency_penalty: Double? = nil, logit_bias: [String: Int]? = nil, user: String? = nil) {
41+
public init(model: String, messages: [ACMChatMessageModel], tools: [ACMToolsModel]? = nil, tool_choice: ACMToolChoiceModel? = nil, temperature: Double? = nil, top_p: Double? = nil, n: Int? = nil, stream: Bool? = nil, stop: [String]? = nil, max_tokens: Int? = nil, presence_penalty: Double? = nil, frequency_penalty: Double? = nil, logit_bias: [String: Int]? = nil, user: String? = nil) {
4242
self.model = model
4343
self.messages = messages
4444
self.temperature = temperature
@@ -52,6 +52,7 @@ public extension ACMOAIChatRequest {
5252
self.logit_bias = logit_bias
5353
self.user = user
5454
self.tools = tools
55+
self.tool_choice = tool_choice
5556
}
5657
}
5758
}

Sources/ACMOpenAI/Requests/Chat/ACMToolsModel.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ public struct ACMToolsModel: Codable {
2020
public struct ACMToolsFunctionModel: Codable {
2121
public let description: String?
2222
public let name: String
23-
public let params: String?
23+
public let parameters: String?
2424

2525
public init(description: String? = nil, name: String, params: [String: Any]? = nil) {
2626
self.description = description
2727
self.name = name
28-
self.params = String(describing: params)
28+
if let params {
29+
self.parameters = String(describing: params)
30+
} else {
31+
self.parameters = nil
32+
}
2933
}
3034
}
3135

@@ -45,8 +49,17 @@ public struct ACMToolChoiceModel: Codable {
4549
public struct ACMToolChoiceObjectModel: Codable {
4650
public var type: String
4751
public var function: ACMToolChoiceObjectFunctionModel
52+
53+
public init(type: String, function: ACMToolChoiceObjectFunctionModel) {
54+
self.type = type
55+
self.function = function
56+
}
4857
}
4958

5059
public struct ACMToolChoiceObjectFunctionModel: Codable {
5160
public var name: String
61+
62+
public init(name: String) {
63+
self.name = name
64+
}
5265
}

0 commit comments

Comments
 (0)