Skip to content

Commit

Permalink
Remove a force unwrap and formating (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Dec 13, 2023
1 parent 6c19387 commit ea39d69
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Sources/GoogleAI/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class Chat {
/// - Parameter content: The new content to send as a single chat message.
/// - Returns: The model's response if no error occurred.
/// - Throws: A ``GenerateContentError`` if an error occurred.
public func sendMessage(_ content: [ModelContent]) async throws
-> GenerateContentResponse {
public func sendMessage(_ content: [ModelContent]) async throws -> GenerateContentResponse {
// Ensure that the new content has the role set.
let newContent: [ModelContent] = content.map(populateContentRole(_:))

Expand Down
6 changes: 3 additions & 3 deletions Tests/GoogleAITests/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,18 @@ final class GenerativeModelTests: XCTestCase {

private func httpRequestHandler(forResource name: String,
withExtension ext: String,
statusCode: Int = 200) throws -> ((URLRequest) -> (
statusCode: Int = 200) throws -> ((URLRequest) throws -> (
URLResponse,
AsyncLineSequence<URL.AsyncBytes>?
)) {
let fileURL = try XCTUnwrap(Bundle.module.url(forResource: name, withExtension: ext))
return { request in
let response = HTTPURLResponse(
let response = try XCTUnwrap(HTTPURLResponse(
url: request.url!,
statusCode: statusCode,
httpVersion: nil,
headerFields: nil
)!
))
return (response, fileURL.lines)
}
}
Expand Down
7 changes: 5 additions & 2 deletions Tests/GoogleAITests/MockURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import XCTest

@available(iOS 15.0, tvOS 15.0, *)
class MockURLProtocol: URLProtocol {
static var requestHandler: ((URLRequest) -> (URLResponse, AsyncLineSequence<URL.AsyncBytes>?))?
static var requestHandler: ((URLRequest) throws -> (
URLResponse,
AsyncLineSequence<URL.AsyncBytes>?
))?

override class func canInit(with request: URLRequest) -> Bool { return true }

Expand All @@ -32,7 +35,7 @@ class MockURLProtocol: URLProtocol {
}

Task {
let (response, stream) = requestHandler(self.request)
let (response, stream) = try requestHandler(self.request)
client.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
if let stream = stream {
do {
Expand Down

0 comments on commit ea39d69

Please sign in to comment.