azure_openai_client 0.0.1 → 0.0.3
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/Gemfile +10 -0
- data/Gemfile.lock +76 -0
- data/README.md +50 -87
- data/Rakefile +10 -0
- data/azure_openai_client.gemspec +38 -0
- data/docs/ChatCompletionsCreate200Response.md +28 -0
- data/docs/ChatCompletionsCreate200ResponseChoicesInner.md +22 -0
- data/docs/ChatCompletionsCreate200ResponseChoicesInnerMessage.md +20 -0
- data/docs/ChatCompletionsCreate200ResponseUsage.md +22 -0
- data/docs/ChatCompletionsCreateRequest.md +38 -0
- data/docs/ChatCompletionsCreateRequestMessagesInner.md +22 -0
- data/docs/ChatCompletionsCreateRequestStop.md +49 -0
- data/docs/CompletionsCreate200Response.md +28 -0
- data/docs/CompletionsCreate200ResponseChoicesInner.md +24 -0
- data/docs/CompletionsCreate200ResponseChoicesInnerLogprobs.md +24 -0
- data/docs/CompletionsCreate200ResponseUsage.md +22 -0
- data/docs/CompletionsCreateRequest.md +52 -0
- data/docs/CompletionsCreateRequestPrompt.md +49 -0
- data/docs/CompletionsCreateRequestStop.md +49 -0
- data/docs/DefaultApi.md +238 -0
- data/docs/EmbeddingsCreate200Response.md +24 -0
- data/docs/EmbeddingsCreate200ResponseDataInner.md +22 -0
- data/docs/EmbeddingsCreate200ResponseUsage.md +20 -0
- data/docs/EmbeddingsCreateRequest.md +24 -0
- data/docs/EmbeddingsCreateRequestInput.md +49 -0
- data/docs/ErrorResponse.md +18 -0
- data/docs/ErrorResponseError.md +24 -0
- data/git_push.sh +53 -0
- data/inference.json +816 -0
- data/lib/azure_openai_client/api/default_api.rb +120 -93
- data/lib/azure_openai_client/api_client.rb +77 -75
- data/lib/azure_openai_client/api_error.rb +5 -5
- data/lib/azure_openai_client/configuration.rb +114 -22
- data/lib/azure_openai_client/models/{inline_response_200_2.rb → chat_completions_create200_response.rb} +34 -26
- data/lib/azure_openai_client/models/{inline_response_200_2_choices.rb → chat_completions_create200_response_choices_inner.rb} +28 -20
- data/lib/azure_openai_client/models/{inline_response_200_2_message.rb → chat_completions_create200_response_choices_inner_message.rb} +28 -20
- data/lib/azure_openai_client/models/{inline_response_200_2_usage.rb → chat_completions_create200_response_usage.rb} +28 -20
- data/lib/azure_openai_client/models/{chat_completions_body.rb → chat_completions_create_request.rb} +183 -37
- data/lib/azure_openai_client/models/{deploymentsdeploymentidchatcompletions_messages.rb → chat_completions_create_request_messages_inner.rb} +30 -22
- data/lib/azure_openai_client/models/chat_completions_create_request_stop.rb +105 -0
- data/lib/azure_openai_client/models/{inline_response_200.rb → completions_create200_response.rb} +34 -26
- data/lib/azure_openai_client/models/{inline_response_200_choices.rb → completions_create200_response_choices_inner.rb} +30 -22
- data/lib/azure_openai_client/models/{inline_response_200_logprobs.rb → completions_create200_response_choices_inner_logprobs.rb} +30 -22
- data/lib/azure_openai_client/models/{inline_response_200_usage.rb → completions_create200_response_usage.rb} +28 -20
- data/lib/azure_openai_client/models/{deploymentid_completions_body.rb → completions_create_request.rb} +58 -52
- data/lib/azure_openai_client/models/completions_create_request_prompt.rb +105 -0
- data/lib/azure_openai_client/models/completions_create_request_stop.rb +105 -0
- data/lib/azure_openai_client/models/{inline_response_200_1.rb → embeddings_create200_response.rb} +30 -22
- data/lib/azure_openai_client/models/{inline_response_200_1_data.rb → embeddings_create200_response_data_inner.rb} +28 -20
- data/lib/azure_openai_client/models/{inline_response_200_1_usage.rb → embeddings_create200_response_usage.rb} +26 -18
- data/lib/azure_openai_client/models/embeddings_create_request.rb +252 -0
- data/lib/azure_openai_client/models/embeddings_create_request_input.rb +105 -0
- data/lib/azure_openai_client/models/error_response.rb +21 -13
- data/lib/azure_openai_client/models/error_response_error.rb +27 -19
- data/lib/azure_openai_client/version.rb +5 -6
- data/lib/azure_openai_client.rb +23 -23
- data/openapi-codegen.sh +12 -0
- data/openapi_config.yaml +15 -0
- data/spec/api/default_api_spec.rb +21 -22
- data/spec/api_client_spec.rb +15 -16
- data/spec/configuration_spec.rb +3 -3
- data/spec/models/chat_completions_create200_response_choices_inner_message_spec.rb +44 -0
- data/spec/models/chat_completions_create200_response_choices_inner_spec.rb +46 -0
- data/spec/models/chat_completions_create200_response_spec.rb +64 -0
- data/spec/models/chat_completions_create200_response_usage_spec.rb +46 -0
- data/spec/models/chat_completions_create_request_messages_inner_spec.rb +50 -0
- data/spec/models/chat_completions_create_request_spec.rb +94 -0
- data/spec/models/chat_completions_create_request_stop_spec.rb +31 -0
- data/spec/models/completions_create200_response_choices_inner_logprobs_spec.rb +52 -0
- data/spec/models/completions_create200_response_choices_inner_spec.rb +52 -0
- data/spec/models/completions_create200_response_spec.rb +64 -0
- data/spec/models/completions_create200_response_usage_spec.rb +46 -0
- data/spec/models/completions_create_request_prompt_spec.rb +31 -0
- data/spec/models/completions_create_request_spec.rb +136 -0
- data/spec/models/completions_create_request_stop_spec.rb +31 -0
- data/spec/models/embeddings_create200_response_data_inner_spec.rb +46 -0
- data/spec/models/embeddings_create200_response_spec.rb +52 -0
- data/spec/models/embeddings_create200_response_usage_spec.rb +40 -0
- data/spec/models/embeddings_create_request_input_spec.rb +31 -0
- data/spec/models/embeddings_create_request_spec.rb +52 -0
- data/spec/models/error_response_error_spec.rb +12 -20
- data/spec/models/error_response_spec.rb +9 -17
- data/spec/spec_helper.rb +4 -5
- metadata +91 -77
- data/lib/azure_openai_client/models/deploymentid_embeddings_body.rb +0 -202
- data/lib/azure_openai_client/models/one_ofchat_completions_body_stop.rb +0 -198
- data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_prompt.rb +0 -198
- data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_stop.rb +0 -198
- data/spec/models/chat_completions_body_spec.rb +0 -102
- data/spec/models/deploymentid_completions_body_spec.rb +0 -144
- data/spec/models/deploymentid_embeddings_body_spec.rb +0 -36
- data/spec/models/deploymentsdeploymentidchatcompletions_messages_spec.rb +0 -58
- data/spec/models/inline_response_200_1_data_spec.rb +0 -54
- data/spec/models/inline_response_200_1_spec.rb +0 -60
- data/spec/models/inline_response_200_1_usage_spec.rb +0 -48
- data/spec/models/inline_response_200_2_choices_spec.rb +0 -54
- data/spec/models/inline_response_200_2_message_spec.rb +0 -52
- data/spec/models/inline_response_200_2_spec.rb +0 -72
- data/spec/models/inline_response_200_2_usage_spec.rb +0 -54
- data/spec/models/inline_response_200_choices_spec.rb +0 -60
- data/spec/models/inline_response_200_logprobs_spec.rb +0 -60
- data/spec/models/inline_response_200_spec.rb +0 -72
- data/spec/models/inline_response_200_usage_spec.rb +0 -54
- data/spec/models/one_ofchat_completions_body_stop_spec.rb +0 -36
- data/spec/models/one_ofdeploymentid_completions_body_prompt_spec.rb +0 -36
- data/spec/models/one_ofdeploymentid_completions_body_stop_spec.rb +0 -36
@@ -1,16 +1,17 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
=begin
|
4
2
|
#Azure OpenAI Service API
|
5
3
|
|
6
4
|
#Azure OpenAI APIs for completions and search
|
7
5
|
|
8
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: 2023-05-15
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
9
10
|
|
10
|
-
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
11
|
-
Swagger Codegen version: 3.0.42
|
12
11
|
=end
|
13
12
|
|
13
|
+
require 'cgi'
|
14
|
+
|
14
15
|
module AzureOpenaiClient
|
15
16
|
class DefaultApi
|
16
17
|
attr_accessor :api_client
|
@@ -18,42 +19,41 @@ module AzureOpenaiClient
|
|
18
19
|
def initialize(api_client = ApiClient.default)
|
19
20
|
@api_client = api_client
|
20
21
|
end
|
21
|
-
|
22
22
|
# Creates a completion for the chat message
|
23
|
-
# @param
|
24
|
-
# @param api_version
|
25
|
-
# @param
|
23
|
+
# @param deployment_id [String]
|
24
|
+
# @param api_version [String]
|
25
|
+
# @param chat_completions_create_request [ChatCompletionsCreateRequest]
|
26
26
|
# @param [Hash] opts the optional parameters
|
27
|
-
# @return [
|
28
|
-
def chat_completions_create(
|
29
|
-
data, _status_code, _headers = chat_completions_create_with_http_info(
|
27
|
+
# @return [ChatCompletionsCreate200Response]
|
28
|
+
def chat_completions_create(deployment_id, api_version, chat_completions_create_request, opts = {})
|
29
|
+
data, _status_code, _headers = chat_completions_create_with_http_info(deployment_id, api_version, chat_completions_create_request, opts)
|
30
30
|
data
|
31
31
|
end
|
32
32
|
|
33
33
|
# Creates a completion for the chat message
|
34
|
-
# @param
|
35
|
-
# @param api_version
|
36
|
-
# @param
|
34
|
+
# @param deployment_id [String]
|
35
|
+
# @param api_version [String]
|
36
|
+
# @param chat_completions_create_request [ChatCompletionsCreateRequest]
|
37
37
|
# @param [Hash] opts the optional parameters
|
38
|
-
# @return [Array<(
|
39
|
-
def chat_completions_create_with_http_info(
|
38
|
+
# @return [Array<(ChatCompletionsCreate200Response, Integer, Hash)>] ChatCompletionsCreate200Response data, response status code and response headers
|
39
|
+
def chat_completions_create_with_http_info(deployment_id, api_version, chat_completions_create_request, opts = {})
|
40
40
|
if @api_client.config.debugging
|
41
41
|
@api_client.config.logger.debug 'Calling API: DefaultApi.chat_completions_create ...'
|
42
42
|
end
|
43
|
-
# verify the required parameter '
|
44
|
-
if @api_client.config.client_side_validation &&
|
45
|
-
fail ArgumentError, "Missing the required parameter '
|
43
|
+
# verify the required parameter 'deployment_id' is set
|
44
|
+
if @api_client.config.client_side_validation && deployment_id.nil?
|
45
|
+
fail ArgumentError, "Missing the required parameter 'deployment_id' when calling DefaultApi.chat_completions_create"
|
46
46
|
end
|
47
47
|
# verify the required parameter 'api_version' is set
|
48
48
|
if @api_client.config.client_side_validation && api_version.nil?
|
49
49
|
fail ArgumentError, "Missing the required parameter 'api_version' when calling DefaultApi.chat_completions_create"
|
50
50
|
end
|
51
|
-
# verify the required parameter '
|
52
|
-
if @api_client.config.client_side_validation &&
|
53
|
-
fail ArgumentError, "Missing the required parameter '
|
51
|
+
# verify the required parameter 'chat_completions_create_request' is set
|
52
|
+
if @api_client.config.client_side_validation && chat_completions_create_request.nil?
|
53
|
+
fail ArgumentError, "Missing the required parameter 'chat_completions_create_request' when calling DefaultApi.chat_completions_create"
|
54
54
|
end
|
55
55
|
# resource path
|
56
|
-
local_var_path = '/deployments/{deployment-id}/chat/completions'.sub('{' + 'deployment-id' + '}', deployment_id.to_s)
|
56
|
+
local_var_path = '/deployments/{deployment-id}/chat/completions'.sub('{' + 'deployment-id' + '}', CGI.escape(deployment_id.to_s))
|
57
57
|
|
58
58
|
# query parameters
|
59
59
|
query_params = opts[:query_params] || {}
|
@@ -64,25 +64,34 @@ module AzureOpenaiClient
|
|
64
64
|
# HTTP header 'Accept' (if needed)
|
65
65
|
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
66
66
|
# HTTP header 'Content-Type'
|
67
|
-
|
67
|
+
content_type = @api_client.select_header_content_type(['application/json'])
|
68
|
+
if !content_type.nil?
|
69
|
+
header_params['Content-Type'] = content_type
|
70
|
+
end
|
68
71
|
|
69
72
|
# form parameters
|
70
73
|
form_params = opts[:form_params] || {}
|
71
74
|
|
72
75
|
# http body (model)
|
73
|
-
post_body = opts[:
|
76
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(chat_completions_create_request)
|
74
77
|
|
75
|
-
|
78
|
+
# return_type
|
79
|
+
return_type = opts[:debug_return_type] || 'ChatCompletionsCreate200Response'
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
header_params: header_params,
|
80
|
-
query_params: query_params,
|
81
|
-
form_params: form_params,
|
82
|
-
body: post_body,
|
83
|
-
auth_names: auth_names,
|
84
|
-
return_type: return_type)
|
81
|
+
# auth_names
|
82
|
+
auth_names = opts[:debug_auth_names] || ['apiKey', 'bearer']
|
85
83
|
|
84
|
+
new_options = opts.merge(
|
85
|
+
:operation => :"DefaultApi.chat_completions_create",
|
86
|
+
:header_params => header_params,
|
87
|
+
:query_params => query_params,
|
88
|
+
:form_params => form_params,
|
89
|
+
:body => post_body,
|
90
|
+
:auth_names => auth_names,
|
91
|
+
:return_type => return_type
|
92
|
+
)
|
93
|
+
|
94
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
86
95
|
if @api_client.config.debugging
|
87
96
|
@api_client.config.logger.debug "API called: DefaultApi#chat_completions_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
88
97
|
end
|
@@ -90,40 +99,40 @@ module AzureOpenaiClient
|
|
90
99
|
end
|
91
100
|
|
92
101
|
# Creates a completion for the provided prompt, parameters and chosen model.
|
93
|
-
# @param
|
94
|
-
# @param api_version
|
95
|
-
# @param
|
102
|
+
# @param deployment_id [String]
|
103
|
+
# @param api_version [String]
|
104
|
+
# @param completions_create_request [CompletionsCreateRequest]
|
96
105
|
# @param [Hash] opts the optional parameters
|
97
|
-
# @return [
|
98
|
-
def completions_create(
|
99
|
-
data, _status_code, _headers = completions_create_with_http_info(
|
106
|
+
# @return [CompletionsCreate200Response]
|
107
|
+
def completions_create(deployment_id, api_version, completions_create_request, opts = {})
|
108
|
+
data, _status_code, _headers = completions_create_with_http_info(deployment_id, api_version, completions_create_request, opts)
|
100
109
|
data
|
101
110
|
end
|
102
111
|
|
103
112
|
# Creates a completion for the provided prompt, parameters and chosen model.
|
104
|
-
# @param
|
105
|
-
# @param api_version
|
106
|
-
# @param
|
113
|
+
# @param deployment_id [String]
|
114
|
+
# @param api_version [String]
|
115
|
+
# @param completions_create_request [CompletionsCreateRequest]
|
107
116
|
# @param [Hash] opts the optional parameters
|
108
|
-
# @return [Array<(
|
109
|
-
def completions_create_with_http_info(
|
117
|
+
# @return [Array<(CompletionsCreate200Response, Integer, Hash)>] CompletionsCreate200Response data, response status code and response headers
|
118
|
+
def completions_create_with_http_info(deployment_id, api_version, completions_create_request, opts = {})
|
110
119
|
if @api_client.config.debugging
|
111
120
|
@api_client.config.logger.debug 'Calling API: DefaultApi.completions_create ...'
|
112
121
|
end
|
113
|
-
# verify the required parameter '
|
114
|
-
if @api_client.config.client_side_validation &&
|
115
|
-
fail ArgumentError, "Missing the required parameter '
|
122
|
+
# verify the required parameter 'deployment_id' is set
|
123
|
+
if @api_client.config.client_side_validation && deployment_id.nil?
|
124
|
+
fail ArgumentError, "Missing the required parameter 'deployment_id' when calling DefaultApi.completions_create"
|
116
125
|
end
|
117
126
|
# verify the required parameter 'api_version' is set
|
118
127
|
if @api_client.config.client_side_validation && api_version.nil?
|
119
128
|
fail ArgumentError, "Missing the required parameter 'api_version' when calling DefaultApi.completions_create"
|
120
129
|
end
|
121
|
-
# verify the required parameter '
|
122
|
-
if @api_client.config.client_side_validation &&
|
123
|
-
fail ArgumentError, "Missing the required parameter '
|
130
|
+
# verify the required parameter 'completions_create_request' is set
|
131
|
+
if @api_client.config.client_side_validation && completions_create_request.nil?
|
132
|
+
fail ArgumentError, "Missing the required parameter 'completions_create_request' when calling DefaultApi.completions_create"
|
124
133
|
end
|
125
134
|
# resource path
|
126
|
-
local_var_path = '/deployments/{deployment-id}/completions'.sub('{' + 'deployment-id' + '}', deployment_id.to_s)
|
135
|
+
local_var_path = '/deployments/{deployment-id}/completions'.sub('{' + 'deployment-id' + '}', CGI.escape(deployment_id.to_s))
|
127
136
|
|
128
137
|
# query parameters
|
129
138
|
query_params = opts[:query_params] || {}
|
@@ -134,25 +143,34 @@ module AzureOpenaiClient
|
|
134
143
|
# HTTP header 'Accept' (if needed)
|
135
144
|
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
136
145
|
# HTTP header 'Content-Type'
|
137
|
-
|
146
|
+
content_type = @api_client.select_header_content_type(['application/json'])
|
147
|
+
if !content_type.nil?
|
148
|
+
header_params['Content-Type'] = content_type
|
149
|
+
end
|
138
150
|
|
139
151
|
# form parameters
|
140
152
|
form_params = opts[:form_params] || {}
|
141
153
|
|
142
154
|
# http body (model)
|
143
|
-
post_body = opts[:
|
155
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(completions_create_request)
|
156
|
+
|
157
|
+
# return_type
|
158
|
+
return_type = opts[:debug_return_type] || 'CompletionsCreate200Response'
|
144
159
|
|
145
|
-
|
160
|
+
# auth_names
|
161
|
+
auth_names = opts[:debug_auth_names] || ['apiKey', 'bearer']
|
146
162
|
|
147
|
-
|
148
|
-
|
149
|
-
header_params
|
150
|
-
query_params
|
151
|
-
form_params
|
152
|
-
body
|
153
|
-
auth_names
|
154
|
-
return_type
|
163
|
+
new_options = opts.merge(
|
164
|
+
:operation => :"DefaultApi.completions_create",
|
165
|
+
:header_params => header_params,
|
166
|
+
:query_params => query_params,
|
167
|
+
:form_params => form_params,
|
168
|
+
:body => post_body,
|
169
|
+
:auth_names => auth_names,
|
170
|
+
:return_type => return_type
|
171
|
+
)
|
155
172
|
|
173
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
156
174
|
if @api_client.config.debugging
|
157
175
|
@api_client.config.logger.debug "API called: DefaultApi#completions_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
158
176
|
end
|
@@ -160,40 +178,40 @@ module AzureOpenaiClient
|
|
160
178
|
end
|
161
179
|
|
162
180
|
# Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
|
163
|
-
# @param
|
164
|
-
# @param api_version
|
165
|
-
# @param
|
181
|
+
# @param deployment_id [String] The deployment id of the model which was deployed.
|
182
|
+
# @param api_version [String]
|
183
|
+
# @param request_body [Hash<String, Object>]
|
166
184
|
# @param [Hash] opts the optional parameters
|
167
|
-
# @return [
|
168
|
-
def embeddings_create(
|
169
|
-
data, _status_code, _headers = embeddings_create_with_http_info(
|
185
|
+
# @return [EmbeddingsCreate200Response]
|
186
|
+
def embeddings_create(deployment_id, api_version, request_body, opts = {})
|
187
|
+
data, _status_code, _headers = embeddings_create_with_http_info(deployment_id, api_version, request_body, opts)
|
170
188
|
data
|
171
189
|
end
|
172
190
|
|
173
191
|
# Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
|
174
|
-
# @param
|
175
|
-
# @param api_version
|
176
|
-
# @param
|
192
|
+
# @param deployment_id [String] The deployment id of the model which was deployed.
|
193
|
+
# @param api_version [String]
|
194
|
+
# @param request_body [Hash<String, Object>]
|
177
195
|
# @param [Hash] opts the optional parameters
|
178
|
-
# @return [Array<(
|
179
|
-
def embeddings_create_with_http_info(
|
196
|
+
# @return [Array<(EmbeddingsCreate200Response, Integer, Hash)>] EmbeddingsCreate200Response data, response status code and response headers
|
197
|
+
def embeddings_create_with_http_info(deployment_id, api_version, request_body, opts = {})
|
180
198
|
if @api_client.config.debugging
|
181
199
|
@api_client.config.logger.debug 'Calling API: DefaultApi.embeddings_create ...'
|
182
200
|
end
|
183
|
-
# verify the required parameter '
|
184
|
-
if @api_client.config.client_side_validation &&
|
185
|
-
fail ArgumentError, "Missing the required parameter '
|
201
|
+
# verify the required parameter 'deployment_id' is set
|
202
|
+
if @api_client.config.client_side_validation && deployment_id.nil?
|
203
|
+
fail ArgumentError, "Missing the required parameter 'deployment_id' when calling DefaultApi.embeddings_create"
|
186
204
|
end
|
187
205
|
# verify the required parameter 'api_version' is set
|
188
206
|
if @api_client.config.client_side_validation && api_version.nil?
|
189
207
|
fail ArgumentError, "Missing the required parameter 'api_version' when calling DefaultApi.embeddings_create"
|
190
208
|
end
|
191
|
-
# verify the required parameter '
|
192
|
-
if @api_client.config.client_side_validation &&
|
193
|
-
fail ArgumentError, "Missing the required parameter '
|
209
|
+
# verify the required parameter 'request_body' is set
|
210
|
+
if @api_client.config.client_side_validation && request_body.nil?
|
211
|
+
fail ArgumentError, "Missing the required parameter 'request_body' when calling DefaultApi.embeddings_create"
|
194
212
|
end
|
195
213
|
# resource path
|
196
|
-
local_var_path = '/deployments/{deployment-id}/embeddings'.sub('{' + 'deployment-id' + '}', deployment_id.to_s)
|
214
|
+
local_var_path = '/deployments/{deployment-id}/embeddings'.sub('{' + 'deployment-id' + '}', CGI.escape(deployment_id.to_s))
|
197
215
|
|
198
216
|
# query parameters
|
199
217
|
query_params = opts[:query_params] || {}
|
@@ -204,25 +222,34 @@ module AzureOpenaiClient
|
|
204
222
|
# HTTP header 'Accept' (if needed)
|
205
223
|
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
206
224
|
# HTTP header 'Content-Type'
|
207
|
-
|
225
|
+
content_type = @api_client.select_header_content_type(['application/json'])
|
226
|
+
if !content_type.nil?
|
227
|
+
header_params['Content-Type'] = content_type
|
228
|
+
end
|
208
229
|
|
209
230
|
# form parameters
|
210
231
|
form_params = opts[:form_params] || {}
|
211
232
|
|
212
233
|
# http body (model)
|
213
|
-
post_body = opts[:
|
234
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(request_body)
|
235
|
+
|
236
|
+
# return_type
|
237
|
+
return_type = opts[:debug_return_type] || 'EmbeddingsCreate200Response'
|
214
238
|
|
215
|
-
|
239
|
+
# auth_names
|
240
|
+
auth_names = opts[:debug_auth_names] || ['apiKey', 'bearer']
|
216
241
|
|
217
|
-
|
218
|
-
|
219
|
-
header_params
|
220
|
-
query_params
|
221
|
-
form_params
|
222
|
-
body
|
223
|
-
auth_names
|
224
|
-
return_type
|
242
|
+
new_options = opts.merge(
|
243
|
+
:operation => :"DefaultApi.embeddings_create",
|
244
|
+
:header_params => header_params,
|
245
|
+
:query_params => query_params,
|
246
|
+
:form_params => form_params,
|
247
|
+
:body => post_body,
|
248
|
+
:auth_names => auth_names,
|
249
|
+
:return_type => return_type
|
250
|
+
)
|
225
251
|
|
252
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
226
253
|
if @api_client.config.debugging
|
227
254
|
@api_client.config.logger.debug "API called: DefaultApi#embeddings_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
228
255
|
end
|
@@ -1,22 +1,21 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
=begin
|
4
2
|
#Azure OpenAI Service API
|
5
3
|
|
6
4
|
#Azure OpenAI APIs for completions and search
|
7
5
|
|
8
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: 2023-05-15
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
9
10
|
|
10
|
-
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
11
|
-
Swagger Codegen version: 3.0.42
|
12
11
|
=end
|
13
12
|
|
14
13
|
require 'date'
|
15
14
|
require 'json'
|
16
15
|
require 'logger'
|
17
16
|
require 'tempfile'
|
17
|
+
require 'time'
|
18
18
|
require 'typhoeus'
|
19
|
-
require 'uri'
|
20
19
|
|
21
20
|
module AzureOpenaiClient
|
22
21
|
class ApiClient
|
@@ -32,7 +31,7 @@ module AzureOpenaiClient
|
|
32
31
|
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
33
32
|
def initialize(config = Configuration.default)
|
34
33
|
@config = config
|
35
|
-
@user_agent = "
|
34
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
36
35
|
@default_headers = {
|
37
36
|
'Content-Type' => 'application/json',
|
38
37
|
'User-Agent' => @user_agent
|
@@ -60,12 +59,12 @@ module AzureOpenaiClient
|
|
60
59
|
fail ApiError.new('Connection timed out')
|
61
60
|
elsif response.code == 0
|
62
61
|
# Errors from libcurl will be made visible here
|
63
|
-
fail ApiError.new(code
|
64
|
-
message
|
62
|
+
fail ApiError.new(:code => 0,
|
63
|
+
:message => response.return_message)
|
65
64
|
else
|
66
|
-
fail ApiError.new(code
|
67
|
-
response_headers
|
68
|
-
response_body
|
65
|
+
fail ApiError.new(:code => response.code,
|
66
|
+
:response_headers => response.headers,
|
67
|
+
:response_body => response.body),
|
69
68
|
response.status_message
|
70
69
|
end
|
71
70
|
end
|
@@ -88,12 +87,13 @@ module AzureOpenaiClient
|
|
88
87
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
89
88
|
# @return [Typhoeus::Request] A Typhoeus Request
|
90
89
|
def build_request(http_method, path, opts = {})
|
91
|
-
url = build_request_url(path)
|
90
|
+
url = build_request_url(path, opts)
|
92
91
|
http_method = http_method.to_sym.downcase
|
93
92
|
|
94
93
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
95
94
|
query_params = opts[:query_params] || {}
|
96
95
|
form_params = opts[:form_params] || {}
|
96
|
+
follow_location = opts[:follow_location] || true
|
97
97
|
|
98
98
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
99
99
|
|
@@ -101,16 +101,17 @@ module AzureOpenaiClient
|
|
101
101
|
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
102
102
|
|
103
103
|
req_opts = {
|
104
|
-
method
|
105
|
-
headers
|
106
|
-
params
|
107
|
-
params_encoding
|
108
|
-
timeout
|
109
|
-
ssl_verifypeer
|
110
|
-
ssl_verifyhost
|
111
|
-
sslcert
|
112
|
-
sslkey
|
113
|
-
verbose
|
104
|
+
:method => http_method,
|
105
|
+
:headers => header_params,
|
106
|
+
:params => query_params,
|
107
|
+
:params_encoding => @config.params_encoding,
|
108
|
+
:timeout => @config.timeout,
|
109
|
+
:ssl_verifypeer => @config.verify_ssl,
|
110
|
+
:ssl_verifyhost => _verify_ssl_host,
|
111
|
+
:sslcert => @config.cert_file,
|
112
|
+
:sslkey => @config.key_file,
|
113
|
+
:verbose => @config.debugging,
|
114
|
+
:followlocation => follow_location
|
114
115
|
}
|
115
116
|
|
116
117
|
# set custom cert, if provided
|
@@ -118,7 +119,7 @@ module AzureOpenaiClient
|
|
118
119
|
|
119
120
|
if [:post, :patch, :put, :delete].include?(http_method)
|
120
121
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
121
|
-
req_opts.update body
|
122
|
+
req_opts.update :body => req_body
|
122
123
|
if @config.debugging
|
123
124
|
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
124
125
|
end
|
@@ -157,6 +158,44 @@ module AzureOpenaiClient
|
|
157
158
|
data
|
158
159
|
end
|
159
160
|
|
161
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
162
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
163
|
+
# The response body is written to the file in chunks in order to handle files which
|
164
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
165
|
+
# process can use.
|
166
|
+
#
|
167
|
+
# @see Configuration#temp_folder_path
|
168
|
+
def download_file(request)
|
169
|
+
tempfile = nil
|
170
|
+
encoding = nil
|
171
|
+
request.on_headers do |response|
|
172
|
+
content_disposition = response.headers['Content-Disposition']
|
173
|
+
if content_disposition && content_disposition =~ /filename=/i
|
174
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
175
|
+
prefix = sanitize_filename(filename)
|
176
|
+
else
|
177
|
+
prefix = 'download-'
|
178
|
+
end
|
179
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
180
|
+
encoding = response.body.encoding
|
181
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
182
|
+
@tempfile = tempfile
|
183
|
+
end
|
184
|
+
request.on_body do |chunk|
|
185
|
+
chunk.force_encoding(encoding)
|
186
|
+
tempfile.write(chunk)
|
187
|
+
end
|
188
|
+
request.on_complete do |response|
|
189
|
+
if tempfile
|
190
|
+
tempfile.close
|
191
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
192
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
193
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
194
|
+
"explicitly with `tempfile.delete`"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
160
199
|
# Check if the given MIME is a JSON MIME.
|
161
200
|
# JSON MIME examples:
|
162
201
|
# application/json
|
@@ -191,9 +230,9 @@ module AzureOpenaiClient
|
|
191
230
|
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
192
231
|
|
193
232
|
begin
|
194
|
-
data = JSON.parse("[#{body}]", symbolize_names
|
233
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
195
234
|
rescue JSON::ParserError => e
|
196
|
-
if %w(String Date
|
235
|
+
if %w(String Date Time).include?(return_type)
|
197
236
|
data = body
|
198
237
|
else
|
199
238
|
raise e
|
@@ -218,9 +257,9 @@ module AzureOpenaiClient
|
|
218
257
|
data.to_f
|
219
258
|
when 'Boolean'
|
220
259
|
data == true
|
221
|
-
when '
|
260
|
+
when 'Time'
|
222
261
|
# parse date time (expecting ISO 8601 format)
|
223
|
-
|
262
|
+
Time.parse data
|
224
263
|
when 'Date'
|
225
264
|
# parse date time (expecting ISO 8601 format)
|
226
265
|
Date.parse data
|
@@ -238,46 +277,9 @@ module AzureOpenaiClient
|
|
238
277
|
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
239
278
|
end
|
240
279
|
else
|
241
|
-
# models
|
242
|
-
AzureOpenaiClient.const_get(return_type)
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
247
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
248
|
-
# The response body is written to the file in chunks in order to handle files which
|
249
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
250
|
-
# process can use.
|
251
|
-
#
|
252
|
-
# @see Configuration#temp_folder_path
|
253
|
-
def download_file(request)
|
254
|
-
tempfile = nil
|
255
|
-
encoding = nil
|
256
|
-
request.on_headers do |response|
|
257
|
-
content_disposition = response.headers['Content-Disposition']
|
258
|
-
if content_disposition && content_disposition =~ /filename=/i
|
259
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
260
|
-
prefix = sanitize_filename(filename)
|
261
|
-
else
|
262
|
-
prefix = 'download-'
|
263
|
-
end
|
264
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
265
|
-
encoding = response.body.encoding
|
266
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
267
|
-
@tempfile = tempfile
|
268
|
-
end
|
269
|
-
request.on_body do |chunk|
|
270
|
-
chunk.force_encoding(encoding)
|
271
|
-
tempfile.write(chunk)
|
272
|
-
end
|
273
|
-
request.on_complete do |response|
|
274
|
-
if tempfile
|
275
|
-
tempfile.close
|
276
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
277
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
278
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
279
|
-
"explicitly with `tempfile.delete`"
|
280
|
-
end
|
280
|
+
# models (e.g. Pet) or oneOf
|
281
|
+
klass = AzureOpenaiClient.const_get(return_type)
|
282
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
281
283
|
end
|
282
284
|
end
|
283
285
|
|
@@ -290,13 +292,13 @@ module AzureOpenaiClient
|
|
290
292
|
filename.gsub(/.*[\/\\]/, '')
|
291
293
|
end
|
292
294
|
|
293
|
-
def build_request_url(path)
|
295
|
+
def build_request_url(path, opts = {})
|
294
296
|
# Add leading and trailing slashes to path
|
295
297
|
path = "/#{path}".gsub(/\/+/, '/')
|
296
|
-
@config.base_url + path
|
298
|
+
@config.base_url(opts[:operation]) + path
|
297
299
|
end
|
298
300
|
|
299
|
-
# Update
|
301
|
+
# Update header and query params based on authentication settings.
|
300
302
|
#
|
301
303
|
# @param [Hash] header_params Header parameters
|
302
304
|
# @param [Hash] query_params Query parameters
|
@@ -308,14 +310,14 @@ module AzureOpenaiClient
|
|
308
310
|
case auth_setting[:in]
|
309
311
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
310
312
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
311
|
-
else fail ArgumentError, 'Authentication token must be in `query`
|
313
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
312
314
|
end
|
313
315
|
end
|
314
316
|
end
|
315
317
|
|
316
318
|
# Sets user agent in HTTP header
|
317
319
|
#
|
318
|
-
# @param [String] user_agent User agent (e.g.
|
320
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
319
321
|
def user_agent=(user_agent)
|
320
322
|
@user_agent = user_agent
|
321
323
|
@default_headers['User-Agent'] = @user_agent
|
@@ -335,8 +337,8 @@ module AzureOpenaiClient
|
|
335
337
|
# @param [Array] content_types array for Content-Type
|
336
338
|
# @return [String] the Content-Type header (e.g. application/json)
|
337
339
|
def select_header_content_type(content_types)
|
338
|
-
#
|
339
|
-
return
|
340
|
+
# return nil by default
|
341
|
+
return if content_types.nil? || content_types.empty?
|
340
342
|
# use JSON when present, otherwise use the first one
|
341
343
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
342
344
|
json_content_type || content_types.first
|
@@ -1,14 +1,13 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
=begin
|
4
2
|
#Azure OpenAI Service API
|
5
3
|
|
6
4
|
#Azure OpenAI APIs for completions and search
|
7
5
|
|
8
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: 2023-05-15
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
9
10
|
|
10
|
-
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
11
|
-
Swagger Codegen version: 3.0.42
|
12
11
|
=end
|
13
12
|
|
14
13
|
module AzureOpenaiClient
|
@@ -33,6 +32,7 @@ module AzureOpenaiClient
|
|
33
32
|
end
|
34
33
|
else
|
35
34
|
super arg
|
35
|
+
@message = arg
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|