Skip to content

Commit e041784

Browse files
committed
add modules
1 parent c2724c2 commit e041784

File tree

7 files changed

+265
-1
lines changed

7 files changed

+265
-1
lines changed

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,65 @@ DerivedData/
66
.swiftpm/configuration/registries.json
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
9+
# Xcode
10+
#
11+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
12+
13+
## User settings
14+
xcuserdata/
15+
16+
## Obj-C/Swift specific
17+
*.hmap
18+
19+
## App packaging
20+
*.ipa
21+
*.dSYM.zip
22+
*.dSYM
23+
24+
## Playgrounds
25+
timeline.xctimeline
26+
playground.xcworkspace
27+
28+
# Swift Package Manager
29+
#
30+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
31+
# Packages/
32+
# Package.pins
33+
# Package.resolved
34+
# *.xcodeproj
35+
#
36+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
37+
# hence it is not needed unless you have added a package configuration file to your project
38+
# .swiftpm
39+
40+
.build/
41+
42+
# CocoaPods
43+
#
44+
# We recommend against adding the Pods directory to your .gitignore. However
45+
# you should judge for yourself, the pros and cons are mentioned at:
46+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
47+
#
48+
# Pods/
49+
#
50+
# Add this line if you want to avoid checking in source code from the Xcode workspace
51+
# *.xcworkspace
52+
53+
# Carthage
54+
#
55+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
56+
# Carthage/Checkouts
57+
58+
Carthage/Build/
59+
60+
# fastlane
61+
#
62+
# It is recommended to not store the screenshots in the git repo.
63+
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
64+
# For more information about the recommended setup visit:
65+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
66+
67+
fastlane/report.xml
68+
fastlane/Preview.html
69+
fastlane/screenshots/**/*.png
70+
fastlane/test_output

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Fumito Ito
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.resolved

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

Package.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,30 @@ import PackageDescription
55

66
let package = Package(
77
name: "FunctionCalling-MacPaw-OpenAI",
8+
platforms: [
9+
.macOS(.v13),
10+
.iOS(.v17)
11+
],
812
products: [
913
// Products define the executables and libraries a package produces, making them visible to other packages.
1014
.library(
1115
name: "FunctionCalling-MacPaw-OpenAI",
1216
targets: ["FunctionCalling-MacPaw-OpenAI"]),
1317
],
18+
dependencies: [
19+
.package(url: "https://github.com/FunctionCalling/FunctionCalling", from: "0.4.0"),
20+
.package(url: "https://github.com/MacPaw/OpenAI", from: "0.3.0")
21+
],
1422
targets: [
1523
// Targets are the basic building blocks of a package, defining a module or a test suite.
1624
// Targets can depend on other targets in this package and products from dependencies.
1725
.target(
18-
name: "FunctionCalling-MacPaw-OpenAI"),
26+
name: "FunctionCalling-MacPaw-OpenAI",
27+
dependencies: [
28+
.product(name: "OpenAI", package: "OpenAI"),
29+
.product(name: "FunctionCalling", package: "FunctionCalling"),
30+
]
31+
),
1932
.testTarget(
2033
name: "FunctionCalling-MacPaw-OpenAITests",
2134
dependencies: ["FunctionCalling-MacPaw-OpenAI"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# FunctionCalling-MacPaw-OpenAI
2+
Easy to use your Swift native functions for function calling with [MacPaw/OpenAI](https://github.com/MacPaw/OpenAI).
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//
2+
// ChatQuery+Extension.swift
3+
// FunctionCalling-MacPaw-OpenAI
4+
//
5+
// Created by 伊藤史 on 2024/09/27.
6+
//
7+
8+
import FunctionCalling
9+
import OpenAI
10+
11+
extension ChatQuery.ChatCompletionToolParam {
12+
init(tool: Tool) {
13+
self.init(function: .init(tool: tool))
14+
}
15+
}
16+
17+
extension ChatQuery.ChatCompletionToolParam.FunctionDefinition {
18+
init(tool: Tool) {
19+
self.init(
20+
name: tool.name,
21+
description: tool.description,
22+
parameters: FunctionParameters(inputSchema: tool.inputSchema)
23+
)
24+
}
25+
}
26+
27+
extension ChatQuery.ChatCompletionToolParam.FunctionDefinition.FunctionParameters {
28+
init(inputSchema: InputSchema) {
29+
self.init(
30+
type: JSONType(dataType: inputSchema.type),
31+
properties: inputSchema.properties?.mapValues { Property(inputSchema: $0) },
32+
required: inputSchema.requiredProperties,
33+
enum: inputSchema.enumValues
34+
)
35+
}
36+
}
37+
38+
extension ChatQuery.ChatCompletionToolParam.FunctionDefinition.FunctionParameters.Property.Items {
39+
init?(inputSchema: InputSchema?) {
40+
guard let inputSchema else {
41+
return nil
42+
}
43+
44+
self.init(
45+
type: JSONType(dataType: inputSchema.type),
46+
properties: inputSchema.properties?.mapValues {
47+
ChatQuery.ChatCompletionToolParam.FunctionDefinition.FunctionParameters.Property(inputSchema: $0)
48+
},
49+
enum: inputSchema.enumValues
50+
)
51+
}
52+
}
53+
54+
extension ChatQuery.ChatCompletionToolParam.FunctionDefinition.FunctionParameters.Property {
55+
init(inputSchema: InputSchema) {
56+
self.init(
57+
type: JSONType(dataType: inputSchema.type),
58+
description: inputSchema.description,
59+
format: inputSchema.format,
60+
items: Items(inputSchema: inputSchema.items),
61+
required: inputSchema.requiredProperties,
62+
enum: inputSchema.enumValues
63+
)
64+
}
65+
}
66+
67+
extension ChatQuery.ChatCompletionToolParam.FunctionDefinition.FunctionParameters.JSONType {
68+
init(dataType: InputSchema.DataType) {
69+
switch dataType {
70+
case .string:
71+
self = .string
72+
case .number:
73+
self = .number
74+
case .integer:
75+
self = .integer
76+
case .boolean:
77+
self = .boolean
78+
case .array:
79+
self = .array
80+
case .object:
81+
self = .object
82+
}
83+
}
84+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
// The Swift Programming Language
22
// https://docs.swift.org/swift-book
3+
4+
import FunctionCalling
5+
import OpenAI
6+
7+
extension ToolContainer {
8+
public var macPawOpenAITools: [ChatQuery.ChatCompletionToolParam] {
9+
guard let allTools else {
10+
return []
11+
}
12+
13+
return allTools.compactMap { ChatQuery.ChatCompletionToolParam(tool: $0) }
14+
}
15+
}

0 commit comments

Comments
 (0)