@@ -13,7 +13,12 @@ def self.name
13
13
'User'
14
14
end
15
15
16
+ def self . instructions
17
+ "Extract the user's name and age."
18
+ end
19
+
16
20
define_schema do
21
+ title 'SomeUser'
17
22
property :name , String
18
23
property :age , Integer
19
24
end
@@ -24,19 +29,39 @@ def self.name
24
29
expect ( patched_client ) . to eq ( OpenAI ::Client )
25
30
end
26
31
32
+ context 'when generating description' do
33
+ let ( :client ) { patched_client . new }
34
+
35
+ it "returns the model's instructions" do
36
+ expect ( client . generate_description ( user_model ) ) . to eq ( "Extract the user's name and age." )
37
+ end
38
+
39
+ it 'returns the default description when the model does not have instructions' do
40
+ model = Class . new do
41
+ include EasyTalk ::Model
42
+
43
+ def self . name
44
+ 'User'
45
+ end
46
+
47
+ define_schema { }
48
+ end
49
+
50
+ expect ( client . generate_description ( model ) ) . to eq ( 'Correctly extracted `User` with all the required parameters with correct types' )
51
+ end
52
+ end
53
+
27
54
context 'with a new instance of the patched client' do
28
55
it 'returns an instance of the patched client' do
29
56
expect ( patched_client . new ) . to be_an_instance_of ( OpenAI ::Client )
30
57
end
31
58
32
59
pending 'receives the chat method with the expected arguments' do
33
- client = patched_client . new
34
60
client . chat ( parameters : { } , response_model : nil )
35
61
expect ( client ) . to have_received ( :chat ) . with ( parameters : { } , response_model : nil )
36
62
end
37
63
38
64
it 'does not require the response model argument' do
39
- client = patched_client . new
40
65
expect { client . chat ( parameters : { } ) } . not_to raise_error ( ArgumentError )
41
66
end
42
67
@@ -45,6 +70,28 @@ def self.name
45
70
expect { client . chat } . to raise_error ( ArgumentError , 'missing keyword: :parameters' )
46
71
end
47
72
73
+ describe 'when setting the function_name' do
74
+ it 'returns the function_name based on the schema title' do
75
+ client = patched_client . new
76
+ expect ( client . generate_function_name ( user_model ) ) . to eq ( 'SomeUser' )
77
+ end
78
+
79
+ it 'returns the class name when the schema title is not defined' do
80
+ model = Class . new do
81
+ include EasyTalk ::Model
82
+
83
+ def self . name
84
+ 'User'
85
+ end
86
+
87
+ define_schema { }
88
+ end
89
+
90
+ client = patched_client . new
91
+ expect ( client . generate_function_name ( model ) ) . to eq ( 'User' )
92
+ end
93
+ end
94
+
48
95
it 'returns an object with the expected valid attribute values' , vcr : 'patching_spec/valid_response' do
49
96
client = patched_client . new
50
97
0 commit comments