Skip to content

Commit 3282029

Browse files
Merge pull request #46 from AppcentMobile/feature/function-calls
🎷 [FEATURE] Function calls added.
2 parents d945381 + 3847cc1 commit 3282029

File tree

157 files changed

+7390
-17582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+7390
-17582
lines changed

ACMOpenAI.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "ACMOpenAI"
3-
spec.version = "1.0.2"
3+
spec.version = "1.0.8"
44
spec.summary = "ACMOpenAI iOS Library"
55
spec.description = <<-DESC
66
ACMOpenAI is a library that help developers to use Open AI API easily.
@@ -14,5 +14,5 @@ Pod::Spec.new do |spec|
1414
spec.swift_version = '5.0'
1515
spec.source = { :git => "https://github.com/AppcentMobile/ACMOpenAI-iOS.git", :tag => "#{spec.version}" }
1616
spec.source_files = "Sources/**/*.{h,m,swift}"
17-
spec.dependency 'ACMNetworking', '~> 1.1.3'
17+
spec.dependency 'ACMNetworking', '~> 1.2.3'
1818
end

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let package = Package(
1515
),
1616
],
1717
dependencies: [
18-
.package(url: "https://github.com/AppcentMobile/ACMNetworking.git", exact: "1.2.0"),
18+
.package(url: "https://github.com/AppcentMobile/ACMNetworking.git", exact: "1.2.3"),
1919
],
2020
targets: [
2121
.target(

Sources/ACMOpenAI/Manager/Chat/ACMOAIChatManager.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public extension ACMOAIChatManager {
1515
/// - request: `ACMOAIChatRequest` Model of possible requests
1616
///
1717
func create(request: ACMOAIChatRequest.Create, onSuccess: ChatCallback.Create = nil, onPartial: ChatCallback.Create = nil, onError: ACMGenericCallbacks.ErrorCallback) {
18-
1918
guard var to = endpoint?.set(path: ChatRoute.create)
2019
.set(method: .post)
2120
.add(param: ACMBodyModel(key: "model", value: request.model))
22-
.add(param: ACMBodyModel(key: "messages", value: request.messages)) else {
21+
.add(param: ACMBodyModel(key: "messages", value: request.messages))
22+
else {
2323
return
2424
}
2525

@@ -63,6 +63,18 @@ public extension ACMOAIChatManager {
6363
to = to.add(param: ACMBodyModel(key: "user", value: user))
6464
}
6565

66+
if let tools = request.tools {
67+
to = to.add(param: ACMBodyModel(key: "tools", value: tools))
68+
}
69+
70+
if let tool_choice = request.tool_choice {
71+
if let strChoice = tool_choice.strChoice {
72+
to = to.add(param: ACMBodyModel(key: "tool_choice", value: strChoice))
73+
} else if let objChoice = tool_choice.objChoice {
74+
to = to.add(param: ACMBodyModel(key: "tool_choice", value: ACMToolChoiceObjectModel(type: objChoice.type, function: objChoice.function)))
75+
}
76+
}
77+
6678
let buildEndpoint = to.build()
6779

6880
if request.stream == true {

Sources/ACMOpenAI/Manager/Moderations/ACMOAIModerationsManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public extension ACMOAIModerationsManager {
1616
func create(request: ACMOAIModerationsRequest.Create, onSuccess: ModerationsCallback.Create, onError: ACMGenericCallbacks.ErrorCallback) {
1717
guard var to = endpoint?.set(path: ModerationsRoute.create)
1818
.set(method: .post)
19-
.add(param: ACMBodyModel(key: "input", value: request.input)) else {
19+
.add(param: ACMBodyModel(key: "input", value: request.input))
20+
else {
2021
return
2122
}
2223

Sources/ACMOpenAI/Requests/Chat/ACMOAIChatRequest.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public extension ACMOAIChatRequest {
1212
public var model: String
1313
/// messages: required*
1414
public var messages: [ACMChatMessageModel]
15+
/// tools
16+
public var tools: [ACMToolsModel]?
17+
/// tool choice
18+
public var tool_choice: ACMToolChoiceModel?
1519
/// temperature: optional
1620
public var temperature: Double?
1721
/// top_p: optional
@@ -34,7 +38,7 @@ public extension ACMOAIChatRequest {
3438
public var user: String?
3539

3640
/// Init function for creating request
37-
public init(model: String, messages: [ACMChatMessageModel], 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) {
3842
self.model = model
3943
self.messages = messages
4044
self.temperature = temperature
@@ -47,6 +51,8 @@ public extension ACMOAIChatRequest {
4751
self.frequency_penalty = frequency_penalty
4852
self.logit_bias = logit_bias
4953
self.user = user
54+
self.tools = tools
55+
self.tool_choice = tool_choice
5056
}
5157
}
5258
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// ACMToolsModel.swift
3+
//
4+
//
5+
// Created by burak on 20.02.2024.
6+
//
7+
8+
import Foundation
9+
10+
public struct ACMToolsModel: Codable {
11+
public let type: String
12+
public let function: ACMToolsFunctionModel
13+
14+
public init(type: String, function: ACMToolsFunctionModel) {
15+
self.type = type
16+
self.function = function
17+
}
18+
}
19+
20+
public struct ACMToolsFunctionModel: Codable {
21+
public let description: String?
22+
public let name: String
23+
public let parameters: String?
24+
25+
public init(description: String? = nil, name: String, params: [String: Any]? = nil) {
26+
self.description = description
27+
self.name = name
28+
if let params, let data = try? JSONSerialization.data(withJSONObject: params, options: []) {
29+
parameters = String(data: data, encoding: .utf8)
30+
} else {
31+
parameters = nil
32+
}
33+
}
34+
}
35+
36+
public struct ACMToolChoiceModel: Codable {
37+
public var strChoice: String?
38+
public var objChoice: ACMToolChoiceObjectModel?
39+
40+
public init(strChoice: String? = nil) {
41+
self.strChoice = strChoice
42+
}
43+
44+
public init(objChoice: ACMToolChoiceObjectModel? = nil) {
45+
self.objChoice = objChoice
46+
}
47+
}
48+
49+
public struct ACMToolChoiceObjectModel: Codable {
50+
public var type: String
51+
public var function: ACMToolChoiceObjectFunctionModel
52+
53+
public init(type: String, function: ACMToolChoiceObjectFunctionModel) {
54+
self.type = type
55+
self.function = function
56+
}
57+
}
58+
59+
public struct ACMToolChoiceObjectFunctionModel: Codable {
60+
public var name: String
61+
62+
public init(name: String) {
63+
self.name = name
64+
}
65+
}

0 commit comments

Comments
 (0)