File tree 3 files changed +90
-1
lines changed
3 files changed +90
-1
lines changed Original file line number Diff line number Diff line change
1
+ source "https://rubygems.org"
2
+
3
+ gem "ruby-openai"
4
+ gem "dotenv"
Original file line number Diff line number Diff line change
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ dotenv (3.1.7 )
5
+ event_stream_parser (1.0.0 )
6
+ faraday (2.12.2 )
7
+ faraday-net_http (>= 2.0 , < 3.5 )
8
+ json
9
+ logger
10
+ faraday-multipart (1.1.0 )
11
+ multipart-post (~> 2.0 )
12
+ faraday-net_http (3.4.0 )
13
+ net-http (>= 0.5.0 )
14
+ json (2.9.1 )
15
+ logger (1.6.5 )
16
+ multipart-post (2.4.1 )
17
+ net-http (0.6.0 )
18
+ uri
19
+ ruby-openai (7.3.1 )
20
+ event_stream_parser (>= 0.3.0 , < 2.0.0 )
21
+ faraday (>= 1 )
22
+ faraday-multipart (>= 1 )
23
+ uri (1.0.2 )
24
+
25
+ PLATFORMS
26
+ x86_64-linux
27
+
28
+ DEPENDENCIES
29
+ dotenv
30
+ ruby-openai
31
+
32
+ BUNDLED WITH
33
+ 2.4.6
Original file line number Diff line number Diff line change 1
- # Write your solution here!
1
+ require "openai"
2
+ require "dotenv/load"
3
+
4
+ client = OpenAI ::Client . new ( access_token : ENV . fetch ( "OPENAI_KEY" ) )
5
+
6
+ # message_list = [
7
+ # {
8
+ # "role" => "system",
9
+ # "content" => "You are a very helpful assistant that likes to speak very passionately"
10
+ # },
11
+ # {
12
+ # "role" => "user",
13
+ # "content" => "Hello, what are the best spots for Japanese food in New York City?"
14
+ # }
15
+ # ]
16
+
17
+ # api_response = client.chat(
18
+ # parameters: {
19
+ # model: "gpt-3.5-turbo",
20
+ # messages: message_list
21
+ # }
22
+ # )
23
+
24
+ puts "Hello. How can I help you today?"
25
+ puts "-" * 50
26
+
27
+ user_input = gets . chomp . gsub ( " " , "%20" )
28
+
29
+ message_list = [
30
+ {
31
+ "role" => "system" ,
32
+ "content" => "You are a very helpful assistant that likes to speak very passionately"
33
+ } ,
34
+ {
35
+ "role" => "user" ,
36
+ "content" => user_input
37
+ }
38
+ ]
39
+
40
+ api_response = client . chat (
41
+ parameters : {
42
+ model : "gpt-3.5-turbo" ,
43
+ messages : message_list
44
+ }
45
+ )
46
+
47
+ specific_1 = api_response . fetch ( "choices" )
48
+ specific_2 = specific_1 . at ( 0 )
49
+ specific_3 = specific_2 . fetch ( "message" )
50
+ specific_4 = specific_3 [ "content" ]
51
+
52
+ puts "-" * 50
53
+ pp specific_4
You can’t perform that action at this time.
0 commit comments