Skip to content

Commit 6974682

Browse files
committed
Update ChatModel to return ChatMessage
1 parent da55011 commit 6974682

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Tool/Sources/LangChain/Agent.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public extension Agent {
104104
) async throws -> AgentNextStep {
105105
let input = getFullInputs(input: input, intermediateSteps: intermediateSteps)
106106
let output = try await chatModelChain.call(input, callbackManagers: callbackManagers)
107-
return parseOutput(output)
107+
return parseOutput(output.content ?? "")
108108
}
109109

110110
func returnStoppedResponse(
@@ -128,12 +128,13 @@ public extension Agent {
128128
"""
129129
let input = AgentInput(input: input, thoughts: .text(thoughts))
130130
let output = try await chatModelChain.call(input, callbackManagers: callbackManagers)
131-
let nextAction = parseOutput(output)
131+
let reply = output.content ?? ""
132+
let nextAction = parseOutput(reply)
132133
switch nextAction {
133134
case let .finish(finish):
134135
return finish
135136
case .actions:
136-
return AgentFinish(returnValue: output, log: output)
137+
return AgentFinish(returnValue: reply, log: reply)
137138
}
138139
}
139140
}

Tool/Sources/LangChain/Chains/RetrievalQA.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,17 @@ public final class RefineDocumentChain: Chain {
183183
output = try await refinementChatModel.call(
184184
.init(
185185
question: input.question,
186-
previousAnswer: output,
186+
previousAnswer: content,
187187
document: document.document.pageContent,
188188
distance: document.distance
189189
),
190190
callbackManagers: callbackManagers
191191
)
192+
content = output.content ?? ""
192193
callbackManagers
193-
.send(CallbackEvents.RetrievalQADidGenerateIntermediateAnswer(info: output))
194+
.send(CallbackEvents.RetrievalQADidGenerateIntermediateAnswer(info: content))
194195
}
195-
return output
196+
return content
196197
}
197198

198199
public func parseOutput(_ output: String) -> String {

0 commit comments

Comments
 (0)