Skip to content

Commit

Permalink
refactor: removes Alamofire from modelInfo (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhermawan authored Jun 8, 2024
1 parent 13eda0e commit 86ec567
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Sources/OllamaKit/OllamaKit+ModelInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ extension OllamaKit {
/// - Returns: An ``OKModelInfoResponse`` containing detailed information about the model.
/// - Throws: An error if the request fails or the response can't be decoded.
public func modelInfo(data: OKModelInfoRequestData) async throws -> OKModelInfoResponse {
let request = AF.request(router.modelInfo(data: data)).validate()
let response = request.serializingDecodable(OKModelInfoResponse.self, decoder: decoder)
let value = try await response.value
let request = try OKRouter.modelInfo(data: data).asURLRequest()

return value
return try await OKHTTPClient.shared.sendRequest(for: request, with: OKModelInfoResponse.self)
}

/// Retrieves detailed information for a specific model from the Ollama API as a Combine publisher.
Expand All @@ -49,12 +47,16 @@ extension OllamaKit {
/// ```
///
/// - Parameter data: The ``OKModelInfoRequestData`` used to query the API for specific model information.
/// - Returns: A `AnyPublisher<OKModelInfoResponse, AFError>` that emits detailed information about the model.
public func modelInfo(data: OKModelInfoRequestData) -> AnyPublisher<OKModelInfoResponse, AFError> {
let request = AF.request(router.modelInfo(data: data)).validate()
/// - Returns: A `AnyPublisher<OKModelInfoResponse, Error>` that emits detailed information about the model.
public func modelInfo(data: OKModelInfoRequestData) -> AnyPublisher<OKModelInfoResponse, Error> {
let request: URLRequest

return request
.publishDecodable(type: OKModelInfoResponse.self, decoder: decoder).value()
.eraseToAnyPublisher()
do {
request = try OKRouter.modelInfo(data: data).asURLRequest()
} catch {
return Fail(error: error).eraseToAnyPublisher()
}

return OKHTTPClient.shared.sendRequest(for: request, with: OKModelInfoResponse.self)
}
}

0 comments on commit 86ec567

Please sign in to comment.