-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
48 lines (40 loc) · 975 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Gpt
def initialize
@client = OpenAI::Client.new
end
def self.run
new.start
end
def start
puts "\n What would you like to ask GPT-3? Type 'exit' to quit. \n".green
ask_gpt
end
private
def ask_gpt
user_input = gets.chomp
if user_input == "exit"
end_app
else
response(user_input)
ask_gpt
end
end
def end_app
puts "Goodbye!"
exit
end
def response(user_input)
response = @client.completions(
parameters: {
model: "text-davinci-003",
prompt: user_input,
max_tokens: 50,
temperature: 0.3,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0
}
)
puts response["choices"].map { |choice| choice["text"].chomp.yellow + "\n \n" }
end
end