Skip to content

Commit 2d92790

Browse files
committed
Update OpenAIChat to support memory and functionProvider
1 parent e011246 commit 2d92790

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Tool/Sources/LangChain/ChatModel/OpenAIChat.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import OpenAIService
33

44
public struct OpenAIChat: ChatModel {
55
public var configuration: ChatGPTConfiguration
6+
public var memory: ChatGPTMemory
7+
public var functionProvider: ChatGPTFunctionProvider
68
public var stream: Bool
79

810
public init(
9-
configuration: ChatGPTConfiguration,
11+
configuration: ChatGPTConfiguration = UserPreferenceChatGPTConfiguration(),
12+
memory: ChatGPTMemory = ConversationChatGPTMemory(systemPrompt: ""),
13+
functionProvider: ChatGPTFunctionProvider = NoChatGPTFunctionProvider(),
1014
stream: Bool
1115
) {
1216
self.configuration = configuration
17+
self.memory = memory
18+
self.functionProvider = functionProvider
1319
self.stream = stream
1420
}
1521

@@ -18,12 +24,11 @@ public struct OpenAIChat: ChatModel {
1824
stops: [String],
1925
callbackManagers: [CallbackManager]
2026
) async throws -> String {
21-
let memory = AutoManagedChatGPTMemory(
22-
systemPrompt: "",
27+
let service = ChatGPTService(
28+
memory: memory,
2329
configuration: configuration,
24-
functionProvider: NoChatGPTFunctionProvider()
30+
functionProvider: functionProvider
2531
)
26-
let service = ChatGPTService(memory: memory, configuration: configuration)
2732
for message in prompt {
2833
let role: OpenAIService.ChatMessage.Role = {
2934
switch message.role {

0 commit comments

Comments
 (0)