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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d415e44469be65939709764b50b5283da141d5e68663acf5e3c376044407970
4
- data.tar.gz: 18846bbcd392e9581f6d9becff711b2e551983759460464b169824e14f3c05a1
3
+ metadata.gz: 8b6f8d477025b929343fbd70605905c557d33550d3f0f3921d256b295f993a96
4
+ data.tar.gz: 49aaf6803e6a8428bf143a743dd07ad840ddd0655a3228fad59543842af65466
5
5
  SHA512:
6
- metadata.gz: 5eb13f0a6b90843366879a773f816d55dbcdba55f2cc6f06915f9e7f7dbc4a73ceb1916505d482a670755d8197519792d649f0731c12f53071fa87b131bcd62a
7
- data.tar.gz: b25c5d0dfa8a2b4d4df66ec9695d226521551ddb77f674722d122ba8e9252546abcfa916d2d379a794f520fedf32247e1dcbeef575739675bdd84ddd705e78f5
6
+ metadata.gz: 6de98f0d6be3266c9b4d873fb0e97bd1cf94f63231411961af39671a1be9b4ce0040d3efd1476fe37a309bee3722e1a7e724fdbd37a0dc949e4982fb8e8425d4
7
+ data.tar.gz: 0cc7c4f3f9fa709c7fd1c7ca1a3b10ede905e5be36b90701edd0f100b404e64144deb20de6f081d3f6b89c757932f2932651fb0b6c6f60ec938419dfde2d5855
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luogu (0.1.7)
4
+ luogu (0.1.9)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  dry-cli (~> 1.0)
7
7
  ruby-openai (~> 3.7)
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
- @plugin.setup_proc.call(self) if @plugin.setup_proc
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
- params = @plugin.before_request_proc.call(self, params) if @plugin.before_request_proc
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
- user_message = @plugin.before_input_proc.call(self, user_message) if @plugin.before_input_proc
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
- @plugin.after_input_proc.call(self, messages) if @plugin.after_input_proc
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
- @plugin.after_save_history_proc.call(self, user_message, assistant_message) if @plugin.after_save_history_proc
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
@@ -5,6 +5,7 @@ require 'json'
5
5
  require 'yaml'
6
6
  require "dry/cli"
7
7
  require 'fileutils'
8
+ require 'ostruct'
8
9
 
9
10
  require_relative 'plugin'
10
11
  require_relative 'history_queue'
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.8"
4
+ VERSION = "0.1.9"
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