Skip to content

Commit

Permalink
Update package
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanot committed Mar 29, 2024
1 parent 96011e0 commit 1a01ea5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ extension AbstractLLM {
public struct FunctionCall: Codable, CustomDebugStringConvertible, Hashable, Sendable {
public let name: String
public let arguments: String

public var context: PromptContextValues

public var debugDescription: String {
"<function call: \(name)>"
}

public init(name: String, arguments: String) {
public init(
name: String,
arguments: String,
context: PromptContextValues
) {
self.name = name
self.arguments = arguments
self.context = context
}
}

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

extension PromptLiteral.StringInterpolation.Component {
public enum Payload: HashEquatable, @unchecked Sendable {
public enum Payload: _CasePathExtracting, HashEquatable, @unchecked Sendable {
case stringLiteral(String)
case image(Image)
case localizedStringResource(LocalizedStringResource)
Expand Down Expand Up @@ -44,7 +44,24 @@ extension PromptLiteral.StringInterpolation.Component.Payload {
}
}
}

public var functionCall: AbstractLLM.ChatPrompt.FunctionCall? {
get {
self[casePath: /Self.other]?[casePath: /Other.functionCall]
} set {
self = try! .other(.functionCall(newValue.unwrap()))
}
}

public var functionInvocation: AbstractLLM.ChatPrompt.FunctionInvocation? {
get {
self[casePath: /Self.other]?[casePath: /Other.functionInvocation]
} set {
self = try! .other(.functionInvocation(newValue.unwrap()))
}
}
}

// MARK: - Conformances

extension PromptLiteral.StringInterpolation.Component.Payload: Codable {
Expand Down Expand Up @@ -163,7 +180,7 @@ extension PromptLiteral.StringInterpolation.Component.Payload {
case url(URL)
}

public enum Other: Hashable, Sendable {
public enum Other: _CasePathExtracting, Hashable, Sendable {
case functionCall(AbstractLLM.ChatPrompt.FunctionCall)
case functionInvocation(AbstractLLM.ChatPrompt.FunctionInvocation)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension OpenAI.APIClient: _TaskDependenciesExporting {

extension OpenAI.APIClient: LLMRequestHandling {
private var _debugPrintCompletions: Bool {
true
false
}

public var _availableModels: [_MLModelIdentifier]? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ extension AbstractLLM.ChatMessage {
id: AnyPersistentIdentifier(erasing: id),
role: role,
content: try PromptLiteral(
functionCall: .init(name: call.name, arguments: call.arguments),
functionCall: .init(
name: call.name,
arguments: call.arguments,
context: .init()
),
role: .chat(role)
)
)
Expand Down

0 comments on commit 1a01ea5

Please sign in to comment.