-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@W-16589742: [iOS] REST wrappers for select SFAP APIs #3801
Merged
JohnsonEricAtSalesforce
merged 9 commits into
forcedotcom:dev
from
JohnsonEricAtSalesforce:feature/w-16589742_ios-rest-wrappers-for-select-sfap-apis
Jan 17, 2025
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d974c3
@W-16589742: [iOS] REST wrappers for select SFAP APIs
JohnsonEricAtSalesforce a401e1a
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Self-Review Up…
JohnsonEricAtSalesforce 70101dc
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Team-Review Up…
JohnsonEricAtSalesforce 8987b9a
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Implementation…
JohnsonEricAtSalesforce 84b883d
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Rename SfapAPI…
JohnsonEricAtSalesforce 5827e32
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Update Xcode P…
JohnsonEricAtSalesforce 981eab4
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Team Code Revi…
JohnsonEricAtSalesforce 74df154
@W-16589742: [iOS] REST wrappers for select SFAP APIs (One More `Sfap…
JohnsonEricAtSalesforce fe63b95
@W-16589742: [iOS] REST wrappers for select SFAP APIs (Additional Nam…
JohnsonEricAtSalesforce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...SDKCore/SalesforceSDKCore/Classes/RestAPI/SFAPAPI/SFAPAPIChatGenerationsRequestBody.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
SFAPAPIChatGenerationsRequestBody.swift | ||
SalesforceSDKCore | ||
|
||
Created by Eric C. Johnson ([email protected]) on 20250114. | ||
|
||
Copyright (c) 2025-present, salesforce.com, inc. All rights reserved. | ||
|
||
Redistribution and use of this software in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions | ||
and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of | ||
conditions and the following disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to | ||
endorse or promote products derived from this software without specific prior written | ||
permission of salesforce.com, inc. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY | ||
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/** | ||
* Models a `sfap_api` `chat-generations` endpoint request. | ||
* See https://developer.salesforce.com/docs/einstein/genai/references/models-api?meta=generateChat | ||
* | ||
* The endpoint accepts a `tags` object. To provide `tags`, subclass and introduce a | ||
* new parameter of any object type named `tags`. Also, the subclass will need to conform to | ||
* `Codable` and provide handling for the custom `tags` object's encoding and decoding as in | ||
* the following sample code. | ||
* required init(from decoder: any Decoder) throws { | ||
* let container = try decoder.container(keyedBy: CodingKeys.self) | ||
* self.tags = try container.decode(Tags.self, forKey: .tags) | ||
* try super.init(from: decoder) | ||
* } | ||
* | ||
* public init( | ||
* // Provide superclass parameters | ||
* tags: Tags | ||
* ) { | ||
* self.tags = tags | ||
* super.init( // Provide superclass parameters) | ||
* } | ||
* | ||
* public override func encode(to encoder: any Encoder) throws { | ||
* var container = encoder.container(keyedBy: CodingKeys.self) | ||
* try container.encode(tags, forKey: .tag`) | ||
* try super.encode(to: encoder) | ||
* } | ||
*/ | ||
@objc | ||
open class SFAPAPIChatGenerationsRequestBody : NSObject, Codable { | ||
|
||
/// The request messages parameter value | ||
public let messages: Array<Message> | ||
|
||
/// The request localization parameter value | ||
public let localization: Localization | ||
|
||
public init( | ||
messages: Array<Message>, | ||
localization: Localization | ||
) { | ||
self.messages = messages | ||
self.localization = localization | ||
} | ||
|
||
public struct Message : Codable { | ||
public let role: String | ||
public let content: String | ||
|
||
public init(role: String, content: String) { | ||
self.role = role | ||
self.content = content | ||
} | ||
} | ||
|
||
public struct Localization : Codable { | ||
public let defaultLocale: String | ||
public let inputLocales: Array<Locale> | ||
public let expectedLocales: Array<String> | ||
|
||
public init( | ||
defaultLocale: String, | ||
inputLocales: Array<Locale>, | ||
expectedLocales: Array<String> | ||
) { | ||
self.defaultLocale = defaultLocale | ||
self.inputLocales = inputLocales | ||
self.expectedLocales = expectedLocales | ||
} | ||
} | ||
|
||
public struct Locale : Codable { | ||
public let locale: String | ||
public let probability: Double | ||
|
||
public init( | ||
locale: String, | ||
probability: Double | ||
) { | ||
self.locale = locale | ||
self.probability = probability | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, sorry, I didn't mean to suggest changing the SFAP part of the Swift names, I meant that I think all the
objc
names should match across classes in parallel with the Swift naming.So from the latest client naming,
I would think this
cc @wmathurin if you have any other thoughts on the format to align on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The funny thing is that the A in SFAP stands for API so SFAP API translates to "salesforce api platform api".
That being said, we didn't start that, the oauth scope is also called "sfap_api".
Should we just call them SfapClient / SfapChat etc ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for Swift. For Objective-C we'd normally add the SF or SFSDK prefix which is also funny for this one because if we do SF like SFRest it's SFSfapClient? or Eric I think you had a condensed version before like SFApClient? No preference from me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like @wmathurin said, it's almost like saying "I'll have a chai tea" ☕️ which, of course, translates to Tea-Tea 🤣
So, maybe thinking like someone who's less used to the
SF
prefix that was used by everything in the legacy Objc codebase: If I were looking for thesfap_api
related code in either Swift or Objc theSFAPAPI
prefixes seem really intuitive to me for both languages. They're also really consistent with the Android code, even though we uppercased it instead of camel-casing it. It is a bit verbose but that's something the old-school iOS dev in me is also really used to 🤓I'd lean towards keeping it named similarly to the Android code, being a multi-platform developer as I am.
Outside of this context, I would usually agree we can drop the mandatory
SF
prefix the Objc code used since that's not really Swifty (is it?).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To the end of consistency, I actually found one more camel-cased name I missed earlier (I was so sure I got them all!) 74df154