#Axios + Coffee Script "401 no_text" issue

1 messages · Page 1 of 1 (latest)

distant cove
#

does anyone see anything amiss with this coffeescript? I get an error back "401 no_text" from the API. Probably something to do with how i'm forming the data, but I can't see what:

axios = require('axios')

request_gpt = (chunk) ->
  uri = "https://api.openai.com/v1/chat/completions"

  headers =
    Authorization: "Bearer #{key}"
    'Content-Type': 'application/json'

  data =
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: chunk }
    ]
    model: "gpt-3.5-turbo"
    temperature: 0.5
    max_tokens: 150

  console.log "calling API with a chunk"

  axios.post(uri, data, {headers: headers})
    .then (response) ->
      console.log response.data
    .catch (error) ->
      console.error error

response = request_gpt("hello world")