luogu 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -0
- data/lib/luogu/chatgpt.rb +17 -7
- data/lib/luogu/init.rb +1 -0
- data/lib/luogu/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6f8d477025b929343fbd70605905c557d33550d3f0f3921d256b295f993a96
|
4
|
+
data.tar.gz: 49aaf6803e6a8428bf143a743dd07ad840ddd0655a3228fad59543842af65466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de98f0d6be3266c9b4d873fb0e97bd1cf94f63231411961af39671a1be9b4ce0040d3efd1476fe37a309bee3722e1a7e724fdbd37a0dc949e4982fb8e8425d4
|
7
|
+
data.tar.gz: 0cc7c4f3f9fa709c7fd1c7ca1a3b10ede905e5be36b90701edd0f100b404e64144deb20de6f081d3f6b89c757932f2932651fb0b6c6f60ec938419dfde2d5855
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -61,4 +61,10 @@ end
|
|
61
61
|
- history 查看当前上下文
|
62
62
|
- exit 退出
|
63
63
|
|
64
|
+
## 插件模式
|
65
|
+
OpenStruct.new(request_params: params)
|
66
|
+
OpenStruct.new(user_input: user_message)
|
67
|
+
OpenStruct.new(request_messages: messages)
|
68
|
+
OpenStruct.new(user_input: user_message, response_message: assistant_message)
|
69
|
+
|
64
70
|
## MIT 协议
|
data/lib/luogu/chatgpt.rb
CHANGED
@@ -23,7 +23,9 @@ module Luogu
|
|
23
23
|
@row_history = []
|
24
24
|
@history = HistoryQueue.new @limit_history
|
25
25
|
|
26
|
-
|
26
|
+
if @plugin.setup_proc
|
27
|
+
@plugin.setup_proc.call(self, OpenStruct.new)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
31
|
def request(messages)
|
@@ -33,17 +35,23 @@ module Luogu
|
|
33
35
|
temperature: @temperature,
|
34
36
|
}
|
35
37
|
|
36
|
-
|
38
|
+
if @plugin.before_request_proc
|
39
|
+
params = @plugin.before_request_proc.call(self, OpenStruct.new(request_params: params)).request_params
|
40
|
+
end
|
37
41
|
response = client.chat(parameters: params)
|
38
|
-
@plugin.after_request_proc.call(self, response) if @plugin.after_request_proc
|
42
|
+
@plugin.after_request_proc.call(self, OpenStruct.new(response: response)) if @plugin.after_request_proc
|
39
43
|
|
40
44
|
response.dig("choices", 0, "message", "content")
|
41
45
|
end
|
42
46
|
|
43
47
|
def chat(user_message)
|
44
|
-
|
48
|
+
if @plugin.before_input_proc
|
49
|
+
user_message = @plugin.before_input_proc.call(self, OpenStruct.new(user_input: user_message)).user_input
|
50
|
+
end
|
45
51
|
messages = (@prompt.render + @history.to_a) << {role: "user", content: user_message}
|
46
|
-
|
52
|
+
if @plugin.after_input_proc
|
53
|
+
messages = @plugin.after_input_proc.call(self, OpenStruct.new(request_messages: messages)).request_messages
|
54
|
+
end
|
47
55
|
|
48
56
|
assistant_message = self.request(messages)
|
49
57
|
|
@@ -53,7 +61,7 @@ module Luogu
|
|
53
61
|
puts "执行文档中的callback"
|
54
62
|
instance_eval @prompt.ruby_code, @prompt.file_path, @prompt.ruby_code_line
|
55
63
|
elsif @plugin.before_save_history_proc
|
56
|
-
@plugin.before_save_history_proc.call(self, user_message, assistant_message)
|
64
|
+
@plugin.before_save_history_proc.call(self, OpenStruct.new(user_input: user_message, response_message: assistant_message))
|
57
65
|
else
|
58
66
|
puts "执行默认的历史记录"
|
59
67
|
self.push_history(user_message, assistant_message)
|
@@ -70,7 +78,9 @@ module Luogu
|
|
70
78
|
def push_history(user_message, assistant_message)
|
71
79
|
@history.enqueue({role: "user", content: user_message})
|
72
80
|
@history.enqueue({role: "assistant", content: assistant_message})
|
73
|
-
|
81
|
+
if @plugin.after_save_history_proc
|
82
|
+
@plugin.after_save_history_proc.call(self, OpenStruct.new(user_input: user_message, response_message: assistant_message))
|
83
|
+
end
|
74
84
|
end
|
75
85
|
|
76
86
|
def ask(message)
|
data/lib/luogu/init.rb
CHANGED
data/lib/luogu/version.rb
CHANGED