-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a6d2e9
commit 24202d0
Showing
9 changed files
with
86 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// OllamaKit+Embeddings.swift | ||
// | ||
// | ||
// Created by Paul Thrasher on 02/09/24. | ||
// | ||
|
||
import Alamofire | ||
import Combine | ||
import Foundation | ||
|
||
extension OllamaKit { | ||
/// Asynchronously generates embeddings from a specific model from the Ollama API. | ||
/// | ||
/// This method accepts ``OKEmbeddingsRequestData`` and returns an ``OKEmbeddingsResponse`` containing embeddings from the requested model. | ||
/// | ||
/// ```swift | ||
/// let ollamaKit = OllamaKit() | ||
/// let requestData = OKEmbeddingsRequestData(/* parameters */) | ||
/// let embeddings = try await ollamaKit.embeddings(data: requestData) | ||
/// ``` | ||
/// | ||
/// - Parameter data: The ``OKEmbeddingsRequestData`` used to query the API for generating specific model embeddings. | ||
/// - Returns: An ``OKEmbeddingsResponse`` containing the embeddings from the model. | ||
/// - Throws: An error if the request fails or the response can't be decoded. | ||
public func embeddings(data: OKEmbeddingsRequestData) async throws -> OKEmbeddingsResponse { | ||
let request = AF.request(router.embeddings(data: data)).validate() | ||
let response = request.serializingDecodable(OKEmbeddingsResponse.self, decoder: decoder) | ||
let value = try await response.value | ||
|
||
return value | ||
} | ||
|
||
/// Retrieves embeddings from a specific model from the Ollama API as a Combine publisher. | ||
/// | ||
/// This method provides a reactive approach to generate embeddings. It accepts ``OKEmbeddingsRequestData`` and returns a Combine publisher that emits an ``OKEmbeddingsResponse`` upon successful retrieval. | ||
/// | ||
/// ```swift | ||
/// let ollamaKit = OllamaKit() | ||
/// let requestData = OKEmbeddingsRequestData(/* parameters */) | ||
/// | ||
/// ollamaKit.embeddings(data: requestData) | ||
/// .sink(receiveCompletion: { completion in | ||
/// // Handle completion | ||
/// }, receiveValue: { response in | ||
/// // Handle the received embeddings response | ||
/// }) | ||
/// .store(in: &cancellables) | ||
/// ``` | ||
/// | ||
/// - Parameter data: The ``OKEmbeddingsRequestData`` used to query the API for embeddings from a specific model. | ||
/// - Returns: A `AnyPublisher<OKEmbeddingsResponse, AFError>` that emits embeddings. | ||
public func embeddings(data: OKEmbeddingsRequestData) -> AnyPublisher<OKEmbeddingsResponse, AFError> { | ||
let request = AF.request(router.embeddings(data: data)).validate() | ||
|
||
return request | ||
.publishDecodable(type: OKEmbeddingsResponse.self, decoder: decoder).value() | ||
.eraseToAnyPublisher() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// OKEmbeddingsResponse.swift | ||
// | ||
// | ||
// Created by Paul Thrasher on 02/09/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A structure that represents the response to an embedding request from the Ollama API. | ||
public struct OKEmbeddingsResponse: Decodable { | ||
|
||
/// An array of doubles representing the embeddings of the input prompt. | ||
public let embedding: [Double]? | ||
} |
15 changes: 0 additions & 15 deletions
15
Sources/OllamaKit/Responses/OKGenerateEmbeddingsResponse.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters