Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/Upstream/main'
Browse files Browse the repository at this point in the history
Conflicts:
	Config.xcconfig
  • Loading branch information
NoahKamara committed Sep 28, 2023
2 parents 2656d95 + 1113a52 commit deba9ba
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 247 deletions.
37 changes: 15 additions & 22 deletions Actions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@
E337A3E627E8BA6B0073E865 /* FuzzyFind in Frameworks */ = {isa = PBXBuildFile; productRef = E337A3E527E8BA6B0073E865 /* FuzzyFind */; };
E33D080D2A11623200FBCAD7 /* SimpleKeychain in Frameworks */ = {isa = PBXBuildFile; productRef = E33D080C2A11623200FBCAD7 /* SimpleKeychain */; };
E33D080F2A11629500FBCAD7 /* AskChatGPT.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33D080E2A11629500FBCAD7 /* AskChatGPT.swift */; };
E33D08122A1163FD00FBCAD7 /* OpenAISwift in Frameworks */ = {isa = PBXBuildFile; productRef = E33D08112A1163FD00FBCAD7 /* OpenAISwift */; };
E33D08142A11679300FBCAD7 /* SettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33D08132A11679300FBCAD7 /* SettingsScreen.swift */; };
E33D4BA62744238300CC7A8A /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33D4BA42744238300CC7A8A /* AppState.swift */; };
E343F9B829713AFF00AD82F4 /* GetMapImageOfLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = E317489E2913BEAB00F6319E /* GetMapImageOfLocation.swift */; };
E34839A12A885DD90040DF6E /* InvertImages.swift in Sources */ = {isa = PBXBuildFile; fileRef = E34839A02A885DD90040DF6E /* InvertImages.swift */; };
E34839A32A88DF7D0040DF6E /* GetBooleanFromInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = E34839A22A88DF7D0040DF6E /* GetBooleanFromInput.swift */; };
E34839A62A88E6A70040DF6E /* IsDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = E34839A52A88E6A70040DF6E /* IsDay.swift */; };
E34AB51628F58B500082AE78 /* Authenticate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E34AB51528F58B500082AE78 /* Authenticate.swift */; };
E350B24F2AC2AF7D00BFC34D /* IsCellularLowDataModeOn.swift in Sources */ = {isa = PBXBuildFile; fileRef = E350B24E2AC2AF7D00BFC34D /* IsCellularLowDataModeOn.swift */; };
E350B2522AC3005800BFC34D /* IsDeviceLocked.swift in Sources */ = {isa = PBXBuildFile; fileRef = E350B2512AC3005800BFC34D /* IsDeviceLocked.swift */; };
E351083128FD14A2007C85AE /* HexEncode.swift in Sources */ = {isa = PBXBuildFile; fileRef = E351083028FD14A2007C85AE /* HexEncode.swift */; };
E351083628FD79D8007C85AE /* OverwriteFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = E351083528FD79D8007C85AE /* OverwriteFile.swift */; };
E351083928FD8089007C85AE /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = E351083828FD8089007C85AE /* Sentry */; };
Expand Down Expand Up @@ -212,6 +213,8 @@
E34839A52A88E6A70040DF6E /* IsDay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsDay.swift; sourceTree = "<group>"; };
E34AB51528F58B500082AE78 /* Authenticate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authenticate.swift; sourceTree = "<group>"; };
E34AB51728F5AA170082AE78 /* ConvertCoordinatesToLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertCoordinatesToLocation.swift; sourceTree = "<group>"; };
E350B24E2AC2AF7D00BFC34D /* IsCellularLowDataModeOn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsCellularLowDataModeOn.swift; sourceTree = "<group>"; };
E350B2512AC3005800BFC34D /* IsDeviceLocked.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsDeviceLocked.swift; sourceTree = "<group>"; };
E351082E28FD099B007C85AE /* IsCellularDataOn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsCellularDataOn.swift; sourceTree = "<group>"; };
E351083028FD14A2007C85AE /* HexEncode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexEncode.swift; sourceTree = "<group>"; };
E351083528FD79D8007C85AE /* OverwriteFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverwriteFile.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -335,7 +338,6 @@
buildActionMask = 2147483647;
files = (
E33D080D2A11623200FBCAD7 /* SimpleKeychain in Frameworks */,
E33D08122A1163FD00FBCAD7 /* OpenAISwift in Frameworks */,
E337A3E627E8BA6B0073E865 /* FuzzyFind in Frameworks */,
E317495F2916A4A300F6319E /* SoulverCore in Frameworks */,
E351083928FD8089007C85AE /* Sentry in Frameworks */,
Expand Down Expand Up @@ -370,6 +372,7 @@
E3DB884F28E6EE7B00FEE8D6 /* HideShortcutsApp.swift */,
E34839A02A885DD90040DF6E /* InvertImages.swift */,
E3C33CA928D3A81700386C59 /* IsDarkMode.swift */,
E350B2512AC3005800BFC34D /* IsDeviceLocked.swift */,
E3CB448A28D71A180031D55F /* IsScreenLocked.swift */,
E3CB44A128D794DA0031D55F /* MergeDictionaries.swift */,
E351083528FD79D8007C85AE /* OverwriteFile.swift */,
Expand Down Expand Up @@ -458,6 +461,7 @@
E3C33CA528D3A52300386C59 /* IsAudioPlaying.swift */,
E3C33CA728D3A6CB00386C59 /* IsBluetoothOn.swift */,
E351082E28FD099B007C85AE /* IsCellularDataOn.swift */,
E350B24E2AC2AF7D00BFC34D /* IsCellularLowDataModeOn.swift */,
E3C33CAF28D3B3EF00386C59 /* IsConnectedToVPN.swift */,
E34839A52A88E6A70040DF6E /* IsDay.swift */,
E3CB448628D717CA0031D55F /* IsDeviceOrientation.swift */,
Expand Down Expand Up @@ -517,10 +521,10 @@
E324C9F0271E972200E7CA9B /* MainScreen.swift */,
E33D08132A11679300FBCAD7 /* SettingsScreen.swift */,
E3BFF7B327428F5200B830DE /* WelcomeScreen.swift */,
E3BFF7B62742A79100B830DE /* AppIcon.swift */,
E3BFF7B02742616400B830DE /* WriteTextScreen.swift */,
E337A3DF27E850EC0073E865 /* ChooseFromListScreen.swift */,
E352420B28F6F6AD00A957A7 /* AskForTextScreen.swift */,
E3BFF7B62742A79100B830DE /* AppIcon.swift */,
E3FC71DC271EBE5B00C9D255 /* Utilities.swift */,
E30FD0D527908D1A00C01D80 /* Actions */,
E324C9F1271E972300E7CA9B /* Assets.xcassets */,
Expand Down Expand Up @@ -585,7 +589,6 @@
E351083828FD8089007C85AE /* Sentry */,
E317495E2916A4A300F6319E /* SoulverCore */,
E33D080C2A11623200FBCAD7 /* SimpleKeychain */,
E33D08112A1163FD00FBCAD7 /* OpenAISwift */,
);
productName = "Actions (iOS)";
productReference = E324C9F6271E972300E7CA9B /* Actions.app */;
Expand Down Expand Up @@ -624,7 +627,6 @@
E32B4F3227FD77700057F08D /* XCRemoteSwiftPackageReference "ExceptionCatcher" */,
E317495D2916A4A300F6319E /* XCRemoteSwiftPackageReference "SoulverCore" */,
E33D080B2A11623200FBCAD7 /* XCRemoteSwiftPackageReference "SimpleKeychain" */,
E33D08102A1163FD00FBCAD7 /* XCRemoteSwiftPackageReference "OpenAISwift" */,
);
productRefGroup = E324C9F7271E972300E7CA9B /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -685,6 +687,7 @@
E34839A62A88E6A70040DF6E /* IsDay.swift in Sources */,
E31749432916A20C00F6319E /* IsAudioPlaying.swift in Sources */,
E31749372916A20C00F6319E /* FormatPersonName.swift in Sources */,
E350B24F2AC2AF7D00BFC34D /* IsCellularLowDataModeOn.swift in Sources */,
E31749182916A20C00F6319E /* IsDeviceOrientation.swift in Sources */,
E31749552916A20C00F6319E /* CombineLists.swift in Sources */,
E34839A32A88DF7D0040DF6E /* GetBooleanFromInput.swift in Sources */,
Expand Down Expand Up @@ -798,6 +801,7 @@
E3DB886C28E7549800FEE8D6 /* Constants.swift in Sources */,
E3DB884D28E6E3AD00FEE8D6 /* HapticFeedback.swift in Sources */,
E3CB448B28D71A180031D55F /* IsScreenLocked.swift in Sources */,
E350B2522AC3005800BFC34D /* IsDeviceLocked.swift in Sources */,
E3DB885428E7057100FEE8D6 /* WriteText.swift in Sources */,
E3CC6D6229A7E293002D8C67 /* GlobalVariable.swift in Sources */,
E324CA01271E972300E7CA9B /* MainScreen.swift in Sources */,
Expand Down Expand Up @@ -963,8 +967,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MACOSX_DEPLOYMENT_TARGET = 13.3;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1024,8 +1028,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MACOSX_DEPLOYMENT_TARGET = 13.3;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -1057,6 +1061,7 @@
INFOPLIST_KEY_NSCameraUsageDescription = "Required to use the “Scan Documents” action.";
INFOPLIST_KEY_NSContactsUsageDescription = "Required to get the user's name in the “Get User Details” action.";
INFOPLIST_KEY_NSFaceIDUsageDescription = "Required to use the “Authenticate” action.";
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © Sindre Sorhus";
INFOPLIST_KEY_NSSpeechRecognitionUsageDescription = "Required to use the “Transcribe Audio” action.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand Down Expand Up @@ -1104,6 +1109,7 @@
INFOPLIST_KEY_NSCameraUsageDescription = "Required to use the “Scan Documents” action.";
INFOPLIST_KEY_NSContactsUsageDescription = "Required to get the user's name in the “Get User Details” action.";
INFOPLIST_KEY_NSFaceIDUsageDescription = "Required to use the “Authenticate” action.";
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © Sindre Sorhus";
INFOPLIST_KEY_NSSpeechRecognitionUsageDescription = "Required to use the “Transcribe Audio” action.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand Down Expand Up @@ -1202,14 +1208,6 @@
minimumVersion = 1.0.0;
};
};
E33D08102A1163FD00FBCAD7 /* XCRemoteSwiftPackageReference "OpenAISwift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/adamrushy/OpenAISwift";
requirement = {
kind = revision;
revision = 73dbe257e6cc612294f771f2dc295dcf1540af33;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -1238,11 +1236,6 @@
package = E33D080B2A11623200FBCAD7 /* XCRemoteSwiftPackageReference "SimpleKeychain" */;
productName = SimpleKeychain;
};
E33D08112A1163FD00FBCAD7 /* OpenAISwift */ = {
isa = XCSwiftPackageProductDependency;
package = E33D08102A1163FD00FBCAD7 /* XCRemoteSwiftPackageReference "OpenAISwift" */;
productName = OpenAISwift;
};
E351083828FD8089007C85AE /* Sentry */ = {
isa = XCSwiftPackageProductDependency;
package = E3327E95272C68DE00AD5CC7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */;
Expand Down
4 changes: 2 additions & 2 deletions Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MARKETING_VERSION = 2.8.1
CURRENT_PROJECT_VERSION = 47
MARKETING_VERSION = 2.9.0
CURRENT_PROJECT_VERSION = 48

// Source for the base of all bundle IDs
// -> Intents extensions and app will derive bundleID from here
Expand Down
2 changes: 1 addition & 1 deletion Intents Extension/Actions/GetHighResolutionTimestamp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Returns a timestamp representing the current instant in nanoseconds.
Example: 434055845120916
The most common use-case is to substract two instances of this to get a highly accurate difference.
The most common use-case is to subtract two instances of this to get a highly accurate difference.
The timestamp is not meant to be stored for a long time. It's only unique for the current computer session.
""",
Expand Down
9 changes: 4 additions & 5 deletions Intents Extension/Actions/IsCellularDataOn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ On macOS, it always returns false.
categoryName: "Device"
)

static var parameterSummary: some ParameterSummary {
Summary("Is cellular data on?")
}

func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
.result(value: await Device.isCellularDataEnabled)
// Give the system time to change the mode when used in an automation.
sleep(.milliseconds(30))

return .result(value: await Device.isCellularDataEnabled)
}
}
21 changes: 21 additions & 0 deletions Intents Extension/Actions/IsCellularLowDataModeOn.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import AppIntents

struct IsCellularLowDataModeOn: AppIntent {
static let title: LocalizedStringResource = "Is Cellular Low Data Mode On"

static let description = IntentDescription(
"""
Returns whether cellular low data mode is enabled on the device.
On macOS, it always returns false.
""",
categoryName: "Device"
)

func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
// Give the system time to change the mode when used in an automation.
sleep(.milliseconds(30))

return .result(value: await Device.isCellularLowDataModeEnabled)
}
}
6 changes: 5 additions & 1 deletion Intents Extension/Actions/IsSilentModeOn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ struct IsSilentModeOn: AppIntent, CustomIntentMigratedAppIntent {
static let title: LocalizedStringResource = "Is Silent Mode On (iOS-only)"

static let description = IntentDescription(
"Returns whether the silent switch (mute) is enabled on the device.",
"""
Returns whether the silent switch (mute) is enabled on the device.
Known limitation: This will return true even if silent mode is not enabled if it's run while Voice Memos is recording.
""",
categoryName: "Device"
)

Expand Down
2 changes: 2 additions & 0 deletions Intents Extension/Actions/TransformLists.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Note that duplicates will be removed from the result.
Tap and hold a list parameter to select a variable to a list. Don't quick tap it.
Note: If you get the error “The operation failed because Shortcuts couldn't convert from Text to NSString.”, just change the preview to show a list view instead. This is a bug in the Shortcuts app.
Known limitation: It does not work with iTunes Media items.
""",
categoryName: "List"
)
Expand Down
85 changes: 9 additions & 76 deletions Shared/Actions/AskChatGPT.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import AppIntents
import SimpleKeychain
import OpenAISwift

