Configure API Keys for OpenAI

OpenAI

In this example, we are using OpenAI to generate the keys.

Note: You will likely need a paid plan and have to pay per usage. See here for up-to-date details and pricing.

Platforms will always change so this guide may not reflect 100% process.

:information_source: In order to use certain AI modules, users must have an API Key from a 3rd party provider such as OpenAI (ChatGPT), Anthropic (Claude), Stability AI (Stable Diffusion), etc.

Please check each AI module to see which 3rd party providers can be used for it.

Generate the API key

  1. Log in to Open AI. An API key can be obtained here OpenAI Platform
  2. Generate the API Key
  3. Once the key is generated, store it in a safe and secure place and copy it

Using API key for Discourse AI

  1. Go to Admin settings from the sidebar or profile and then Plugins
  2. Search or find Discourse AI and click settings
  3. Search or find ai_openai_api_key and input your copied-over key

4 Likes

no matter what we do, it always says openai gpt-4 not configured.

what am i missing?

2 Likes

Where is this popping up for you and I’m assuming you have inputted in the OpenAI key? where there any other settings you have changed? have you tried a refresh on the browser post inputting in the key - does that help?

we have three valid openai keys we use for other things so i know they work.

no matter what we do, this is an example of the rror we get:

What’s the output of running

curl https://api.openai.com/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer $OPENAI_API_KEY"   -d '{
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
      },
      {
        "role": "user",
        "content": "Compose a poem that explains the concept of recursion in programming."
      }
    ]
  }'

in your Discourse server? Don’t forget to place your API key on the command.

2 Likes

will login to our server and check this out.

{
“id”: “chatcmpl-8vT2UYe6i5m9EO0N4KdG6klcO4dVJ”,
“object”: “chat.completion”,
“created”: 1708707014,
“model”: “gpt-4-0613”,
“choices”: [
{
“index”: 0,
“message”: {
“role”: “assistant”,
“content”: “A tale within a tale untold,\nAn echo of a mirrored call,\nSuch is used in software’s sprawl,\nA concept called recursion, all.\n\nImagine a box within a box,\nEach pregnant with the one before,\nEach step to the origin restores,\nInfinite layers, like paradox.\n\nLike Russian dolls, a dream within,\nEach smaller than the one outside,\nYet hiding life within they reside,\nA patterned approach to chaos, therein.\n\nFrom problem to sub-problem, there,\nEach atom is an image proud,\nOf the larger form that’s to be found,\nTwisted whirls of logic’s flare.\n\nConjuring functions that call their own,\nIt tumbles down, a spiral vast,\nBut in the base case, it rests at last,\nThe seeds of recursion thus are sown.\n\nIn every loop’s heart you’ll find,\nA recursion lightly spinning, twined.\nWith every thread of question lined,\nIt folds back on itself, yet unconfined.\n\nBut dear programmers, mind your step,\nInfinite loops are hell’s gateway,\nKeep thy base case in the array,\nThe art of recursion, now adept.\n\nRepeating tasks, yet ever smaller,\nWith each pass, yet closer to end,\nDecomposing problems, our trusted friend,\nRecursion in code, the infinite caller.”
},
“logprobs”: null,
“finish_reason”: “stop”
}
],
“usage”: {
“prompt_tokens”: 39,
“completion_tokens”: 265,
“total_tokens”: 304
},
“system_fingerprint”: null
}

claude-v2 does not return an error.