luogu 0.1.0 → 0.1.2
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/lib/luogu/chatgpt.rb +19 -17
- data/lib/luogu/cli.rb +6 -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: 584995338f86e7c2be1f099920457c424396373ec007e6fa7185face0a0254e9
|
4
|
+
data.tar.gz: 7414294ca9278bc20989b2fb5e58bd5c3b6602a35853ae8f56a4b35423b1974b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca7945d9ef6ddc5ba18ff6e258f18bf8799049d580b7befbe50b1db43297322171b68852f8783643b16f829c7a7b99faf5fceec6d87c64a20232fd9e7ce04087
|
7
|
+
data.tar.gz: 2982f3f04cb4edec38434db75933921b7574f8b885d8a8265514071724f0ca72eb2bd681377773c97edf5be9ee48a358f729f5a12f507fc753527f1f594300ea
|
data/Gemfile.lock
CHANGED
data/lib/luogu/chatgpt.rb
CHANGED
@@ -62,21 +62,6 @@ module Luogu
|
|
62
62
|
@_puts_method.call message
|
63
63
|
end
|
64
64
|
|
65
|
-
def save(history, file_path)
|
66
|
-
text = ""
|
67
|
-
role_map = {"user" => "@u", "assistant" => "@a", "system" => "@s"}
|
68
|
-
history.each do |item|
|
69
|
-
text += role_map[item[:role]]
|
70
|
-
text += "\n"
|
71
|
-
text += item[:content]
|
72
|
-
text += "\n\n"
|
73
|
-
end
|
74
|
-
File.open(file_path, 'w') do |f|
|
75
|
-
f.write(text)
|
76
|
-
end
|
77
|
-
puts "已经保存文件到 #{file_path}"
|
78
|
-
end
|
79
|
-
|
80
65
|
def run
|
81
66
|
loop do
|
82
67
|
# 从命令行读取输入
|
@@ -85,8 +70,8 @@ module Luogu
|
|
85
70
|
# 根据用户输入执行相应的操作
|
86
71
|
case input
|
87
72
|
when "save"
|
88
|
-
self.save @row_history, "./prompt.row_history.md"
|
89
|
-
self.save @history.to_a, "./prompt.history.md"
|
73
|
+
self.class.save @row_history, "./prompt.row_history.md"
|
74
|
+
self.class.save @history.to_a, "./prompt.history.md"
|
90
75
|
when "row history"
|
91
76
|
p @row_history
|
92
77
|
when "history"
|
@@ -99,5 +84,22 @@ module Luogu
|
|
99
84
|
end
|
100
85
|
end
|
101
86
|
end
|
87
|
+
|
88
|
+
class << self
|
89
|
+
def save(history, file_path)
|
90
|
+
text = ""
|
91
|
+
role_map = {"user" => "@u", "assistant" => "@a", "system" => "@s"}
|
92
|
+
history.each do |item|
|
93
|
+
text += role_map[item[:role]]
|
94
|
+
text += "\n"
|
95
|
+
text += item[:content]
|
96
|
+
text += "\n\n"
|
97
|
+
end
|
98
|
+
File.open(file_path, 'w') do |f|
|
99
|
+
f.write(text)
|
100
|
+
end
|
101
|
+
puts "已经保存文件到 #{file_path}"
|
102
|
+
end
|
103
|
+
end
|
102
104
|
end
|
103
105
|
end
|
data/lib/luogu/cli.rb
CHANGED
@@ -11,6 +11,7 @@ module Luogu
|
|
11
11
|
puts """
|
12
12
|
luogu build <file> -> 编译prompt
|
13
13
|
luogu run <file> -> 测试 prompt
|
14
|
+
luogu gen <file> <target> -> 根据 json 生成 prompt 文件
|
14
15
|
"""
|
15
16
|
exit
|
16
17
|
end
|
@@ -31,6 +32,11 @@ module Luogu
|
|
31
32
|
chatgpt.run
|
32
33
|
end
|
33
34
|
|
35
|
+
subcommands['gen'] = Proc.new do |args|
|
36
|
+
json = JSON.parse File.read(args.first), symbolize_names: true
|
37
|
+
chatgpt = ChatGPT.save(json, args.last)
|
38
|
+
end
|
39
|
+
|
34
40
|
if subcommands.key?(ARGV.first)
|
35
41
|
subcommands[ARGV.first].call(ARGV[1..-1])
|
36
42
|
else
|
data/lib/luogu/version.rb
CHANGED