luogu 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/luogu/aiui.rb +26 -0
- data/lib/luogu/application.rb +5 -0
- data/lib/luogu/init.rb +3 -0
- data/lib/luogu/openai.rb +36 -0
- data/lib/luogu/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a148eff2b580b1fc02bf9a71ffbef28bcfbe54752bc73c877ea17ed19cf301c4
|
4
|
+
data.tar.gz: edeb9d2d566292180ad9cc29c172a2e7545c1656dd3791258780adf8a0587571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fd79fb77f48a73cd6e64194cd2826e23ad27c18d7904c0a737c0b2340bc080a33e65271f005f91a6182eed36f77ccb08c15efd4f93c43588b3ac6800af2e48c
|
7
|
+
data.tar.gz: 4f3fbb7674ae5dd9ddf3df8979ccbea102552527eba4090309cf6a0265d4022701e1338d91fa8dba4283acc9bede24398365ad8dddc4e4efe606e0b28e9b3e9f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -142,6 +142,7 @@ end
|
|
142
142
|
- 0.1.15:http库替换成HTTP.rb并且加入了重试机制,默认为3次,可通过设置环境变量OPENAI_REQUEST_RETRIES来设置次数
|
143
143
|
- 0.1.16:增加对agent的支持
|
144
144
|
- 0.2.0:重构了代码,agent的支持基本达到可用状态,具体看`bin/agent.rb`示例,有破坏性更新,不兼容0.1.x的agent写法
|
145
|
+
- 0.2.3: 增加了 AIUI 客户端,具体情况示例,openai的接口加入message类用于快速拼接messages,具体看 lib/luogu/openai.rb
|
145
146
|
|
146
147
|
## License
|
147
148
|
|
data/lib/luogu/aiui.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Luogu
|
4
|
+
class AIUI < Base
|
5
|
+
setting :id, default: Application.config.aiui.id
|
6
|
+
setting :key, default: Application.config.aiui.key
|
7
|
+
setting :request_url, default: 'http://api.iflyos.cn/external/ls_log/aiui_request'
|
8
|
+
setting :parse, default: ->(response) { response.parse.dig("data", 0, "intent", "answer") }
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def request(text: nil, uid: SecureRandom.hex(16))
|
12
|
+
response = HTTP.post(config.request_url, json: {
|
13
|
+
appid: config.id,
|
14
|
+
appkey: config.key,
|
15
|
+
uid: uid,
|
16
|
+
text: text
|
17
|
+
})
|
18
|
+
if response.code == 200
|
19
|
+
config.parse.call(response)
|
20
|
+
else
|
21
|
+
raise RequestError, response.body.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/luogu/application.rb
CHANGED
@@ -12,6 +12,11 @@ module Luogu
|
|
12
12
|
setting :temperature, default: ENV.fetch('OPENAI_TEMPERATURE', 1).to_i
|
13
13
|
end
|
14
14
|
|
15
|
+
setting :aiui do
|
16
|
+
setting :id, default: ENV.fetch('AIUI_APP_ID')
|
17
|
+
setting :key, default: ENV.fetch('AIUI_APP_KEY')
|
18
|
+
end
|
19
|
+
|
15
20
|
setting :run_agent_retries, default: ENV.fetch('RUN_AGENT_RETRIES', 5).to_i
|
16
21
|
|
17
22
|
setting :logger, reader: true,
|
data/lib/luogu/init.rb
CHANGED
@@ -8,6 +8,7 @@ require 'ostruct'
|
|
8
8
|
require 'benchmark'
|
9
9
|
require 'erb'
|
10
10
|
require 'logger'
|
11
|
+
require 'securerandom'
|
11
12
|
|
12
13
|
require "dry/cli"
|
13
14
|
require 'dry-configurable'
|
@@ -29,6 +30,8 @@ require_relative "agent_runner"
|
|
29
30
|
require_relative 'openai'
|
30
31
|
require_relative 'terminal'
|
31
32
|
|
33
|
+
require_relative 'aiui'
|
34
|
+
|
32
35
|
class String
|
33
36
|
def cover_chinese
|
34
37
|
self.gsub(/[\uFF01-\uFF0F]/) {|s| (s.ord-65248).chr}
|
data/lib/luogu/openai.rb
CHANGED
@@ -74,5 +74,41 @@ module Luogu::OpenAI
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
class Messages
|
78
|
+
def initialize
|
79
|
+
@messages = []
|
80
|
+
@system = {}
|
81
|
+
end
|
82
|
+
|
83
|
+
def system(text: nil, file_: nil)
|
84
|
+
data = text || File.read(file)
|
85
|
+
@system = {role: "system", content: data}
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def user(text: nil, file: nil)
|
90
|
+
data = text || File.read(file)
|
91
|
+
@messages << {role: "user", content: data}
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def assistant(text: nil, file: nil)
|
96
|
+
data = text || File.read(file)
|
97
|
+
@messages << {role: "assistant", content: data}
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_a
|
102
|
+
@messages.unshift @system
|
103
|
+
end
|
104
|
+
|
105
|
+
class << self
|
106
|
+
def create
|
107
|
+
self.new
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
77
113
|
module_function :chat, :client, :parse_json, :chat_response_handle, :find_final_answer, :get_content
|
78
114
|
end
|
data/lib/luogu/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.3
|
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
|
+
date: 2023-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/luogu.rb
|
116
116
|
- lib/luogu/agent.rb
|
117
117
|
- lib/luogu/agent_runner.rb
|
118
|
+
- lib/luogu/aiui.rb
|
118
119
|
- lib/luogu/application.rb
|
119
120
|
- lib/luogu/base.rb
|
120
121
|
- lib/luogu/chatllm.rb
|