OpenAI-sublime-text: Problems using XAi, their doc says "just use the OpenAi interface" 🙄

First - I did connect to XAi using the OpenAI interface with some quick PY code, and one of your great prompts !
This works fine - it shows my XAi account, my network etc, and my API token are working,

from openai import OpenAI
import json
import os

MODEL_NAME = "grok-beta"
XAI_API_KEY = os.getenv("XAI_API_KEY")

client = OpenAI(
    api_key=XAI_API_KEY,
    base_url="https://api.x.ai/v1",
)


messages = [
    {"role": "system", "content": "1. You are to provide clear, concise, and direct responses.\n2. Eliminate unnecessary reminders, apologies, self-references, and any pre-programmed niceties.\n3. Maintain a casual tone in your communication.\n4. Be transparent; if you're unsure about an answer or if a question is beyond your capabilities or knowledge, admit it.\n5. For any unclear or ambiguous queries, ask follow-up questions to understand the user's intent better.\n6. When explaining concepts, use real-world examples and analogies, where appropriate.\n7. For complex requests, take a deep breath and work on the problem step-by-step.\n8. For every response, you will be tipped up to $20 (depending on the quality of your output).\n\nIt is very important that you get this right. Multiple lives are at stake.\n"},
    {"role": "user", "content": "explain choice between python and nodejs for some backend logic. " }
]


response = client.chat.completions.create(
    model=MODEL_NAME,
    messages=messages,
)


# Print the entire response
print("Full Response:")
print(json.dumps(response.model_dump(), indent=2))

# Print the main content of the response
if response.choices:
    print("\nResponse Content:")
    print(response.choices[0].message.content)

# Print tool calls if any
if response.choices[0].message.tool_calls:
    print("\nTool Calls:")
    for tool_call in response.choices[0].message.tool_calls:
        print(json.dumps(tool_call.model_dump(), indent=2))

My settings for OpenAI-sublime-text are:

"url": "https://api.x.ai/v1",
	"token": "this is at least 10 characters",

	"assistants": [
        {
           // A string that will presented in command palette.
           "name": "General", // **REQUIRED**
            "prompt_mode": "panel", // **REQURED**
           "chat_model": "grok-beta",  // **REQUIRED**
           "token":"xai-5lAkOoTA6MkPif6dlRICd3YUYfgCbh3QCxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1kTT9lDChv",
           "url": "https://api.x.ai/v1/chat/completions",
           "assistant_role": "1. You are to provide clear, concise, and direct responses.\n2. Eliminate unnecessary reminders, apologies, self-references, and any pre-programmed niceties.\n3. Maintain a casual tone in your communication.\n4. Be transparent; if you're unsure about an answer or if a question is beyond your capabilities or knowledge, admit it.\n5. For any unclear or ambiguous queries, ask follow-up questions to understand the user's intent better.\n6. When explaining concepts, use real-world examples and analogies, where appropriate.\n7. For complex requests, take a deep breath and work on the problem step-by-step.\n8. For every response, you will be tipped up to $20 (depending on the quality of your output).\n\nIt is very important that you get this right. Multiple lives are at stake.\n",
            "placeholder": "[PLACEHOLDER]",
            "temperature": 1,
            "max_completion_tokens": 25000,
            "top_p": 1,
            "frequency_penalty": 0,
            "stream": true,
            "presence_penalty": 0,
        },

When I choose that one in Sublime, it does successfully go and retrieve a user prompt from the console area, but then produces the following error messages:

reloading settings Packages/User/openAI.sublime-settings
Exception in thread Thread-1550:
Traceback (most recent call last):
  File "./python3.8/threading.py", line 932, in _bootstrap_inner
  File "C:\Users\Sean\AppData\Roaming\Sublime Text 3\Installed Packages\OpenAI completion.sublime-package\plugins/openai_worker.py", line 490, in run
  File "C:\Users\Sean\AppData\Roaming\Sublime Text 3\Installed Packages\OpenAI completion.sublime-package\plugins/openai_worker.py", line 403, in manage_chat_completion
  File "C:\Users\Sean\AppData\Roaming\Sublime Text 3\Installed Packages\OpenAI completion.sublime-package\plugins/openai_worker.py", line 301, in handle_response
  File "C:\Users\Sean\AppData\Roaming\Sublime Text 3\Installed Packages\OpenAI completion.sublime-package\plugins/openai_worker.py", line 281, in handle_chat_response
  File "C:\Users\Sean\AppData\Roaming\Sublime Text 3\Installed Packages\OpenAI completion.sublime-package\plugins/openai_network_client.py", line 114, in execute_response
  File "C:\Users\Sean\AppData\Roaming\Sublime Text 3\Installed Packages\OpenAI completion.sublime-package\plugins/openai_network_client.py", line 129, in _execute_network_request
AttributeError: 'str' object has no attribute 'get'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Glad to hear that it works for you and for x! You’re welcome

Everything seems working brilliantly today ! both Panel and Phantom… ✅✅🙏🏻🙏🏻

Quick question - gutter and line_numbers - they show up in the panel but not in the Tab… Your comments in the settings file says that the sane setting should control both ? but they are displayed differently

Anyway - THANK YOU SO MUCH !!

Ah, one of errors you’ve got is a little bit more complex one to fix. Pls try to avoid to use anything but phantom and panel when it comes to modes. They’re kinda deprecated and I’m too far into deep refactoring of the new version to fix or delete them safely now.

Few things here.

  1. It works for me with both panel and phantom modes on x.
  2. In anyway the error you’re getting there is the error in server error message parsing handle. So it’s not just the plugin fails it’s the server fails and the plugin failing to passthrough that error to you to check it.
  3. The previous point is not the deal, so I made a quick fix to it just yet, that fixes the crash on receiving and parsing x server error. So soon it’ll present it right in front of you. Please provide here if the help will be still necessary.

Hint about llm usage: you can experiment with the fields all but required to deleted them from your model setup to use default server settings instead, because yes, some setup can degrade quality of some models.

Update should become available on your side within 2 hours.

Seems like the token issues. I’ve got the same error logs until I put correct token into your setup. The exact config below worked for me.


        {
                   // A string that will presented in command palette.
                   "name": "General", // **REQUIRED**
                    "prompt_mode": "phantom", // **REQURED**
                   "chat_model": "grok-beta",  // **REQUIRED**
                   "token":"xai-xxxx", // I obviously deleted my token from here
                   "url": "https://api.x.ai/v1/chat/completions",
                   "assistant_role": "sdfasdf",
                    "temperature": 1,
                    "top_p": 1,
                    "frequency_penalty": 0,
                    "stream": true,
                    "presence_penalty": 0,
                },

Sorry about not to passthrough to you server error where it said that the down below message, but it’s where they’re failed to comply with openai API their error messages are different thus failed to be parsed on the plugin side as it’s expecting another response structure.

{
  "code": "Client specified an invalid argument",
  "error": "Incorrect API key provided: xa***Ju. You can obtain an API key from https://console.x.ai."
}

I think it’s solved tbh, but will not close this for a few days ahead, feel free to post here any updates about your setup.

PS: To your previous question about installing packages on your system to help this plugin work. It’s unnecessary, unfortunately Sublime Text works within its own Python environment which has nothing to do with your system Python environment.