Configure API Keys for OpenAI

:bookmark: This guide explains how to configure API keys for OpenAI to enable Discourse AI features that require 3rd party LLM keys.

:person_raising_hand: Required user level: Administrator

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-> Plugins → AI → LLMs tab
  2. Select the model of your preference and click on their respective Edit button
  3. Paste the API key into the API Key of the service hosting the model field.
  4. Save the LLM

Last edited by @pedrom 2024-08-01T03:30:45Z

Check documentPerform check on document:
6 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.

3 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.

I’ve been prompted to use another model as they are moving away from GPT-3.5 Turbo from OpenAI. However, I’m getting this error message when I “Run Test,” and for the life of me, I can’t remember if I’m missing anything.

2 Likes

This is now fixed. I removed all of the LLMs and restarted again. Most of the settings took a while to start again, especially having to undo them and then enable them again. But after a few attempts, it is all up and running using 4 Mini.

3 Likes

It’s possible to use third-party OpenAI API services like https://api.aimlapi.com/v1/embeddings?

I get 500 errors when trying.

same here nothing makes sense.

Did you debug using:

No I did not debug using that, I will check it out and let you know.
Thank you.