@available(*, deprecated, message: "This action was moved to a separate app called “AI Actions” by the same author. It's a drop-in replacement.")
struct AskChatGPT: AppIntent {
static let title: LocalizedStringResource = "Ask ChatGPT"

static let description = IntentDescription(
"""
Send a prompt to ChatGPT and get a text reply.
It does not remember previous conversations.
IMPORTANT: You must add your open OpenAI API key in the app settings before using this action.
NOTE: Using the GPT-4 model requires access to the beta: https://openai.com/waitlist/gpt-4
NOTE: The GPT-4 model generally costs 14x more than GPT-3.5.
TIP: If you want a dictionary back, end your prompt with: “Return the result as a JSON object. Don't include any other text than the JSON object.” and then pass the result to the “Get Dictionary from Input” action. For more consistent result, also describe the shape of the JSON and include an example.
DEPRECATED. WILL BE REMOVED SOON.
""",
categoryName: "AI"
)
Expand All @@ -29,7 +19,7 @@ TIP: If you want a dictionary back, end your prompt with: “Return the result a

@Parameter(
title: "Max Tokens",
description: "The maximum number of tokens allowed for the generated answer. More about tokens: https://platform.openai.com/tokenizer"
description: "The maximum number of tokens allowed for the generated answer."
)
var maxTokens: Int?

Expand All @@ -52,7 +42,7 @@ TIP: If you want a dictionary back, end your prompt with: “Return the result a

@Parameter(
title: "Presence Penalty",
description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. More info: https://platform.openai.com/docs/api-reference/parameter-details Default: 0",
description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. Default: 0",
default: 0,
// controlStyle: .slider,
inclusiveRange: (-2, 2)
Expand All @@ -61,7 +51,7 @@ TIP: If you want a dictionary back, end your prompt with: “Return the result a

@Parameter(
title: "Frequency Penalty",
description: "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. More info: https://platform.openai.com/docs/api-reference/parameter-details Default: 0",
description: "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. Default: 0",
default: 0,
// controlStyle: .slider,
inclusiveRange: (-2, 2)
Expand Down Expand Up @@ -103,68 +93,11 @@ As an example, you can pass {"50256": -100} to prevent the <|endoftext|> token f
}

func perform() async throws -> some IntentResult & ReturnsValue<String> {
let keychain = SimpleKeychain(synchronizable: true)

guard
try keychain.hasItem(forKey: Constants.keychainKey_openAI),
let token = try keychain.string(forKey: Constants.keychainKey_openAI).nilIfEmptyOrWhitespace
else {
throw "Please add your OpenAI API key in the settings of the main Actions app.".toError
}

let openAI = OpenAISwift(authToken: token)

let logitBiasFinal = try logitBias?
.nilIfEmptyOrWhitespace?
.toData
.jsonToDictionary()
.compactMapKeys { Int($0) }
.compactMapValues {
if let double = $0 as? Double {
return double
}

if let string = $0 as? String {
return Double(string)
}

return nil
}

let response: OpenAI<MessageResult>
do {
response = try await openAI.sendChat(
with: [
.init(role: .system, content: "Keep it short."),
.init(role: .user, content: prompt)
],
model: model == .gpt3_5 ? .chat(.chatgpt) : .gpt4(.gpt4),
temperature: temperature,
topProbabilityMass: topProbabilityMass,
maxTokens: maxTokens,
presencePenalty: presencePenalty,
frequencyPenalty: frequencyPenalty,
logitBias: logitBiasFinal
)
} catch OpenAIError.genericError(let error) {
throw error.presentableMessage.toError
} catch OpenAIError.decodingError(let error) {
throw error.presentableMessage.toError
} catch OpenAIError.chatError(let error) {
var message = error.message

if error.code == "model_not_found" {
message += ". Make sure you have access to this model. GPT-4 requires special access."
}

throw error.message.toError
}

guard let reply = response.choices?.first?.message.content else {
throw "Missing reply.".toError
}
#if os(macOS)
"https://sindresorhus.com/ai-actions".openUrl()
#endif

return .result(value: reply)
return .result(value: "PLEASE READ: This action was moved to a separate app called “AI Actions” by the same author. It's a drop-in replacement. The action in that app is called “Ask AI”. https://sindresorhus.com/ai-actions")
}
}

Expand Down

0 comments on commit deba9ba

Please sign in to comment.