Skip to content

Commit ed182b7

Browse files
committed
Support exit plugin
1 parent a3d890a commit ed182b7

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

Core/Sources/ChatService/ChatService.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,30 @@ public final class ChatService: ObservableObject {
2727
let matches = regex.matches(in: content, range: NSRange(content.startIndex..., in: content))
2828
if let match = matches.first {
2929
let command = String(content[Range(match.range(at: 1), in: content)!])
30-
if let pluginType = plugins[command] {
30+
if command == "/exit" {
31+
if let plugin = runningPlugin {
32+
_ = await chatGPTService.mutateHistory { history in
33+
history.append(.init(
34+
role: .user,
35+
content: "",
36+
summary: "Exit plugin \(plugin.name)."
37+
))
38+
history.append(.init(
39+
role: .system,
40+
content: "",
41+
summary: "Exited plugin \(plugin.name)."
42+
))
43+
}
44+
} else {
45+
_ = await chatGPTService.mutateHistory { history in
46+
history.append(.init(
47+
role: .system,
48+
content: "",
49+
summary: "No plugin running."
50+
))
51+
}
52+
}
53+
} else if let pluginType = plugins[command] {
3154
let plugin = pluginType.init(inside: chatGPTService, delegate: self)
3255
await plugin.send(content: String(content.dropFirst(command.count + 1)))
3356
}

0 commit comments

Comments
 (0)