Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F665043
open_ai.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
895 B
Subscribers
None
open_ai.ex
View Options
defmodule
OpenAi
do
def
post
(
path
,
data
,
options
\\
[])
do
config
=
Application
.
get_env
(
:nola
,
:openai
,
[])
url
=
"https://api.openai.com
#{
path
}
"
headers
=
[{
"user-agent"
,
"internal private experiment bot, href@random.sh"
},
{
"content-type"
,
"application/json"
},
{
"authorization"
,
"Bearer "
<>
Keyword
.
get
(
config
,
:key
,
"unset-api-key"
)}]
options
=
options
++
[
timeout
:
:timer
.
seconds
(
180
),
recv_timeout
:
:timer
.
seconds
(
180
)]
with
{
:ok
,
json
}
<-
Poison
.
encode
(
data
),
{
:ok
,
%
HTTPoison.Response
{
status_code
:
200
,
body
:
body
}}
<-
HTTPoison
.
post
(
url
,
json
,
headers
,
options
),
{
:ok
,
data
}
<-
Poison
.
decode
(
body
)
do
{
:ok
,
data
}
else
{
:ok
,
%
HTTPoison.Response
{
status_code
:
code
}}
->
{
:error
,
Plug.Conn.Status
.
reason_atom
(
code
)}
{
:error
,
%
HTTPoison.Error
{
reason
:
reason
}}
->
{
:error
,
reason
}
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Fri, Feb 27, 7:10 AM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
86698
Default Alt Text
open_ai.ex (895 B)
Attached To
rNOLA Nola
Event Timeline
Log In to Comment