Skip to content

Commit

Permalink
ENG-1726 (#48)
Browse files Browse the repository at this point in the history
* initial

* Request/Response bodies setup.

* Client + Tests

* Tests + Model updates

* Upload file testing

* Further testing

* update

* removed API keys

* added get file test

* upload video and upload audio working

* Fixed file loading

* Cleaned up tests

* Added image test

* Added url test endpoint

* Cleanup

* cleanup

* cleanup

* update function call tests

* added role

* Added function calling + tests

* CodeFunction initial

* Testing fixes

* removed key

* Grounding initial setup

* Fixed endpoints

* Structured Output

* removed key

* Fine Tuning

* Embeddings

* refactor

* Fixed embeddings

* removed resources. Fixed tests.

* removed key

* Refactor

* Update package

---------

Co-authored-by: Vatsal Manot <[email protected]>
  • Loading branch information
Archetapp and vmanot authored Dec 20, 2024
1 parent 95b3ce3 commit bfe29a1
Show file tree
Hide file tree
Showing 57 changed files with 2,880 additions and 66 deletions.
10 changes: 5 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "c84aa4446fdd21cbb193bc4ba0b1cdc79c7ec1f15c14460832a38ff9323b7098",
"originHash" : "094840915419b625ed8a43083bdf164ab8d3f6bbb7fda2dcec07cb5e55a2b736",
"pins" : [
{
"identity" : "corepersistence",
Expand All @@ -16,7 +16,7 @@
"location" : "https://github.com/vmanot/Merge.git",
"state" : {
"branch" : "master",
"revision" : "aca0b0c7a48d91934b098bab9b5c4a9f343369f2"
"revision" : "4bc71ce650b79b3dbe1a26acf7e54b29d750e0b6"
}
},
{
Expand All @@ -34,7 +34,7 @@
"location" : "https://github.com/vmanot/Swallow.git",
"state" : {
"branch" : "master",
"revision" : "890a767eacad123a5310cdcc8074d16378c18cbe"
"revision" : "4c05166cf644846199fb734bbc47d74f87610945"
}
},
{
Expand All @@ -49,9 +49,9 @@
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-precompiled/swift-syntax",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "85ba62b876bb023acdd828d738703f1c08eaa058",
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
Expand Down
67 changes: 54 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,39 @@ let package = Package(
"Anthropic",
"Cohere",
"ElevenLabs",
"_Gemini",
"Groq",
"HuggingFace",
"Jina",
"Mistral",
"Ollama",
"OpenAI",
"Perplexity",
"TogetherAI",
"VoyageAI",
"AI",
]
),
.library(
name: "_Gemini",
targets: [
"_Gemini"
]
),
.library(
name: "Anthropic",
targets: [
"Anthropic"
]
),
.library(
name: "HumeAI",
targets: [
"HumeAI"
]
),
.library(
name: "NeetsAI",
targets: [
"NeetsAI"
]
),
.library(
name: "OpenAI",
targets: [
Expand All @@ -50,7 +64,31 @@ let package = Package(
targets: [
"Perplexity"
]
)
),
.library(
name: "PlayHT",
targets: [
"PlayHT"
]
),
.library(
name: "Rime",
targets: [
"Rime"
]
),
.library(
name: "TogetherAI",
targets: [
"TogetherAI"
]
),
.library(
name: "VoyageAI",
targets: [
"VoyageAI"
]
),
],
dependencies: [
.package(url: "https://github.com/vmanot/CorePersistence.git", branch: "main"),
Expand Down Expand Up @@ -340,30 +378,33 @@ let package = Package(
dependencies: [
"CoreMI",
"LargeLanguageModels",
"_Gemini",
"Anthropic",
"Cohere",
"ElevenLabs",
"Groq",
"HuggingFace",
"HumeAI",
"Jina",
"NeetsAI",
"Mistral",
"Ollama",
"OpenAI",
"Perplexity",
"PlayHT",
"Rime",
"Swallow",
"TogetherAI",
"VoyageAI",
],
path: "Sources/AI",
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
]
),
.testTarget(
name: "_GeminiTests",
dependencies: [
"AI",
"Swallow"
],
path: "Tests/_Gemini",
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
]
),
.testTarget(
name: "LargeLanguageModelsTests",
dependencies: [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Swallow

extension AbstractLLM {
public protocol Completion: Codable, CustomDebugStringConvertible, Hashable, Sendable {
static var _completionType: AbstractLLM.CompletionType? { get }
static var knownCompletionType: AbstractLLM.CompletionType? { get }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ extension AbstractLLM {
associatedtype CompletionParameters: AbstractLLM.CompletionParameters
associatedtype Completion: Partializable

static var completionType: AbstractLLM.CompletionType? { get }
static var knownCompletionType: AbstractLLM.CompletionType? { get }

var context: PromptContextValues { get set }
}
}

extension AbstractLLM {
public enum ChatOrTextPrompt: Prompt {
public typealias CompletionParameters = AbstractLLM.ChatOrTextCompletionParameters
public typealias CompletionParameters = ChatOrTextCompletionParameters
public typealias Completion = AbstractLLM.ChatOrTextCompletion

public static var completionType: AbstractLLM.CompletionType? {
public static var knownCompletionType: AbstractLLM.CompletionType? {
nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Swallow

extension AbstractLLM {
public struct ChatCompletion: Completion {
public static var _completionType: AbstractLLM.CompletionType? {
public static var knownCompletionType: AbstractLLM.CompletionType? {
.chat
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension AbstractLLM {
public typealias CompletionParameters = AbstractLLM.ChatCompletionParameters
public typealias Completion = AbstractLLM.ChatCompletion

public static var completionType: AbstractLLM.CompletionType? {
public static var knownCompletionType: AbstractLLM.CompletionType? {
.chat
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Diagnostics
import Foundation
import Swallow
import CreateMLComponents

public protocol __AbstractLLM_ChatRole_Initiable {
init(from role: AbstractLLM.ChatRole) throws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Swallow

extension AbstractLLM {
public struct TextCompletion: Completion {
public static var _completionType: AbstractLLM.CompletionType? {
public static var knownCompletionType: AbstractLLM.CompletionType? {
.text
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension AbstractLLM {
public typealias CompletionParameters = AbstractLLM.TextCompletionParameters
public typealias Completion = AbstractLLM.TextCompletion

public static var completionType: AbstractLLM.CompletionType? {
public static var knownCompletionType: AbstractLLM.CompletionType? {
.text
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,49 @@ import LargeLanguageModels
import Swallow

extension OpenAI {
public struct ToolName: Codable, Hashable, RawRepresentable, Sendable {
public let rawValue: String

public init(rawValue: String) {
self.rawValue = rawValue
}

public init(from decoder: any Decoder) throws {
rawValue = try String(from: decoder)
}

public func encode(to encoder: any Encoder) throws {
try rawValue.encode(to: encoder)
}
}

public struct ChatFunctionDefinition: Codable, Hashable, Sendable {
public let name: String
public let name: OpenAI.ToolName
public let description: String
public let parameters: JSONSchema

public init(
name: String,
name: OpenAI.ToolName,
description: String,
parameters: JSONSchema
) {
self.name = name
self.description = description
self.parameters = parameters
}

public init(
name: String,
description: String,
parameters: JSONSchema
) {
self.init(
name: OpenAI.ToolName(
rawValue: name
),
description: description,
parameters: parameters
)
}
}
}
19 changes: 10 additions & 9 deletions Sources/OpenAI/Intramodular/Models/OpenAI.ToolChoice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NetworkKit
import Swift

extension OpenAI {
/// https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-tool_choice
public enum ToolChoice: Codable {
case none
case auto
Expand All @@ -20,15 +21,7 @@ extension OpenAI {
}

public enum ToolValue: Codable {
case function(String)

public struct FunctionDetails: Codable {
var name: String

public init(name: String) {
self.name = name
}
}
case function(ToolName)
}
}
}
Expand Down Expand Up @@ -83,6 +76,14 @@ extension OpenAI.ToolChoice.ToolValue {
case function
}

private struct FunctionDetails: Codable {
var name: OpenAI.ToolName

public init(name: OpenAI.ToolName) {
self.name = name
}
}

public init(
from decoder: Decoder
) throws {
Expand Down
Loading

0 comments on commit bfe29a1

Please sign in to comment.