forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLLMChain.swift
More file actions
37 lines (31 loc) · 909 Bytes
/
LLMChain.swift
File metadata and controls
37 lines (31 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Foundation
public class ChatModelChain<Input>: Chain {
public typealias Output = String
var chatModel: ChatModel
var promptTemplate: (Input) -> [ChatMessage]
var stops: [String]
public init(
chatModel: ChatModel,
stops: [String] = [],
promptTemplate: @escaping (Input) -> [ChatMessage]
) {
self.chatModel = chatModel
self.promptTemplate = promptTemplate
self.stops = stops
}
public func callLogic(
_ input: Input,
callbackManagers: [ChainCallbackManager]
) async throws -> Output {
let prompt = promptTemplate(input)
let output = try await chatModel.generate(
prompt: prompt,
stops: stops,
callbackManagers: callbackManagers
)
return output
}
public func parseOutput(_ output: Output) -> String {
output
}
}