diff --git a/Sources/OllamaKit/OllamaKit+Chat.swift b/Sources/OllamaKit/OllamaKit+Chat.swift index e914c45..2006db9 100644 --- a/Sources/OllamaKit/OllamaKit+Chat.swift +++ b/Sources/OllamaKit/OllamaKit+Chat.swift @@ -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) diff --git a/Sources/OllamaKit/OllamaKit+CopyModel.swift b/Sources/OllamaKit/OllamaKit+CopyModel.swift index 0b6d06f..baedd0e 100644 --- a/Sources/OllamaKit/OllamaKit+CopyModel.swift +++ b/Sources/OllamaKit/OllamaKit+CopyModel.swift @@ -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) /// ``` @@ -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) diff --git a/Sources/OllamaKit/OllamaKit+DeleteModel.swift b/Sources/OllamaKit/OllamaKit+DeleteModel.swift index 0ed6326..11c6506 100644 --- a/Sources/OllamaKit/OllamaKit+DeleteModel.swift +++ b/Sources/OllamaKit/OllamaKit+DeleteModel.swift @@ -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) /// ``` @@ -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) diff --git a/Sources/OllamaKit/OllamaKit+Generate.swift b/Sources/OllamaKit/OllamaKit+Generate.swift index 44bbe78..9f17b1c 100644 --- a/Sources/OllamaKit/OllamaKit+Generate.swift +++ b/Sources/OllamaKit/OllamaKit+Generate.swift @@ -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) diff --git a/Sources/OllamaKit/OllamaKit+GenerateEmbeddings.swift b/Sources/OllamaKit/OllamaKit+GenerateEmbeddings.swift index c047c43..cdeb0e0 100644 --- a/Sources/OllamaKit/OllamaKit+GenerateEmbeddings.swift +++ b/Sources/OllamaKit/OllamaKit+GenerateEmbeddings.swift @@ -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) /// ``` @@ -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) diff --git a/Sources/OllamaKit/OllamaKit+ModelInfo.swift b/Sources/OllamaKit/OllamaKit+ModelInfo.swift index 1fcf15c..70fe448 100644 --- a/Sources/OllamaKit/OllamaKit+ModelInfo.swift +++ b/Sources/OllamaKit/OllamaKit+ModelInfo.swift @@ -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) /// ``` @@ -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) diff --git a/Sources/OllamaKit/OllamaKit+Models.swift b/Sources/OllamaKit/OllamaKit+Models.swift index 2817154..bfa2974 100644 --- a/Sources/OllamaKit/OllamaKit+Models.swift +++ b/Sources/OllamaKit/OllamaKit+Models.swift @@ -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() /// ``` /// @@ -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 diff --git a/Sources/OllamaKit/OllamaKit+Reachable.swift b/Sources/OllamaKit/OllamaKit+Reachable.swift index df5212d..aff37c8 100644 --- a/Sources/OllamaKit/OllamaKit+Reachable.swift +++ b/Sources/OllamaKit/OllamaKit+Reachable.swift @@ -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() /// ``` /// @@ -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 diff --git a/Sources/OllamaKit/OllamaKit.swift b/Sources/OllamaKit/OllamaKit.swift index 5eda69a..4312913 100644 --- a/Sources/OllamaKit/OllamaKit.swift +++ b/Sources/OllamaKit/OllamaKit.swift @@ -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