luogu 0.1.10 → 0.1.12

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: bf66040bab414493d1be24b2ed42780d2cefae0c79814b48b363bcc2ed094415
4
- data.tar.gz: 4e1c53cb018a14ed2ca607d364717fd5f84a8ff7a7246c641e79cd6f17806ae7
3
+ metadata.gz: d3ff171b0c4c4e1d93ebec7ffdbb1d9d95103989b4b9f29e0914b0c8f92a5949
4
+ data.tar.gz: fbb022de66ceaec42953c212e20ecb3a53a21d95664170249dbd7f036898e11b
5
5
  SHA512:
6
- metadata.gz: 9670b5c6bd270e449b2916313474c4a6ac0eafff47b550a9853e8a6b0a032375eb7d74bc29d68c431fbb8ffe2ba946cc458316aa0046fde514e710b7dc642d06
7
- data.tar.gz: 30556b308a94306863f8f2f7e6b1ebf9d53214a3832644cb013dc99fb332e781e519e2dd6f52a99d6da367b9f9973c1b7123b5a5e524aaa4d1d4eb5015f3d0e4
6
+ metadata.gz: 6abeb1fa0e1bc92d9a744ecd2dbefa109deefd4f8d758de15838be7eb15560885652018662e9d864c201d08339f9e5a6de51b335cfeef0ab8579b2987a00e132
7
+ data.tar.gz: b9f3a6dfefe8004be775e590ae8ee4763a3bf254a02038ecfae711ba902c97e7468ce060f9308cc1ca1188d088693fd3d8f5c3b70ff78d773569c83b14ddd502
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luogu (0.1.9)
4
+ luogu (0.1.11)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  dry-cli (~> 1.0)
7
7
  ruby-openai (~> 3.7)
data/README.md CHANGED
@@ -62,10 +62,69 @@ end
62
62
  - exit 退出
63
63
 
64
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
- - OpenStruct.new(response: response)
65
+ run 和 test 中可以使用,可以使用 --plugin=<file>.plugin.rb
66
+ 默认情况下你可以使用 <文件名>.plugin.rb 来实现一个prompt.md的插件
67
+ 在插件中有两个对象
68
+
69
+ ```ruby
70
+ #gpt
71
+ gpt.row_history # 访问裸的历史记录 可读写
72
+ gpt.history # 处理过的历史记录 可读写
73
+ gpt.temperature # 设置请求的 temperature
74
+ gpt.model_name # 获取模型名称
75
+
76
+ #context
77
+ OpenStruct.new(
78
+ request_params: params, # 请求参数
79
+ user_input: user_message, # 用户输入
80
+ request_messages: messages, #请求时的messages
81
+ response_message: assistant_message, # 回复的message
82
+ response: response # 回复的response
83
+ )
84
+ # 如果需要在方法中使用使用变量传递,必须使用context包括你要的变量名,比如 context.name = "luogu"
85
+ ```
86
+
87
+ 支持的回调
88
+ ```ruby
89
+ # 所有方法都必须返回context
90
+ # 可以使用
91
+ # require 'irb'
92
+ # binding.irb
93
+ # 来调试断点
94
+
95
+ setup do |gpt, context|
96
+ puts gpt
97
+ context
98
+ end
99
+
100
+ before_input do |gpt, context|
101
+ puts "用户输入了: #{context.user_input}"
102
+ context
103
+ end
104
+
105
+ after_input do |gpt, context|
106
+ context
107
+ end
108
+
109
+ before_request do |gpt, context|
110
+ puts "request params: "
111
+ puts context
112
+ context
113
+ end
114
+
115
+ after_request do |gpt, context|
116
+ context
117
+ end
118
+
119
+ before_save_history do |gpt, context|
120
+ context
121
+ end
122
+
123
+ after_save_historydo |gpt, context|
124
+ context
125
+ end
126
+
127
+
128
+ ```
70
129
 
71
130
  ## MIT 协议
data/lib/luogu/chatgpt.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Luogu
2
2
  class ChatGPT
3
3
 
4
- attr_accessor :template, :limit_history, :prompt, :row_history, :history, :temperature, :model_name, :context
4
+ attr_accessor :limit_history, :prompt, :row_history, :history, :temperature, :model_name, :context
5
5
 
6
6
  def initialize(file, history_path='.', plugin_file_path=nil)
7
7
  @plugin_file_path = plugin_file_path || file.sub(File.extname(file), ".plugin.rb")
@@ -128,15 +128,21 @@ module Luogu
128
128
  puts "再见!"
129
129
  break
130
130
  else
131
- self.puts self.chat(input)
131
+ time = Benchmark.measure do
132
+ self.puts self.chat(input)
133
+ end
134
+ puts "input: #{input} 执行时间为 #{time.real} 秒"
132
135
  end
133
136
  end
134
137
  end
135
138
 
136
139
  def playload(messages)
137
140
  messages.each do |message|
138
- puts "test: #{message}"
139
- self.puts self.chat(message)
141
+ time = Benchmark.measure do
142
+ puts "test: #{message}"
143
+ self.puts self.chat(message)
144
+ end
145
+ puts "test: #{message} 执行时间为 #{time.real} 秒"
140
146
  end
141
147
  now = Time.now.to_i
142
148
  file_name = File.basename(@prompt_file, ".*")
data/lib/luogu/init.rb CHANGED
@@ -6,6 +6,7 @@ require 'yaml'
6
6
  require "dry/cli"
7
7
  require 'fileutils'
8
8
  require 'ostruct'
9
+ require 'benchmark'
9
10
 
10
11
  require_relative 'plugin'
11
12
  require_relative 'history_queue'
@@ -1,6 +1,6 @@
1
1
  module Luogu
2
2
  class PromptParser
3
- attr_reader :ruby_code, :ruby_code_line, :file_path
3
+ attr_reader :ruby_code, :ruby_code_line, :file_path, :messages
4
4
  def initialize(file_path)
5
5
  @file_path = file_path
6
6
  @messages = []
@@ -17,7 +17,6 @@ module Luogu
17
17
  JSON.pretty_generate self.render
18
18
  end
19
19
 
20
- private
21
20
  def process_file
22
21
  @messages = []
23
22
  file = File.read(@file_path)
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.10"
4
+ VERSION = "0.1.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luogu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-11 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai