Skip to content

Commit 6eef413

Browse files
committed
Remove the current implementation of the new plugins
1 parent 32c388a commit 6eef413

File tree

4 files changed

+71
-163
lines changed

4 files changed

+71
-163
lines changed

Core/Sources/ChatPlugins/MathChatPlugin/SolveMathProblem.swift

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@ import PythonHelper
44
import PythonKit
55

66
func solveMathProblem(_ problem: String) async throws -> String {
7-
#if DEBUG
8-
let verbose = true
9-
#else
10-
let verbose = false
11-
#endif
12-
13-
struct E: Error, LocalizedError {
14-
var errorDescription: String? {
15-
"Failed to parse answer."
16-
}
17-
}
18-
19-
let task = Task {
20-
try runPython {
21-
let langchain = try Python.attemptImportOnPythonThread("langchain")
22-
let LLMMathChain = langchain.LLMMathChain
23-
let llm = try LangChainChatModel.DynamicChatOpenAI(temperature: 0)
24-
let llmMath = LLMMathChain.from_llm(llm, verbose: verbose)
25-
let result = try llmMath.run.throwing.dynamicallyCall(withArguments: problem)
26-
let answer = String(result)
27-
if let answer { return answer }
28-
29-
throw E()
30-
}
31-
}
32-
33-
return try await task.value
7+
// #if DEBUG
8+
// let verbose = true
9+
// #else
10+
// let verbose = false
11+
// #endif
12+
//
13+
// struct E: Error, LocalizedError {
14+
// var errorDescription: String? {
15+
// "Failed to parse answer."
16+
// }
17+
// }
18+
//
19+
// let task = Task {
20+
// try runPython {
21+
// let langchain = try Python.attemptImportOnPythonThread("langchain")
22+
// let LLMMathChain = langchain.LLMMathChain
23+
// let llm = try LangChainChatModel.DynamicChatOpenAI(temperature: 0)
24+
// let llmMath = LLMMathChain.from_llm(llm, verbose: verbose)
25+
// let result = try llmMath.run.throwing.dynamicallyCall(withArguments: problem)
26+
// let answer = String(result)
27+
// if let answer { return answer }
28+
//
29+
// throw E()
30+
// }
31+
// }
32+
//
33+
// return try await task.value
34+
return "N/A"
3435
}
3536

Core/Sources/ChatPlugins/SearchChatPlugin/SearchAgent.swift

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,6 @@ import PythonHelper
44
import PythonKit
55

