-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors chat API to use new OKTool structure
- Loading branch information
Showing
3 changed files
with
110 additions
and
143 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
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,46 @@ | ||
// | ||
// OKTool.swift | ||
// OllamaKit | ||
// | ||
// Created by Norikazu Muramoto on 2025/01/11. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Represents a tool that can be used in the Ollama API chat. | ||
public struct OKTool: Encodable, Sendable { | ||
/// The type of the tool (e.g., "function"). | ||
public let type: String | ||
|
||
/// The function details associated with the tool. | ||
public let function: OKFunction | ||
|
||
public init(type: String, function: OKFunction) { | ||
self.type = type | ||
self.function = function | ||
} | ||
|
||
/// Convenience method for creating a tool with type "function". | ||
public static func function(_ function: OKFunction) -> OKTool { | ||
return OKTool(type: "function", function: function) | ||
} | ||
} | ||
|
||
/// Represents a function used as a tool in the Ollama API chat. | ||
public struct OKFunction: Encodable, Sendable { | ||
/// The name of the function. | ||
public let name: String | ||
|
||
/// A description of what the function does. | ||
public let description: String | ||
|
||
/// Parameters required by the function, defined as a JSON schema. | ||
public let parameters: OKJSONValue | ||
|
||
public init(name: String, description: String, parameters: OKJSONValue) { | ||
self.name = name | ||
self.description = description | ||
self.parameters = parameters | ||
} | ||
} | ||
|