Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to connect to server with auth disabled, still results in error "No API token provided" #64

Closed
knutle opened this issue Oct 14, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@knutle
Copy link
Contributor

knutle commented Oct 14, 2024

Problem: Currently package returns API request error even when server does not require authentication.

Cause: Excessive pre-request validation on token property from package settings.

Desired behavior: Provide a way to allow user to bypass this check when necessary, but still trigger the validation for legitimate cases.

Suggested fix: Allow token property to be empty or omitted from package settings if not required by provider. Either by explicitly setting "token": null, or by adding a separate property like "auth": false.


The error message is triggered by the exception raised on line 472 in the following code snippet.

api_token = self.settings.get('token')
if not isinstance(api_token, str):
raise WrongUserInputException('The token must be a string.')
if len(api_token) < 10:
raise WrongUserInputException(
'No API token provided, you have to set the OpenAI token into the settings to make things work.'
)


Simply ensuring that the token key exists in the plugin config and has any value of length > 10 seems to be a good workaround for now, though it looks like this should be pretty straightforward to fix.

@knutle
Copy link
Contributor Author

knutle commented Oct 14, 2024

Summary + Workaround for End-Users

Caution

There is currently a known issue which will trigger the following error even when connecting to an unsecured server.

"No API token provided, you have to set the OpenAI token into the settings to make things work."

It is highly recommended to enable authentication in most cases, but especially when self-hosting models on your local system this can be inconvenient.

Tip

Use the following workaround to avoid this error until a permanent solution can be released.

Simply ensure your assistant configuration defines a "token", value longer than 10 characters. It can be anything, since the server doesn't care, but must be present to prevent a validation error.

Sample config

{
    "url": "http://localhost:1234", // Url to your unsecured server
    "token": "xxxxxxxxxx", // Token can be anything so long as it is at least 10 characters long
    "assistants": [
        {
            // Inherits token from top-level, no error
            "name": "Code assistant",
            "prompt_mode": "panel",
            "chat_model": "codestral-22b-v0.1",
            "assistant_role": "You are a software developer, you develop software programs and applications using programming languages and development tools.",
            "temperature": 1,
            "max_tokens": 2048,
        },
        {
            // Overrides top-level token incorrectly, will get error
            "name": "Lazy Assistant",
            "token": "",
            "prompt_mode": "phantom",
            "chat_model": "llama-3-8b-instruct-32k-v0.1",
            "assistant_role": "You are very unhelpful.",
            "max_tokens": 4000,
        },
        {
            // Overrides top-level token correctly, no error
            "name": "General Assistant",
            "token": "abcdefghijklmn",
            "prompt_mode": "phantom",
            "chat_model": "llama-3-8b-instruct-32k-v0.1",
            "assistant_role": "You are very helpful.",
            "max_tokens": 4000,
        },
    ]
}

knutle added a commit to knutle/OpenAI-sublime-text that referenced this issue Oct 14, 2024
… mentions including a reference to details to relevant README sections, as well as default sublime-settings template
@knutle knutle changed the title Allow token property to be empty or omitted from package settings if not required by provider Failure to connect to server with auth disabled, still results in error "No API token provided", Oct 14, 2024
@knutle knutle changed the title Failure to connect to server with auth disabled, still results in error "No API token provided", Failure to connect to server with auth disabled, still results in error "No API token provided" Oct 14, 2024
knutle added a commit to knutle/OpenAI-sublime-text that referenced this issue Oct 14, 2024
@yaroslavyaroslav yaroslavyaroslav added the bug Something isn't working label Oct 14, 2024
@yaroslavyaroslav
Copy link
Owner

As long as the docs updated this is actually not a bug but a feature to implement. Originally by some forgotten sense I made this check local, but I think it's really worth it to leave it to the remote server to decide whether or not token is required and if it if what format and length it should be. So I believe those checks could be safely deleted.

@yaroslavyaroslav yaroslavyaroslav added enhancement New feature or request good first issue Good for newcomers and removed bug Something isn't working labels Oct 18, 2024
@yaroslavyaroslav
Copy link
Owner

Fixed in 4.2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants