Skip to content

Commit

Permalink
feat: adds initializer with default base URL (#15)
Browse files Browse the repository at this point in the history
* feat: adds initializer with default base URL

* improves the usage examples
  • Loading branch information
kevinhermawan authored Mar 30, 2024
1 parent ec01cc2 commit 1a6d2e9
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Sources/OllamaKit/OllamaKit+Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method sets up a streaming connection using the Combine framework, facilitating real-time data handling as chat responses are generated by the Ollama API.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let chatData = OKChatRequestData(/* parameters */)
///
/// ollamaKit.chat(data: chatData)
Expand Down
4 changes: 2 additions & 2 deletions Sources/OllamaKit/OllamaKit+CopyModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method sends a request to the Ollama API to copy a model based on the provided ``OKCopyModelRequestData``.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKCopyModelRequestData(/* parameters */)
/// try await ollamaKit.copyModel(data: requestData)
/// ```
Expand All @@ -32,7 +32,7 @@ extension OllamaKit {
/// This method provides a reactive approach to request a model copy operation. It accepts ``OKCopyModelRequestData`` and returns a Combine publisher that completes when the copy operation is finished.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKCopyModelRequestData(/* parameters */)
///
/// ollamaKit.copyModel(data: requestData)
Expand Down
4 changes: 2 additions & 2 deletions Sources/OllamaKit/OllamaKit+DeleteModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method sends a request to the Ollama API to delete a model based on the provided ``OKDeleteModelRequestData``.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKDeleteModelRequestData(/* parameters */)
/// try await ollamaKit.deleteModel(data: requestData)
/// ```
Expand All @@ -32,7 +32,7 @@ extension OllamaKit {
/// This method provides a reactive approach to request a model deletion operation. It accepts ``OKDeleteModelRequestData`` and returns a Combine publisher that completes when the deletion operation is finished.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKDeleteModelRequestData(/* parameters */)
///
/// ollamaKit.deleteModel(data: requestData)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OllamaKit/OllamaKit+Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method sets up a streaming connection using the Combine framework, allowing for real-time data handling as the responses are generated by the Ollama API.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKGenerateRequestData(/* parameters */)
///
/// ollamaKit.generate(data: requestData)
Expand Down
4 changes: 2 additions & 2 deletions Sources/OllamaKit/OllamaKit+GenerateEmbeddings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method accepts ``OKGenerateEmbeddingsRequestData`` and returns an ``OKGenerateEmbeddingsResponse`` containing embeddings from the requested model.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKGenerateEmbeddingsRequestData(/* parameters */)
/// let generateEmbeddings = try await ollamaKit.generateEmbeddings(data: requestData)
/// ```
Expand All @@ -36,7 +36,7 @@ extension OllamaKit {
/// This method provides a reactive approach to generate embeddings. It accepts ``OKGenerateEmbeddingsRequestData`` and returns a Combine publisher that emits an ``OKGenerateEmbeddingsResponse`` upon successful retrieval.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKGenerateEmbeddingsRequestData(/* parameters */)
///
/// ollamaKit.generateEmbeddings(data: requestData)
Expand Down
4 changes: 2 additions & 2 deletions Sources/OllamaKit/OllamaKit+ModelInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method accepts ``OKModelInfoRequestData`` and returns an ``OKModelInfoResponse`` containing detailed information about the requested model.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKModelInfoRequestData(/* parameters */)
/// let modelInfo = try await ollamaKit.modelInfo(data: requestData)
/// ```
Expand All @@ -36,7 +36,7 @@ extension OllamaKit {
/// This method provides a reactive approach to fetch detailed model information. It accepts ``OKModelInfoRequestData`` and returns a Combine publisher that emits an ``OKModelInfoResponse`` upon successful retrieval.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let requestData = OKModelInfoRequestData(/* parameters */)
///
/// ollamaKit.modelInfo(data: requestData)
Expand Down
4 changes: 2 additions & 2 deletions Sources/OllamaKit/OllamaKit+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method returns an ``OKModelResponse`` containing the details of the available models.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let models = try await ollamaKit.models()
/// ```
///
Expand All @@ -34,7 +34,7 @@ extension OllamaKit {
/// This method provides a reactive approach to fetch model data, returning a Combine publisher that emits an ``OKModelResponse`` with details of available models.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
///
/// ollamaKit.models()
/// .sink(receiveCompletion: { completion in
Expand Down
4 changes: 2 additions & 2 deletions Sources/OllamaKit/OllamaKit+Reachable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension OllamaKit {
/// This method attempts to make a network request to the Ollama API. It returns `true` if the request is successful, indicating that the API is reachable. Otherwise, it returns `false`.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
/// let isReachable = await ollamaKit.reachable()
/// ```
///
Expand All @@ -37,7 +37,7 @@ extension OllamaKit {
/// This method performs a network request to the Ollama API and returns a Combine publisher that emits `true` if the API is reachable. In case of any errors, it emits `false`.
///
/// ```swift
/// let ollamaKit = OllamaKit(baseURL: URL(string: "http://localhost:11434")!)
/// let ollamaKit = OllamaKit()
///
/// ollamaKit.reachable()
/// .sink(receiveValue: { isReachable in
Expand Down
30 changes: 20 additions & 10 deletions Sources/OllamaKit/OllamaKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@
import Foundation

/// Provides a streamlined way to access the Ollama API, encapsulating the complexities of network communication and data processing.
///
/// Usage of ``OllamaKit`` involves initializing it with the base URL of the Ollama API. This setup configures the internal router and decoder for handling API interactions.
///
/// ```swift
/// let baseURL = URL(string: "http://localhost:11434")!
/// let ollamaKit = OllamaKit(baseURL: baseURL)
/// ```
///
/// - Initialization:
/// - `init(baseURL: URL)`: Initializes a new instance of ``OllamaKit`` with the provided base URL for the Ollama API.
public struct OllamaKit {
var router: OKRouter.Type
var decoder: JSONDecoder = .default

/// Initializes a new instance of `OllamaKit` with the default base URL for the Ollama API.
///
/// ```swift
/// let ollamaKit = OllamaKit()
/// ```
public init() {
let router = OKRouter.self
router.baseURL = URL(string: "http://localhost:11434")!

self.router = router
}

/// Initializes a new instance of `OllamaKit` with a custom base URL for the Ollama API.
///
/// ```swift
/// let customBaseURL = URL(string: "https://api.customollama.com")!
/// let ollamaKit = OllamaKit(baseURL: customBaseURL)
/// ```
///
/// - Parameter baseURL: The base URL to use for API requests.
public init(baseURL: URL) {
let router = OKRouter.self
router.baseURL = baseURL
Expand Down

0 comments on commit 1a6d2e9

Please sign in to comment.