-
-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathhttp_headers.rb
43 lines (37 loc) · 848 Bytes
/
http_headers.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
module OpenAI
module HTTPHeaders
def add_headers(headers)
@extra_headers = extra_headers.merge(headers.transform_keys(&:to_s))
end
private
def headers
if azure?
azure_headers
else
openai_headers
end.merge(extra_headers)
end
def openai_headers
{
"Content-Type" => "application/json",
"Authorization" => "Bearer #{@access_token}",
"OpenAI-Organization" => @organization_id
}.compact
end
def openai_realtime_headers
{
"Authorization" => "Bearer #{@client.access_token}",
"OpenAI-Beta" => "realtime=v1"
}
end
def azure_headers
{
"Content-Type" => "application/json",
"api-key" => @access_token
}
end
def extra_headers
@extra_headers ||= {}
end
end
end