Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow third-party module to use langchain agent #112

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading