Skip to content

Commit a08cca8

Browse files
committed
Support no memory for OpenAIChat
1 parent eb71146 commit a08cca8

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

Tool/Sources/LangChain/Agents/FunctionCallingChatAgent.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class FunctionCallingChatAgent<Output: AgentOutputParsable & Decodable>:
7676

7777
public init(
7878
configuration: ChatGPTConfiguration = UserPreferenceChatGPTConfiguration(),
79-
memory: ChatGPTMemory = ConversationChatGPTMemory(systemPrompt: ""),
8079
tools: [AgentTool] = [],
8180
endFunction: EndFunction
8281
) {
@@ -92,7 +91,7 @@ public class FunctionCallingChatAgent<Output: AgentOutputParsable & Decodable>:
9291
configuration: configuration.overriding {
9392
$0.runFunctionsAutomatically = false
9493
},
95-
memory: memory,
94+
memory: nil,
9695
functionProvider: functionProvider,
9796
stream: false
9897
),
@@ -158,7 +157,7 @@ public class FunctionCallingChatAgent<Output: AgentOutputParsable & Decodable>:
158157
}
159158

160159
public func parseOutput(_ message: ChatMessage) async -> AgentNextStep<Output> {
161-
if message.role == .function, let functionCall = message.functionCall {
160+
if message.role == .assistant, let functionCall = message.functionCall {
162161
if let function = functionProvider.functionTools.first(where: {
163162
$0.name == functionCall.name
164163
}) {

Tool/Sources/LangChain/ChatModel/OpenAIChat.swift

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

44
public struct OpenAIChat: ChatModel {
55
public var configuration: ChatGPTConfiguration
6-
public var memory: ChatGPTMemory
6+
public var memory: ChatGPTMemory?
77
public var functionProvider: ChatGPTFunctionProvider
88
public var stream: Bool
99

1010
public init(
1111
configuration: ChatGPTConfiguration = UserPreferenceChatGPTConfiguration(),
12-
memory: ChatGPTMemory = ConversationChatGPTMemory(systemPrompt: ""),
12+
memory: ChatGPTMemory? = ConversationChatGPTMemory(systemPrompt: ""),
1313
functionProvider: ChatGPTFunctionProvider = NoChatGPTFunctionProvider(),
1414
stream: Bool
1515
) {
@@ -24,6 +24,8 @@ public struct OpenAIChat: ChatModel {
2424
stops: [String],
2525
callbackManagers: [CallbackManager]
2626
) async throws -> ChatMessage {
27+
let memory = memory ?? EmptyChatGPTMemory()
28+
2729
let service = ChatGPTService(
2830
memory: memory,
2931
configuration: configuration,

0 commit comments

Comments
 (0)