66
func search(_ query: String) async throws -> String {
7-
#if DEBUG
8-
let verbose = true
9-
#else
10-
let verbose = false
11-
#endif
12-
13-
let task = Task {
14-
try runPython {
15-
let llm = try LangChainChatModel.DynamicChatOpenAI(temperature: 0)
16-
let utilities = try Python.attemptImportOnPythonThread("langchain.utilities")
17-
let BingSearchAPIWrapper = utilities.BingSearchAPIWrapper
18-
let agents = try Python.attemptImportOnPythonThread("langchain.agents")
19-
let Tool = agents.Tool
20-
let initializeAgent = agents.initialize_agent
21-
let AgentType = agents.AgentType
22-
23-
let bingSearch = BingSearchAPIWrapper(
24-
bing_subscription_key: "f1eaef707e9443ddb08df2cfb6ac1eb5",
25-
bing_search_url: "https://api.bing.microsoft.com/v7.0/search/",
26-
k: 5
27-
)
28-
29-
var links = [String]()
30-
31-
let getSearchResult = PythonInstanceMethod { arguments -> String in
32-
guard let query = arguments.first else { return "Empty" }
33-
let results = bingSearch.results(query, 5)
34-
let resultString = results.enumerated().map { "[\($0)]:###\($1["snippet"])###" }
35-
.joined(separator: "\n")
36-
links = results.map {
37-
let url = String($0["link"]) ?? "N/A"
38-
let title = String($0["title"]) ?? "Unknown Title"
39-
return "[\(title)](\(url))"
40-
}
41-
return resultString
42-
}
43-
44-
let ff = PythonClass("FF", members: [
45-
"run": PythonInstanceMethod { arguments -> String in
46-
guard let query = arguments.first else { return "Empty" }
47-
let results = bingSearch.results(query, 5)
48-
let resultString = results.enumerated().map { "[\($0)]:###\($1["snippet"])###" }
49-
.joined(separator: "\n")
50-
links = results.map {
51-
let url = String($0["link"]) ?? "N/A"
52-
let title = String($0["title"]) ?? "Unknown Title"
53-
return "[\(title)](\(url))"
54-
}
55-
return resultString
56-
}
57-
])
58-
59-
let fi = ff.pythonObject()
60-
61-
print(fi.run)
62-
print(getSearchResult.pythonObject)
63-
64-
let tools = [
65-
Tool(
66-
name: "Search",
67-
func: fi.run,
68-
description: "useful for when you need to answer questions about current events. You should ask targeted questions"
69-
),
70-
]
71-
72-
let chain = initializeAgent(
73-
tools, llm,
74-
agent: AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
75-
verbose: verbose,
76-
max_iterations: 1,
77-
early_stopping_method: "generate",
78-
agent_kwargs: ["system_message_prefix": "Respond to the human as helpfully and accurately as possible. Wrap any code block in thought in <code></code>. Format final answer to be more readable, in a ordered list if possible. You have access to the following tools:"]
79-
)
80-
81-
let trimmedQuery = query.trimmingCharacters(in: [" ", "\n"])
82-
do {
83-
let result = try chain.run.throwing.dynamicallyCall(withArguments: trimmedQuery)
84-
return (String(result) ?? "", links)
85-
} catch {
86-
return (error.localizedDescription, links)
87-
}
88-
}
89-
}
90-
91-
let (answer, links) = try await task.value
92-
93-
return """
94-
\(answer)
95-
------
96-
\(links.map { "- \($0)" }.joined(separator: "\n"))
97-
"""
7+
return ""
988
}
999

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import Foundation
2-
import Preferences
3-
import PythonHelper
4-
import PythonKit
5-
6-
public enum LangChainChatModel {
7-
/// Dynamically create a ChatOpenAI object based on the user's preferences.
8-
public static func DynamicChatOpenAI(
9-
temperature: Double
10-
) throws -> PythonObject {
11-
switch UserDefaults.shared.value(for: \.chatFeatureProvider) {
12-
case .openAI:
13-
let model = UserDefaults.shared.value(for: \.chatGPTModel)
14-
let apiBaseURL = UserDefaults.shared.value(for: \.openAIBaseURL)
15-
let apiKey = UserDefaults.shared.value(for: \.openAIAPIKey)
16-
let chatModels = try Python.attemptImportOnPythonThread("langchain.chat_models")
17-
let ChatOpenAI = chatModels.ChatOpenAI
18-
return ChatOpenAI(
19-
temperature: temperature,
20-
model: model,
21-
openai_api_base: "\(apiBaseURL)/v1",
22-
openai_api_key: apiKey
23-
)
24-
case .azureOpenAI:
25-
let apiBaseURL = UserDefaults.shared.value(for: \.azureOpenAIBaseURL)
26-
let apiKey = UserDefaults.shared.value(for: \.azureOpenAIAPIKey)
27-
let deployment = UserDefaults.shared.value(for: \.azureChatGPTDeployment)
28-
let chatModels = try Python.attemptImportOnPythonThread("langchain.chat_models")
29-
let ChatOpenAI = chatModels.AzureChatOpenAI
30-
return ChatOpenAI(
31-
temperature: temperature,
32-
openai_api_type: "azure",
33-
openai_api_version: "2023-03-15-preview",
34-
deployment_name: deployment,
35-
openai_api_base: apiBaseURL,
36-
openai_api_key: apiKey
37-
)
38-
}
39-
}
40-
}
1+
//import Foundation
2+
//import Preferences
3+
//import PythonHelper
4+
//import PythonKit
5+
//
6+
//public enum LangChainChatModel {
7+
// /// Dynamically create a ChatOpenAI object based on the user's preferences.
8+
// public static func DynamicChatOpenAI(
9+
// temperature: Double
10+
// ) throws -> PythonObject {
11+
// switch UserDefaults.shared.value(for: \.chatFeatureProvider) {
12+
// case .openAI:
13+
// let model = UserDefaults.shared.value(for: \.chatGPTModel)
14+
// let apiBaseURL = UserDefaults.shared.value(for: \.openAIBaseURL)
15+
// let apiKey = UserDefaults.shared.value(for: \.openAIAPIKey)
16+
// let chatModels = try Python.attemptImportOnPythonThread("langchain.chat_models")
17+
// let ChatOpenAI = chatModels.ChatOpenAI
18+
// return ChatOpenAI(
19+
// temperature: temperature,
20+
// model: model,
21+
// openai_api_base: "\(apiBaseURL)/v1",
22+
// openai_api_key: apiKey
23+
// )
24+
// case .azureOpenAI:
25+
// let apiBaseURL = UserDefaults.shared.value(for: \.azureOpenAIBaseURL)
26+
// let apiKey = UserDefaults.shared.value(for: \.azureOpenAIAPIKey)
27+
// let deployment = UserDefaults.shared.value(for: \.azureChatGPTDeployment)
28+
// let chatModels = try Python.attemptImportOnPythonThread("langchain.chat_models")
29+
// let ChatOpenAI = chatModels.AzureChatOpenAI
30+
// return ChatOpenAI(
31+
// temperature: temperature,
32+
// openai_api_type: "azure",
33+
// openai_api_version: "2023-03-15-preview",
34+
// deployment_name: deployment,
35+
// openai_api_base: apiBaseURL,
36+
// openai_api_key: apiKey
37+
// )
38+
// }
39+
// }
40+
//}
4141

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import XCTest
2-
@testable import Tool
2+
@testable import LangChain
33

44
final class ToolTests: XCTestCase {
55
func testExample() throws {
6-
// This is an example of a functional test case.
7-
// Use XCTAssert and related functions to verify your tests produce the correct
8-
// results.
9-
XCTAssertEqual(Tool().text, "Hello, World!")
6+
107
}
118
}

0 commit comments

Comments
 (0)