Skip to content
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-17685462 - Update SfapClient to use updated send method #3820

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,12 @@
path: "einstein/platform/v1/models/\(modelName)/embeddings"
)

// Submit the sfap_api embeddings request and fetch the response.
let embeddingsResponse = await withCheckedContinuation { continuation in
restClient.send(
request: embeddingsRequest
) { result in
continuation.resume(returning: result)
}
}

// React to the sfap_api embeddings response.
switch embeddingsResponse {

case .success(let embeddingsResponse):
// Decode the sfap_api embeddings response.
let embeddingsResponseBody = try embeddingsResponse.asDecodable(
type: EmbeddingsResponseBody.self
)
embeddingsResponseBody.sourceJson = embeddingsResponse.asString()
return embeddingsResponseBody

case .failure(let error):
throw try errorForRestClientError(error, requestName: "generate embeddings request")
}
let embeddingsResponse = try await restClient.send(request: embeddingsRequest)
let embeddingsResponseBody = try embeddingsResponse.asDecodable(
type: EmbeddingsResponseBody.self

Check warning on line 104 in libs/SalesforceSDKCore/SalesforceSDKCore/Classes/RestAPI/SfapAPI/SfapClient.swift

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'send(request:_:)' is deprecated: Deprecated in Salesforce Mobile SDK 13.0 and will be removed in Salesforce Mobile SDK 14.0. Use the async/await version of `send(request:)` instead.
)
embeddingsResponseBody.sourceJson = embeddingsResponse.asString()
return embeddingsResponseBody
}

/**
Expand Down Expand Up @@ -151,29 +134,12 @@
path: "einstein/platform/v1/models/\(modelName)/chat-generations"
)

// Submit the sfap_api chat generations request and fetch the response.
let chatGenerationsResponse = await withCheckedContinuation { continuation in
restClient.send(
request: chatGenerationsRequest
) { result in
continuation.resume(returning: result)
}
}

// React to the sfap_api chat generations response.
switch chatGenerationsResponse {

case .success(let chatGenerationsResponse):
// Decode the sfap_api chat generations response.
let chatGenerationsResponseBody = try chatGenerationsResponse.asDecodable(
type: ChatGenerationsResponseBody.self
)
chatGenerationsResponseBody.sourceJson = chatGenerationsResponse.asString()
return chatGenerationsResponseBody

case .failure(let error):
throw try errorForRestClientError(error, requestName: "chat generations request")
}
let chatGenerationsResponse = try await restClient.send(request: chatGenerationsRequest)
let chatGenerationsResponseBody = try chatGenerationsResponse.asDecodable(
type: ChatGenerationsResponseBody.self
)
chatGenerationsResponseBody.sourceJson = chatGenerationsResponse.asString()
return chatGenerationsResponseBody
}

/**
Expand All @@ -187,7 +153,7 @@
_ prompt: String
) async throws -> GenerationsResponseBody {

// Guards.

Check warning on line 156 in libs/SalesforceSDKCore/SalesforceSDKCore/Classes/RestAPI/SfapAPI/SfapClient.swift

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'send(request:_:)' is deprecated: Deprecated in Salesforce Mobile SDK 13.0 and will be removed in Salesforce Mobile SDK 14.0. Use the async/await version of `send(request:)` instead.
guard let modelName = modelName else {
throw sfapError(message: "Cannot fetch generated text without specifying a model name.")
}
Expand All @@ -203,29 +169,12 @@
path: "einstein/platform/v1/models/\(modelName)/generations"
)

// Submit the sfap_api generations request and fetch the response.
let generationsResponse = await withCheckedContinuation { continuation in
restClient.send(
request: generationsRequest
) { result in
continuation.resume(returning: result)
}
}

// React to the sfap_api generations response.
switch generationsResponse {

case .success(let generationsResponse):
// Decode the sfap_api generations response.
let generationsResponseBody = try generationsResponse.asDecodable(
type: GenerationsResponseBody.self
)
generationsResponseBody.sourceJson = generationsResponse.asString()
return generationsResponseBody

case .failure(let error):
throw try errorForRestClientError(error, requestName: "generations request")
}
let generationsResponse = try await restClient.send(request: generationsRequest)
let generationsResponseBody = try generationsResponse.asDecodable(
type: GenerationsResponseBody.self
)
generationsResponseBody.sourceJson = generationsResponse.asString()
return generationsResponseBody
}

/**
Expand All @@ -251,29 +200,12 @@
path: "einstein/platform/v1/feedback"
)

// Submit the sfap_api feedback request and fetch the response.
let feedbackResponse = await withCheckedContinuation { continuation in
restClient.send(
request: feedbackRequest
) { result in
continuation.resume(returning: result)
}
}

// React to the sfap_api feedback response.
switch feedbackResponse {

case .success(let feedbackResponse):
// Decode the sfap_api feedback response.
let feedbackResponseBody = try feedbackResponse.asDecodable(
type: FeedbackResponseBody.self
)
feedbackResponseBody.sourceJson = feedbackResponse.asString()
return feedbackResponseBody

case .failure(let error):
throw try errorForRestClientError(error, requestName: "feedback request")
}
let feedbackResponse = try await restClient.send(request: feedbackRequest)
let feedbackResponseBody = try feedbackResponse.asDecodable(
type: FeedbackResponseBody.self
)
feedbackResponseBody.sourceJson = feedbackResponse.asString()
return feedbackResponseBody

Check warning on line 208 in libs/SalesforceSDKCore/SalesforceSDKCore/Classes/RestAPI/SfapAPI/SfapClient.swift

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'send(request:_:)' is deprecated: Deprecated in Salesforce Mobile SDK 13.0 and will be removed in Salesforce Mobile SDK 14.0. Use the async/await version of `send(request:)` instead.
}

private func generateHeaders() -> NSMutableDictionary {
Expand Down Expand Up @@ -321,7 +253,7 @@
private func errorForRestClientError(_ restClientError: RestClientError, requestName: String) throws -> Error {
switch restClientError {

case .apiFailed(

Check warning on line 256 in libs/SalesforceSDKCore/SalesforceSDKCore/Classes/RestAPI/SfapAPI/SfapClient.swift

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'send(request:_:)' is deprecated: Deprecated in Salesforce Mobile SDK 13.0 and will be removed in Salesforce Mobile SDK 14.0. Use the async/await version of `send(request:)` instead.
response: let response,
underlyingError: _,
urlResponse: _
Expand Down
Loading