Skip to content

Commit

Permalink
Merge pull request #112 from bsorrentino/feature/integrate_langgraph
Browse files Browse the repository at this point in the history
fix: allow third-party module to use langchain agent
  • Loading branch information
buhe authored Mar 17, 2024
2 parents 2a82fc7 + f59f8f0 commit 202b774
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
38 changes: 21 additions & 17 deletions Sources/LangChain/callbacks/BaseCallbackHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,79 @@
//

import Foundation
public class BaseCallbackHandler: LLMManagerMixin, ChainManagerMixin, CallbackManagerMixin, ToolManagerMixin, LoaderManagerMixin {
open class BaseCallbackHandler: LLMManagerMixin, ChainManagerMixin, CallbackManagerMixin, ToolManagerMixin, LoaderManagerMixin {

public init() {

}
// Loader
public func on_loader_start(type: String, metadata: [String : String]) throws {
open func on_loader_start(type: String, metadata: [String : String]) throws {

}

public func on_loader_error(type: String, cause: String, metadata: [String : String]) throws {
open func on_loader_error(type: String, cause: String, metadata: [String : String]) throws {

}

public func on_loader_end(type: String, metadata: [String : String]) throws {
open func on_loader_end(type: String, metadata: [String : String]) throws {

}

// Agent
public func on_agent_start(prompt: String, metadata: [String : String]) throws {
open func on_agent_start(prompt: String, metadata: [String : String]) throws {

}

public func on_llm_error(error: Error, metadata: [String: String]) throws {
open func on_llm_error(error: Error, metadata: [String: String]) throws {

}

public func on_llm_start(prompt: String, metadata: [String: String]) throws {
open func on_llm_start(prompt: String, metadata: [String: String]) throws {

}

// Manage callback
public func on_chain_start(prompts: String, metadata: [String: String]) throws {
open func on_chain_start(prompts: String, metadata: [String: String]) throws {

}

public func on_tool_start(tool: BaseTool, input: String, metadata: [String: String]) throws {
open func on_tool_start(tool: BaseTool, input: String, metadata: [String: String]) throws {

}

// Chain callback
public func on_chain_end(output: String, metadata: [String: String]) throws {
open func on_chain_end(output: String, metadata: [String: String]) throws {

}

public func on_chain_error(error: Error, metadata: [String: String]) throws {
open func on_chain_error(error: Error, metadata: [String: String]) throws {

}

public func on_agent_action(action: AgentAction, metadata: [String: String]) throws {
open func on_agent_action(action: AgentAction, metadata: [String: String]) throws {

}

public func on_agent_finish(action: AgentFinish, metadata: [String: String]) throws {
open func on_agent_finish(action: AgentFinish, metadata: [String: String]) throws {

}


// LLM callback
public func on_llm_new_token(metadata: [String: String]) {
open func on_llm_new_token(metadata: [String: String]) {

}

public func on_llm_end(output: String, metadata: [String: String]) throws {
open func on_llm_end(output: String, metadata: [String: String]) throws {

}

// Tool callback
public func on_tool_end(tool: BaseTool, output: String, metadata: [String: String]) throws {
open func on_tool_end(tool: BaseTool, output: String, metadata: [String: String]) throws {

}

public func on_tool_error(error: Error, metadata: [String: String]) throws {
open func on_tool_error(error: Error, metadata: [String: String]) throws {

}
}
Expand Down
16 changes: 12 additions & 4 deletions Sources/LangChain/parser/BaseOutputParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ import Foundation
import SwiftyJSON

public struct AgentAction{
let action: String
let input: String
let log: String
public let action: String
public let input: String
public let log: String
public init(action: String, input: String, log: String) {
self.action = action
self.input = input
self.log = log
}
}
public struct AgentFinish {
let final: String
public let final: String
public init(final: String) {
self.final = final
}
}

public enum Parsed {
Expand Down
2 changes: 1 addition & 1 deletion Sources/LangChain/tools/InvalidTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
public class InvalidTool: BaseTool {
let tool_name: String

init(tool_name: String) {
public init(tool_name: String) {
self.tool_name = tool_name
}

Expand Down

0 comments on commit 202b774

Please sign in to comment.