Skip to content

Commit de74bfb

Browse files
committed
Fix FunctionCallingAgentTool
1 parent 74df8f7 commit de74bfb

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

Tool/Sources/LangChain/AgentTool.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,13 @@ public struct SimpleAgentTool: AgentTool {
3131
}
3232
}
3333

34-
public class FunctionCallingAgentTool<F: ChatGPTFunction>: AgentTool {
34+
public class FunctionCallingAgentTool<F: ChatGPTFunction>: AgentTool, ChatGPTFunction {
3535
public func call(arguments: F.Arguments) async throws -> F.Result {
3636
try await function.call(arguments: arguments, reportProgress: reportProgress)
3737
}
3838

3939
public var argumentSchema: OpenAIService.JSONSchemaValue { function.argumentSchema }
4040

41-
public func prepare() async {
42-
await function.prepare(reportProgress: { [weak self] p in
43-
self?.reportProgress(p)
44-
})
45-
}
46-
4741
public typealias Arguments = F.Arguments
4842
public typealias Result = F.Result
4943

@@ -76,13 +70,29 @@ public class FunctionCallingAgentTool<F: ChatGPTFunction>: AgentTool {
7670
}
7771

7872
public func run(input: String) async throws -> String {
79-
try await function.call(
73+
await prepare(reportProgress: { [weak self] p in
74+
self?.reportProgress(p)
75+
})
76+
return try await call(
8077
argumentsJsonString: input,
8178
reportProgress: { [weak self] p in
8279
self?.reportProgress(p)
8380
}
8481
)
8582
.botReadableContent
8683
}
84+
85+
public func prepare(reportProgress: @escaping ReportProgress) async {
86+
await function.prepare(reportProgress: { [weak self] p in
87+
self?.reportProgress(p)
88+
})
89+
}
90+
91+
public func call(
92+
arguments: F.Arguments,
93+
reportProgress: @escaping ReportProgress
94+
) async throws -> F.Result {
95+
try await function.call(arguments: arguments, reportProgress: reportProgress)
96+
}
8797
}
8898

0 commit comments

Comments
 (0)