Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ let package = Package(
targets: ["OllamaKit"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.3.0"))
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.3.0")),
.package(url: "https://github.com/1amageek/swift-json-schema.git", branch: "main")
],
targets: [
.target(
name: "OllamaKit",
dependencies: []),
dependencies: [
.product(name: "JSONSchema", package: "swift-json-schema")
]),
.testTarget(
name: "OllamaKitTests",
dependencies: ["OllamaKit"]),
Expand Down
7 changes: 5 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ let package = Package(
targets: ["OllamaKit"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.3.0"))
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.3.0")),
.package(url: "https://github.com/kevinhermawan/swift-json-schema.git", .upToNextMajor(from: "2.0.1"))
],
targets: [
.target(
name: "OllamaKit",
dependencies: []),
dependencies: [
.product(name: "JSONSchema", package: "swift-json-schema")
]),
.testTarget(
name: "OllamaKitTests",
dependencies: ["OllamaKit"]),
Expand Down
2 changes: 1 addition & 1 deletion Playground/OKPlayground/Views/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ChatView: View {
@Environment(ViewModel.self) private var viewModel

@State private var model: String? = nil
@State private var temperature: Double = 0.5
@State private var temperature: Float = 0.5
@State private var prompt = ""
@State private var response = ""
@State private var cancellables = Set<AnyCancellable>()
Expand Down
25 changes: 12 additions & 13 deletions Playground/OKPlayground/Views/ChatWithFormatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Combine
import OllamaKit
import SwiftUI
import JSONSchema

struct ChatWithFormatView: View {

Expand Down Expand Up @@ -133,19 +134,17 @@ struct ChatWithFormatView: View {
.store(in: &cancellables)
}

private func getFormat() -> OKJSONValue {
return
.object(["type": .string("array"),
"items": .object([
"type" : .string("object"),
"properties": .object([
"id": .object(["type" : .string("string")]),
"country": .object(["type" : .string("string")]),
"capital": .object(["type" : .string("string")]),
]),
"required": .array([.string("id"), .string("country"), .string("capital")])
])
])
private func getFormat() -> JSONSchema {
return .array(
items:.object(
properties: [
"id": .string(),
"country": .string(),
"capital": .string()
],
required: ["id", "country", "capital"]
)
)
}

private func decodeResponse(_ content: String) {
Expand Down
43 changes: 19 additions & 24 deletions Playground/OKPlayground/Views/ChatWithToolsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,32 @@ struct ChatWithToolsView: View {
.store(in: &cancellables)
}

private func getTools() -> [OKJSONValue] {
private func getTools() -> [OKTool] {
return [
.object([
"type": .string("function"),
"function": .object([
"name": .string("get_current_weather"),
"description": .string("Get the current weather for a location"),
"parameters": .object([
"type": .string("object"),
"properties": .object([
"location": .object([
"type": .string("string"),
"description": .string("The location to get the weather for, e.g. San Francisco, CA")
]),
"format": .object([
"type": .string("string"),
"description": .string("The format to return the weather in, e.g. 'celsius' or 'fahrenheit'"),
"enum": .array([.string("celsius"), .string("fahrenheit")])
])
]),
"required": .array([.string("location"), .string("format")])
])
])
])
.function(
.init(
name: "get_current_weather",
description: "Get the current weather for a location",
parameters:
.object(
properties: [
"location": .string(
description: "The location to get the weather for, e.g. San Francisco, CA"
),
"format": .enum(description: "The format to return the weather in, e.g. 'celsius' or 'fahrenheit'", values: [.string("celsius"), .string("fahrenheit")])
],
required: ["location", "format"]
)
)
)

]
}

private func setResponses(_ function: OKChatResponse.Message.ToolCall.Function) {
self.toolCalledResponse = function.name ?? ""
self.argumentsResponse = "\(function.arguments ?? .string("No arguments"))"

if let arguments = function.arguments {
switch arguments {
case .object(let argDict):
Expand Down
2 changes: 1 addition & 1 deletion Playground/OKPlayground/Views/EmbeddingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct EmbeddingsView: View {

@State private var model: String? = nil
@State private var prompt = ""
@State private var embedding = [Double]()
@State private var embedding = [Float]()
@State private var cancellables = Set<AnyCancellable>()

var body: some View {
Expand Down
2 changes: 1 addition & 1 deletion Playground/OKPlayground/Views/GenerateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct GenerateView: View {
@Environment(ViewModel.self) private var viewModel

@State private var model: String? = nil
@State private var temperature: Double = 0.5
@State private var temperature: Float = 0.5
@State private var prompt = ""
@State private var response = ""
@State private var cancellables = Set<AnyCancellable>()
Expand Down
Loading
Loading