ai_client 0.4.0 → 0.4.1
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/CHANGELOG.md +3 -0
- data/lib/ai_client/chat.rb +28 -13
- data/lib/ai_client/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: a6a570561363cbf57df995b7154be4214cb7e7488f0e826bd92b9d523affe52b
|
4
|
+
data.tar.gz: 42c3545fd727a240261c7df1d39528fcb5bf8c6cf6dce5820763d3cef22ccd20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a20e587c840fc83a5a3253cead493b15672d64ed0994245da1f54b2fc0e74852170637ff7c2d745b1cec5776cdfc3716bd210a664667632db3700075c5b974d5
|
7
|
+
data.tar.gz: 2e25503d39cbb956905c46cea2c519d6b086a0887469bd5b7c237040063aac2c886bdd57ffca365376ad908b53f407c3ef090a731f83551452dbcb4a782105a6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
## Released
|
4
4
|
|
5
|
+
### [0.4.1] - 2024-10-21
|
6
|
+
- fixed the context problem. the chatbot method works now.
|
7
|
+
|
5
8
|
### [0.4.0] - 2024-10-20
|
6
9
|
- Removed Logger.new(STDOUT) from the default configuration
|
7
10
|
> config.logger now returns nil If you want a class or instance logger setup, then you will have to do a config.logger = Logger.new(STDOUT) or whatever you need.
|
data/lib/ai_client/chat.rb
CHANGED
@@ -43,7 +43,10 @@ class AiClient
|
|
43
43
|
@last_response = result
|
44
44
|
result = raw? ? result : content
|
45
45
|
|
46
|
-
@context.push(
|
46
|
+
@context = @context.push({
|
47
|
+
user: @last_messages,
|
48
|
+
bot: result
|
49
|
+
}).last(config.context_length)
|
47
50
|
|
48
51
|
result
|
49
52
|
end
|
@@ -54,19 +57,18 @@ class AiClient
|
|
54
57
|
# @param prompt [String, Array<String>] the current prompt.
|
55
58
|
# @return [String, Array<String>] the prompt with context added.
|
56
59
|
#
|
57
|
-
def add_context(
|
58
|
-
return(
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def add_context(my_prompt)
|
61
|
+
return(my_prompt) if @config.context_length.nil? ||
|
62
|
+
0 == @config.context_length ||
|
63
|
+
my_prompt.is_a?(Array) ||
|
64
|
+
@context.empty?
|
62
65
|
|
63
|
-
|
64
|
-
prompt
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
66
|
+
prompt = "\nUser: #{my_prompt} Bot: "
|
67
|
+
prompt.prepend(
|
68
|
+
@context.map{|entry|
|
69
|
+
"User: #{entry[:user]} Bot: #{entry[:bot]}"
|
70
|
+
}.join("\n")
|
71
|
+
)
|
70
72
|
|
71
73
|
prompt
|
72
74
|
end
|
@@ -90,4 +92,17 @@ class AiClient
|
|
90
92
|
def chat_without_middlewares(messages, **params, &block)
|
91
93
|
@client.chat(messages, model: @model, **params, &block)
|
92
94
|
end
|
95
|
+
|
96
|
+
|
97
|
+
def chatbot
|
98
|
+
prompt = "hello"
|
99
|
+
until prompt.empty? do
|
100
|
+
response = chat prompt
|
101
|
+
puts
|
102
|
+
puts content
|
103
|
+
puts
|
104
|
+
print "Follow Up: "
|
105
|
+
prompt = gets.chomp
|
106
|
+
end
|
107
|
+
end
|
93
108
|
end
|
data/lib/ai_client/version.rb
CHANGED