azure_openai_client 0.0.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 +7 -0
- data/README.md +178 -0
- data/lib/azure_openai_client/api/default_api.rb +232 -0
- data/lib/azure_openai_client/api_client.rb +390 -0
- data/lib/azure_openai_client/api_error.rb +58 -0
- data/lib/azure_openai_client/configuration.rb +214 -0
- data/lib/azure_openai_client/models/chat_completions_body.rb +334 -0
- data/lib/azure_openai_client/models/deploymentid_completions_body.rb +406 -0
- data/lib/azure_openai_client/models/deploymentid_embeddings_body.rb +202 -0
- data/lib/azure_openai_client/models/deploymentsdeploymentidchatcompletions_messages.rb +274 -0
- data/lib/azure_openai_client/models/error_response.rb +209 -0
- data/lib/azure_openai_client/models/error_response_error.rb +236 -0
- data/lib/azure_openai_client/models/inline_response_200.rb +281 -0
- data/lib/azure_openai_client/models/inline_response_200_1.rb +258 -0
- data/lib/azure_openai_client/models/inline_response_200_1_data.rb +244 -0
- data/lib/azure_openai_client/models/inline_response_200_1_usage.rb +228 -0
- data/lib/azure_openai_client/models/inline_response_200_2.rb +281 -0
- data/lib/azure_openai_client/models/inline_response_200_2_choices.rb +227 -0
- data/lib/azure_openai_client/models/inline_response_200_2_message.rb +264 -0
- data/lib/azure_openai_client/models/inline_response_200_2_usage.rb +242 -0
- data/lib/azure_openai_client/models/inline_response_200_choices.rb +236 -0
- data/lib/azure_openai_client/models/inline_response_200_logprobs.rb +244 -0
- data/lib/azure_openai_client/models/inline_response_200_usage.rb +242 -0
- data/lib/azure_openai_client/models/one_ofchat_completions_body_stop.rb +198 -0
- data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_prompt.rb +198 -0
- data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_stop.rb +198 -0
- data/lib/azure_openai_client/version.rb +16 -0
- data/lib/azure_openai_client.rb +61 -0
- data/spec/api/default_api_spec.rb +75 -0
- data/spec/api_client_spec.rb +229 -0
- data/spec/configuration_spec.rb +78 -0
- data/spec/models/chat_completions_body_spec.rb +102 -0
- data/spec/models/deploymentid_completions_body_spec.rb +144 -0
- data/spec/models/deploymentid_embeddings_body_spec.rb +36 -0
- data/spec/models/deploymentsdeploymentidchatcompletions_messages_spec.rb +58 -0
- data/spec/models/error_response_error_spec.rb +60 -0
- data/spec/models/error_response_spec.rb +42 -0
- data/spec/models/inline_response_200_1_data_spec.rb +54 -0
- data/spec/models/inline_response_200_1_spec.rb +60 -0
- data/spec/models/inline_response_200_1_usage_spec.rb +48 -0
- data/spec/models/inline_response_200_2_choices_spec.rb +54 -0
- data/spec/models/inline_response_200_2_message_spec.rb +52 -0
- data/spec/models/inline_response_200_2_spec.rb +72 -0
- data/spec/models/inline_response_200_2_usage_spec.rb +54 -0
- data/spec/models/inline_response_200_choices_spec.rb +60 -0
- data/spec/models/inline_response_200_logprobs_spec.rb +60 -0
- data/spec/models/inline_response_200_spec.rb +72 -0
- data/spec/models/inline_response_200_usage_spec.rb +54 -0
- data/spec/models/one_ofchat_completions_body_stop_spec.rb +36 -0
- data/spec/models/one_ofdeploymentid_completions_body_prompt_spec.rb +36 -0
- data/spec/models/one_ofdeploymentid_completions_body_stop_spec.rb +36 -0
- data/spec/spec_helper.rb +112 -0
- metadata +177 -0
@@ -0,0 +1,334 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
=begin
|
4
|
+
#Azure OpenAI Service API
|
5
|
+
|
6
|
+
#Azure OpenAI APIs for completions and search
|
7
|
+
|
8
|
+
OpenAPI spec version: 2023-05-15
|
9
|
+
|
10
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
11
|
+
Swagger Codegen version: 3.0.42
|
12
|
+
=end
|
13
|
+
|
14
|
+
require 'date'
|
15
|
+
|
16
|
+
module AzureOpenaiClient
|
17
|
+
class ChatCompletionsBody
|
18
|
+
# The messages to generate chat completions for, in the chat format.
|
19
|
+
attr_accessor :messages
|
20
|
+
|
21
|
+
# What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
|
22
|
+
attr_accessor :temperature
|
23
|
+
|
24
|
+
# An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
25
|
+
attr_accessor :top_p
|
26
|
+
|
27
|
+
# How many chat completion choices to generate for each input message.
|
28
|
+
attr_accessor :n
|
29
|
+
|
30
|
+
# If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message.
|
31
|
+
attr_accessor :stream
|
32
|
+
|
33
|
+
# Up to 4 sequences where the API will stop generating further tokens.
|
34
|
+
attr_accessor :stop
|
35
|
+
|
36
|
+
# The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens).
|
37
|
+
attr_accessor :max_tokens
|
38
|
+
|
39
|
+
# Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
|
40
|
+
attr_accessor :presence_penalty
|
41
|
+
|
42
|
+
# Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
|
43
|
+
attr_accessor :frequency_penalty
|
44
|
+
|
45
|
+
# Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
|
46
|
+
attr_accessor :logit_bias
|
47
|
+
|
48
|
+
# A unique identifier representing your end-user, which can help Azure OpenAI to monitor and detect abuse.
|
49
|
+
attr_accessor :user
|
50
|
+
|
51
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
52
|
+
def self.attribute_map
|
53
|
+
{
|
54
|
+
'messages': :'messages',
|
55
|
+
'temperature': :'temperature',
|
56
|
+
'top_p': :'top_p',
|
57
|
+
'n': :'n',
|
58
|
+
'stream': :'stream',
|
59
|
+
'stop': :'stop',
|
60
|
+
'max_tokens': :'max_tokens',
|
61
|
+
'presence_penalty': :'presence_penalty',
|
62
|
+
'frequency_penalty': :'frequency_penalty',
|
63
|
+
'logit_bias': :'logit_bias',
|
64
|
+
'user': :'user'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# Attribute type mapping.
|
69
|
+
def self.openapi_types
|
70
|
+
{
|
71
|
+
'messages': :'Object',
|
72
|
+
'temperature': :'Object',
|
73
|
+
'top_p': :'Object',
|
74
|
+
'n': :'Object',
|
75
|
+
'stream': :'Object',
|
76
|
+
'stop': :'Object',
|
77
|
+
'max_tokens': :'Object',
|
78
|
+
'presence_penalty': :'Object',
|
79
|
+
'frequency_penalty': :'Object',
|
80
|
+
'logit_bias': :'Object',
|
81
|
+
'user': :'Object'
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
# List of attributes with nullable: true
|
86
|
+
def self.openapi_nullable
|
87
|
+
Set.new([
|
88
|
+
:'temperature',
|
89
|
+
:'top_p',
|
90
|
+
:'n',
|
91
|
+
:'stream',
|
92
|
+
:'logit_bias',
|
93
|
+
])
|
94
|
+
end
|
95
|
+
|
96
|
+
# Initializes the object
|
97
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
98
|
+
def initialize(attributes = {})
|
99
|
+
if (!attributes.is_a?(Hash))
|
100
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ChatCompletionsBody` initialize method"
|
101
|
+
end
|
102
|
+
|
103
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
104
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
105
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
106
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ChatCompletionsBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
107
|
+
end
|
108
|
+
h[k.to_sym] = v
|
109
|
+
}
|
110
|
+
|
111
|
+
if attributes.key?(:'messages')
|
112
|
+
if (value = attributes[:'messages']).is_a?(Array)
|
113
|
+
self.messages = value
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
if attributes.key?(:'temperature')
|
118
|
+
self.temperature = attributes[:'temperature']
|
119
|
+
else
|
120
|
+
self.temperature = 1
|
121
|
+
end
|
122
|
+
|
123
|
+
if attributes.key?(:'top_p')
|
124
|
+
self.top_p = attributes[:'top_p']
|
125
|
+
else
|
126
|
+
self.top_p = 1
|
127
|
+
end
|
128
|
+
|
129
|
+
if attributes.key?(:'n')
|
130
|
+
self.n = attributes[:'n']
|
131
|
+
else
|
132
|
+
self.n = 1
|
133
|
+
end
|
134
|
+
|
135
|
+
if attributes.key?(:'stream')
|
136
|
+
self.stream = attributes[:'stream']
|
137
|
+
else
|
138
|
+
self.stream = false
|
139
|
+
end
|
140
|
+
|
141
|
+
if attributes.key?(:'stop')
|
142
|
+
self.stop = attributes[:'stop']
|
143
|
+
end
|
144
|
+
|
145
|
+
if attributes.key?(:'max_tokens')
|
146
|
+
self.max_tokens = attributes[:'max_tokens']
|
147
|
+
end
|
148
|
+
|
149
|
+
if attributes.key?(:'presence_penalty')
|
150
|
+
self.presence_penalty = attributes[:'presence_penalty']
|
151
|
+
else
|
152
|
+
self.presence_penalty = 0
|
153
|
+
end
|
154
|
+
|
155
|
+
if attributes.key?(:'frequency_penalty')
|
156
|
+
self.frequency_penalty = attributes[:'frequency_penalty']
|
157
|
+
else
|
158
|
+
self.frequency_penalty = 0
|
159
|
+
end
|
160
|
+
|
161
|
+
if attributes.key?(:'logit_bias')
|
162
|
+
self.logit_bias = attributes[:'logit_bias']
|
163
|
+
end
|
164
|
+
|
165
|
+
if attributes.key?(:'user')
|
166
|
+
self.user = attributes[:'user']
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
171
|
+
# @return Array for valid properties with the reasons
|
172
|
+
def list_invalid_properties
|
173
|
+
invalid_properties = Array.new
|
174
|
+
if @messages.nil?
|
175
|
+
invalid_properties.push('invalid value for "messages", messages cannot be nil.')
|
176
|
+
end
|
177
|
+
|
178
|
+
invalid_properties
|
179
|
+
end
|
180
|
+
|
181
|
+
# Check to see if the all the properties in the model are valid
|
182
|
+
# @return true if the model is valid
|
183
|
+
def valid?
|
184
|
+
return false if @messages.nil?
|
185
|
+
true
|
186
|
+
end
|
187
|
+
|
188
|
+
# Checks equality by comparing each attribute.
|
189
|
+
# @param [Object] Object to be compared
|
190
|
+
def ==(o)
|
191
|
+
return true if self.equal?(o)
|
192
|
+
self.class == o.class &&
|
193
|
+
messages == o.messages &&
|
194
|
+
temperature == o.temperature &&
|
195
|
+
top_p == o.top_p &&
|
196
|
+
n == o.n &&
|
197
|
+
stream == o.stream &&
|
198
|
+
stop == o.stop &&
|
199
|
+
max_tokens == o.max_tokens &&
|
200
|
+
presence_penalty == o.presence_penalty &&
|
201
|
+
frequency_penalty == o.frequency_penalty &&
|
202
|
+
logit_bias == o.logit_bias &&
|
203
|
+
user == o.user
|
204
|
+
end
|
205
|
+
|
206
|
+
# @see the `==` method
|
207
|
+
# @param [Object] Object to be compared
|
208
|
+
def eql?(o)
|
209
|
+
self == o
|
210
|
+
end
|
211
|
+
|
212
|
+
# Calculates hash code according to all attributes.
|
213
|
+
# @return [Integer] Hash code
|
214
|
+
def hash
|
215
|
+
[messages, temperature, top_p, n, stream, stop, max_tokens, presence_penalty, frequency_penalty, logit_bias, user].hash
|
216
|
+
end
|
217
|
+
|
218
|
+
# Builds the object from hash
|
219
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
220
|
+
# @return [Object] Returns the model itself
|
221
|
+
def self.build_from_hash(attributes)
|
222
|
+
new.build_from_hash(attributes)
|
223
|
+
end
|
224
|
+
|
225
|
+
# Builds the object from hash
|
226
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
227
|
+
# @return [Object] Returns the model itself
|
228
|
+
def build_from_hash(attributes)
|
229
|
+
return nil unless attributes.is_a?(Hash)
|
230
|
+
self.class.openapi_types.each_pair do |key, type|
|
231
|
+
if type =~ /\AArray<(.*)>/i
|
232
|
+
# check to ensure the input is an array given that the attribute
|
233
|
+
# is documented as an array but the input is not
|
234
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
235
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
236
|
+
end
|
237
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
238
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
239
|
+
elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
240
|
+
self.send("#{key}=", nil)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
self
|
245
|
+
end
|
246
|
+
|
247
|
+
# Deserializes the data based on type
|
248
|
+
# @param string type Data type
|
249
|
+
# @param string value Value to be deserialized
|
250
|
+
# @return [Object] Deserialized data
|
251
|
+
def _deserialize(type, value)
|
252
|
+
case type.to_sym
|
253
|
+
when :DateTime
|
254
|
+
DateTime.parse(value)
|
255
|
+
when :Date
|
256
|
+
Date.parse(value)
|
257
|
+
when :String
|
258
|
+
value.to_s
|
259
|
+
when :Integer
|
260
|
+
value.to_i
|
261
|
+
when :Float
|
262
|
+
value.to_f
|
263
|
+
when :Boolean
|
264
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
265
|
+
true
|
266
|
+
else
|
267
|
+
false
|
268
|
+
end
|
269
|
+
when :Object
|
270
|
+
# generic object (usually a Hash), return directly
|
271
|
+
value
|
272
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
273
|
+
inner_type = Regexp.last_match[:inner_type]
|
274
|
+
value.map { |v| _deserialize(inner_type, v) }
|
275
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
276
|
+
k_type = Regexp.last_match[:k_type]
|
277
|
+
v_type = Regexp.last_match[:v_type]
|
278
|
+
{}.tap do |hash|
|
279
|
+
value.each do |k, v|
|
280
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
else # model
|
284
|
+
AzureOpenaiClient.const_get(type).build_from_hash(value)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
# Returns the string representation of the object
|
289
|
+
# @return [String] String presentation of the object
|
290
|
+
def to_s
|
291
|
+
to_hash.to_s
|
292
|
+
end
|
293
|
+
|
294
|
+
# to_body is an alias to to_hash (backward compatibility)
|
295
|
+
# @return [Hash] Returns the object in the form of hash
|
296
|
+
def to_body
|
297
|
+
to_hash
|
298
|
+
end
|
299
|
+
|
300
|
+
# Returns the object in the form of hash
|
301
|
+
# @return [Hash] Returns the object in the form of hash
|
302
|
+
def to_hash
|
303
|
+
hash = {}
|
304
|
+
self.class.attribute_map.each_pair do |attr, param|
|
305
|
+
value = self.send(attr)
|
306
|
+
if value.nil?
|
307
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
308
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
309
|
+
end
|
310
|
+
|
311
|
+
hash[param] = _to_hash(value)
|
312
|
+
end
|
313
|
+
hash
|
314
|
+
end
|
315
|
+
|
316
|
+
# Outputs non-array value in the form of hash
|
317
|
+
# For object, use to_hash. Otherwise, just return the value
|
318
|
+
# @param [Object] value Any valid value
|
319
|
+
# @return [Hash] Returns the value in the form of hash
|
320
|
+
def _to_hash(value)
|
321
|
+
if value.is_a?(Array)
|
322
|
+
value.compact.map { |v| _to_hash(v) }
|
323
|
+
elsif value.is_a?(Hash)
|
324
|
+
{}.tap do |hash|
|
325
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
326
|
+
end
|
327
|
+
elsif value.respond_to? :to_hash
|
328
|
+
value.to_hash
|
329
|
+
else
|
330
|
+
value
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|