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

refactor: removes Alamofire from modelInfo #23

Merged
merged 1 commit into from
Jun 8, 2024
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
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)
}
}
Loading