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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cd2a93255b9c6ed4fe776dab51414384fea23cad8d73c1e407acb5deb9bb382
4
- data.tar.gz: e26cdfa7b3e748a580181f6a916a6fd07667fe6b0a3d3c713c454b9584b09eee
3
+ metadata.gz: 584995338f86e7c2be1f099920457c424396373ec007e6fa7185face0a0254e9
4
+ data.tar.gz: 7414294ca9278bc20989b2fb5e58bd5c3b6602a35853ae8f56a4b35423b1974b
5
5
  SHA512:
6
- metadata.gz: f6ce3327ccd8824a59e5deda151876f1d6fc1b64247c5d5b1140ae4e1fd8455169b8c346f3101304f4b0dd01a5c201b43d5cbb8f322b91ab23a159d6285cf6c3
7
- data.tar.gz: 3b6e68d717a10b7ca2feca6cf5b47760e0ab0d672b5cce34883e992a6fffa49caa0a69cd5f36f98cd51c49d1237d76f643f3ca50c241f328f1789ab803ac38ee
6
+ metadata.gz: ca7945d9ef6ddc5ba18ff6e258f18bf8799049d580b7befbe50b1db43297322171b68852f8783643b16f829c7a7b99faf5fceec6d87c64a20232fd9e7ce04087
7
+ data.tar.gz: 2982f3f04cb4edec38434db75933921b7574f8b885d8a8265514071724f0ca72eb2bd681377773c97edf5be9ee48a358f729f5a12f507fc753527f1f594300ea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luogu (0.1.0)
4
+ luogu (0.1.1)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  ruby-openai (~> 3.7)
7
7
  tty-prompt (~> 0.23.1)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Luogu
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luogu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