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

Failed to Enter Dummy OpenAI API Key On First Use - Now Won't Run At All Or Generates Error Message #585

Closed
richardstevenhack opened this issue Jun 27, 2024 · 2 comments

Comments

@richardstevenhack
Copy link

I overlooked the Ollama instruction to enter a random string for the prompt for OpenAI API key on first use. So of course the program crashed.

I then ran it again - now it just crashes without prompting for the API key.

I then updated the .sgptrc config file to enter the string "alalalal" in the OpenAI API Key field.

I then ran "rhack@localhost:/Data2/Work> sgpt --model qwen2:latest "Who are you?"". That generated a massive pile of error messages, ending with the message:
AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: alalalala. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

This is the full output of the command above:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/sgpt/app.py:229 in │ │ main │ │ │ │ 226 │ │ │ functions=function_schemas, │ │ 227 │ │ ) │ │ 228 │ else: │ │ ❱ 229 │ │ full_completion = DefaultHandler(role_class, md).handle( │ │ 230 │ │ │ prompt=prompt, │ │ 231 │ │ │ model=model, │ │ 232 │ │ │ temperature=temperature, │ │ │ │ ╭─────────────────────────────── locals ────────────────────────────────╮ │ │ │ cache = True │ │ │ │ chat = None │ │ │ │ code = False │ │ │ │ create_role = None │ │ │ │ describe_shell = False │ │ │ │ editor = False │ │ │ │ function_schemas = None │ │ │ │ functions = True │ │ │ │ install_functions = None │ │ │ │ install_integration = None │ │ │ │ interaction = True │ │ │ │ list_chats = None │ │ │ │ list_roles = None │ │ │ │ md = True │ │ │ │ model = 'qwen2:latest' │ │ │ │ prompt = 'Who are you?' │ │ │ │ repl = None │ │ │ │ role = None │ │ │ │ role_class = <sgpt.role.SystemRole object at 0x7f2ed2ac2e50> │ │ │ │ shell = False │ │ │ │ show_chat = None │ │ │ │ show_role = None │ │ │ │ stdin_passed = False │ │ │ │ temperature = 0.0 │ │ │ │ top_p = 1.0 │ │ │ │ version = None │ │ │ ╰───────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/sgpt/handlers/handl │ │ er.py:158 in handle │ │ │ │ 155 │ │ │ caching=caching, │ │ 156 │ │ │ **kwargs, │ │ 157 │ │ ) │ │ ❱ 158 │ │ return self.printer(generator, not disable_stream) │ │ 159 │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ caching = True │ │ │ │ disable_stream = False │ │ │ │ functions = None │ │ │ │ generator = <generator object Cache.__call__.<locals>.wrapper at 0x7f2ed2edef80> │ │ │ │ kwargs = {} │ │ │ │ messages = [ │ │ │ │ │ { │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ }, │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ ] │ │ │ │ model = 'qwen2:latest' │ │ │ │ prompt = 'Who are you?' │ │ │ │ self = <sgpt.handlers.default_handler.DefaultHandler object at 0x7f2ed2ac2890> │ │ │ │ temperature = 0.0 │ │ │ │ top_p = 1.0 │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/sgpt/printer.py:23 │ │ in __call__ │ │ │ │ 20 │ │ │ 21 │ def __call__(self, chunks: Generator[str, None, None], live: bool = True) -> str: │ │ 22 │ │ if live: │ │ ❱ 23 │ │ │ return self.live_print(chunks) │ │ 24 │ │ with self.console.status("[bold green]Loading..."): │ │ 25 │ │ │ full_completion = "".join(chunks) │ │ 26 │ │ self.static_print(full_completion) │ │ │ │ ╭─────────────────────────────────── locals ────────────────────────────────────╮ │ │ │ chunks = <generator object Cache.__call__.<locals>.wrapper at 0x7f2ed2edef80> │ │ │ │ live = True │ │ │ │ self = <sgpt.printer.MarkdownPrinter object at 0x7f2ed2ac23d0> │ │ │ ╰───────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/sgpt/printer.py:38 │ │ in live_print │ │ │ │ 35 │ def live_print(self, chunks: Generator[str, None, None]) -> str: │ │ 36 │ │ full_completion = "" │ │ 37 │ │ with Live(console=self.console) as live: │ │ ❱ 38 │ │ │ for chunk in chunks: │ │ 39 │ │ │ │ full_completion += chunk │ │ 40 │ │ │ │ markdown = Markdown(markup=full_completion, code_theme=self.theme) │ │ 41 │ │ │ │ live.update(markdown, refresh=True) │ │ │ │ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮ │ │ │ chunks = <generator object Cache.__call__.<locals>.wrapper at 0x7f2ed2edef80> │ │ │ │ full_completion = '' │ │ │ │ live = <rich.live.Live object at 0x7f2ed2ac26d0> │ │ │ │ self = <sgpt.printer.MarkdownPrinter object at 0x7f2ed2ac23d0> │ │ │ ╰────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/sgpt/cache.py:37 in │ │ wrapper │ │ │ │ 34 │ │ │ │ yield file.read_text() │ │ 35 │ │ │ │ return │ │ 36 │ │ │ result = "" │ │ ❱ 37 │ │ │ for i in func(*args, **kwargs): │ │ 38 │ │ │ │ result += i │ │ 39 │ │ │ │ yield i │ │ 40 │ │ │ if "@FunctionCall" not in result: │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ args = (<sgpt.handlers.default_handler.DefaultHandler object at 0x7f2ed2ac2890>,) │ │ │ │ file = PosixPath('/tmp/cache/70734d248360d944a0dd919690a83b45') │ │ │ │ func = <function Handler.get_completion at 0x7f2ed2ab8cc0> │ │ │ │ key = '70734d248360d944a0dd919690a83b45' │ │ │ │ kwargs = { │ │ │ │ │ 'model': 'qwen2:latest', │ │ │ │ │ 'temperature': 0.0, │ │ │ │ │ 'top_p': 1.0, │ │ │ │ │ 'messages': [ │ │ │ │ │ │ { │ │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ │ }, │ │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ │ ], │ │ │ │ │ 'functions': None │ │ │ │ } │ │ │ │ result = '' │ │ │ │ self = <sgpt.cache.Cache object at 0x7f2ed2ab76d0> │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/sgpt/handlers/handl │ │ er.py:99 in get_completion │ │ │ │ 96 │ │ if is_shell_role or is_code_role or is_dsc_shell_role: │ │ 97 │ │ │ functions = None │ │ 98 │ │ │ │ ❱ 99 │ │ response = completion( │ │ 100 │ │ │ model=model, │ │ 101 │ │ │ temperature=temperature, │ │ 102 │ │ │ top_p=top_p, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ arguments = '' │ │ │ │ functions = None │ │ │ │ is_code_role = False │ │ │ │ is_dsc_shell_role = False │ │ │ │ is_shell_role = False │ │ │ │ messages = [ │ │ │ │ │ { │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ }, │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ ] │ │ │ │ model = 'qwen2:latest' │ │ │ │ name = '' │ │ │ │ self = <sgpt.handlers.default_handler.DefaultHandler object at 0x7f2ed2ac2890> │ │ │ │ temperature = 0.0 │ │ │ │ top_p = 1.0 │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/openai/_utils/_util │ │ s.py:277 in wrapper │ │ │ │ 274 │ │ │ │ │ else: │ │ 275 │ │ │ │ │ │ msg = f"Missing required argument: {quote(missing[0])}" │ │ 276 │ │ │ │ raise TypeError(msg) │ │ ❱ 277 │ │ │ return func(*args, **kwargs) │ │ 278 │ │ │ │ 279 │ │ return wrapper # type: ignore │ │ 280 │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ _ = <openai.resources.chat.completions.Completions object at 0x7f2ed2ab7490> │ │ │ │ args = (<openai.resources.chat.completions.Completions object at 0x7f2ed2ab7490>,) │ │ │ │ func = <function Completions.create at 0x7f2ed2c24180> │ │ │ │ given_params = {'top_p', 'functions', 'model', 'self', 'temperature', 'stream', 'messages'} │ │ │ │ i = 0 │ │ │ │ key = 'stream' │ │ │ │ kwargs = { │ │ │ │ │ 'model': 'qwen2:latest', │ │ │ │ │ 'temperature': 0.0, │ │ │ │ │ 'top_p': 1.0, │ │ │ │ │ 'messages': [ │ │ │ │ │ │ { │ │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ │ }, │ │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ │ ], │ │ │ │ │ 'functions': None, │ │ │ │ │ 'stream': True │ │ │ │ } │ │ │ │ matches = True │ │ │ │ positional = ['self'] │ │ │ │ variant = ['messages', 'model'] │ │ │ │ variants = (['messages', 'model'], ['messages', 'model', 'stream']) │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/openai/resources/ch │ │ at/completions.py:643 in create │ │ │ │ 640 │ │ extra_body: Body | None = None, │ │ 641 │ │ timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, │ │ 642 │ ) -> ChatCompletion | Stream[ChatCompletionChunk]: │ │ ❱ 643 │ │ return self._post( │ │ 644 │ │ │ "/chat/completions", │ │ 645 │ │ │ body=maybe_transform( │ │ 646 │ │ │ │ { │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ extra_body = None │ │ │ │ extra_headers = None │ │ │ │ extra_query = None │ │ │ │ frequency_penalty = NOT_GIVEN │ │ │ │ function_call = NOT_GIVEN │ │ │ │ functions = None │ │ │ │ logit_bias = NOT_GIVEN │ │ │ │ logprobs = NOT_GIVEN │ │ │ │ max_tokens = NOT_GIVEN │ │ │ │ messages = [ │ │ │ │ │ { │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ }, │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ ] │ │ │ │ model = 'qwen2:latest' │ │ │ │ n = NOT_GIVEN │ │ │ │ parallel_tool_calls = NOT_GIVEN │ │ │ │ presence_penalty = NOT_GIVEN │ │ │ │ response_format = NOT_GIVEN │ │ │ │ seed = NOT_GIVEN │ │ │ │ self = <openai.resources.chat.completions.Completions object at │ │ │ │ 0x7f2ed2ab7490> │ │ │ │ service_tier = NOT_GIVEN │ │ │ │ stop = NOT_GIVEN │ │ │ │ stream = True │ │ │ │ stream_options = NOT_GIVEN │ │ │ │ temperature = 0.0 │ │ │ │ timeout = NOT_GIVEN │ │ │ │ tool_choice = NOT_GIVEN │ │ │ │ tools = NOT_GIVEN │ │ │ │ top_logprobs = NOT_GIVEN │ │ │ │ top_p = 1.0 │ │ │ │ user = NOT_GIVEN │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/openai/_base_client │ │ .py:1250 in post │ │ │ │ 1247 │ │ opts = FinalRequestOptions.construct( │ │ 1248 │ │ │ method="post", url=path, json_data=body, files=to_httpx_files(files), **opti │ │ 1249 │ │ ) │ │ ❱ 1250 │ │ return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=str │ │ 1251 │ │ │ 1252 │ def patch( │ │ 1253 │ │ self, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ body = { │ │ │ │ │ 'messages': [ │ │ │ │ │ │ { │ │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ │ }, │ │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ │ ], │ │ │ │ │ 'model': 'qwen2:latest', │ │ │ │ │ 'frequency_penalty': NOT_GIVEN, │ │ │ │ │ 'function_call': NOT_GIVEN, │ │ │ │ │ 'functions': None, │ │ │ │ │ 'logit_bias': NOT_GIVEN, │ │ │ │ │ 'logprobs': NOT_GIVEN, │ │ │ │ │ 'max_tokens': NOT_GIVEN, │ │ │ │ │ 'n': NOT_GIVEN, │ │ │ │ │ 'parallel_tool_calls': NOT_GIVEN, │ │ │ │ │ ... +13 │ │ │ │ } │ │ │ │ cast_to = <class 'openai.types.chat.chat_completion.ChatCompletion'> │ │ │ │ files = None │ │ │ │ options = {} │ │ │ │ opts = FinalRequestOptions( │ │ │ │ │ method='post', │ │ │ │ │ url='/chat/completions', │ │ │ │ │ params={}, │ │ │ │ │ headers=NOT_GIVEN, │ │ │ │ │ max_retries=NOT_GIVEN, │ │ │ │ │ timeout=NOT_GIVEN, │ │ │ │ │ files=None, │ │ │ │ │ idempotency_key=None, │ │ │ │ │ post_parser=NOT_GIVEN, │ │ │ │ │ json_data={ │ │ │ │ │ │ 'messages': [ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and system │ │ │ │ administration assistant.\nYou ar'+284 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ │ │ ], │ │ │ │ │ │ 'model': 'qwen2:latest', │ │ │ │ │ │ 'functions': None, │ │ │ │ │ │ 'stream': True, │ │ │ │ │ │ 'temperature': 0.0, │ │ │ │ │ │ 'top_p': 1.0 │ │ │ │ │ }, │ │ │ │ │ extra_json=None │ │ │ │ ) │ │ │ │ path = '/chat/completions' │ │ │ │ self = <openai.OpenAI object at 0x7f2ed4607cd0> │ │ │ │ stream = True │ │ │ │ stream_cls = openai.Stream[openai.types.chat.chat_completion_chunk.ChatCompletionChunk] │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/openai/_base_client │ │ .py:931 in request │ │ │ │ 928 │ │ stream: bool = False, │ │ 929 │ │ stream_cls: type[_StreamT] | None = None, │ │ 930 │ ) -> ResponseT | _StreamT: │ │ ❱ 931 │ │ return self._request( │ │ 932 │ │ │ cast_to=cast_to, │ │ 933 │ │ │ options=options, │ │ 934 │ │ │ stream=stream, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ cast_to = <class 'openai.types.chat.chat_completion.ChatCompletion'> │ │ │ │ options = FinalRequestOptions( │ │ │ │ │ method='post', │ │ │ │ │ url='/chat/completions', │ │ │ │ │ params={}, │ │ │ │ │ headers=NOT_GIVEN, │ │ │ │ │ max_retries=NOT_GIVEN, │ │ │ │ │ timeout=NOT_GIVEN, │ │ │ │ │ files=None, │ │ │ │ │ idempotency_key=None, │ │ │ │ │ post_parser=NOT_GIVEN, │ │ │ │ │ json_data={ │ │ │ │ │ │ 'messages': [ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and │ │ │ │ system administration assistant.\nYou ar'+284 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ │ │ ], │ │ │ │ │ │ 'model': 'qwen2:latest', │ │ │ │ │ │ 'functions': None, │ │ │ │ │ │ 'stream': True, │ │ │ │ │ │ 'temperature': 0.0, │ │ │ │ │ │ 'top_p': 1.0 │ │ │ │ │ }, │ │ │ │ │ extra_json=None │ │ │ │ ) │ │ │ │ remaining_retries = None │ │ │ │ self = <openai.OpenAI object at 0x7f2ed4607cd0> │ │ │ │ stream = True │ │ │ │ stream_cls = openai.Stream[openai.types.chat.chat_completion_chunk.ChatCompletionChu… │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/rhack/.local/share/pipx/venvs/shell-gpt/lib64/python3.11/site-packages/openai/_base_client │ │ .py:1030 in _request │ │ │ │ 1027 │ │ │ │ err.response.read() │ │ 1028 │ │ │ │ │ 1029 │ │ │ log.debug("Re-raising status error") │ │ ❱ 1030 │ │ │ raise self._make_status_error_from_response(err.response) from None │ │ 1031 │ │ │ │ 1032 │ │ return self._process_response( │ │ 1033 │ │ │ cast_to=cast_to, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ cast_to = <class 'openai.types.chat.chat_completion.ChatCompletion'> │ │ │ │ kwargs = {} │ │ │ │ options = FinalRequestOptions( │ │ │ │ │ method='post', │ │ │ │ │ url='/chat/completions', │ │ │ │ │ params={}, │ │ │ │ │ headers=NOT_GIVEN, │ │ │ │ │ max_retries=NOT_GIVEN, │ │ │ │ │ timeout=NOT_GIVEN, │ │ │ │ │ files=None, │ │ │ │ │ idempotency_key=None, │ │ │ │ │ post_parser=NOT_GIVEN, │ │ │ │ │ json_data={ │ │ │ │ │ │ 'messages': [ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ 'role': 'system', │ │ │ │ │ │ │ │ 'content': 'You are ShellGPT\nYou are programming and │ │ │ │ system administration assistant.\nYou ar'+284 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ {'role': 'user', 'content': 'Who are you?'} │ │ │ │ │ │ ], │ │ │ │ │ │ 'model': 'qwen2:latest', │ │ │ │ │ │ 'functions': None, │ │ │ │ │ │ 'stream': True, │ │ │ │ │ │ 'temperature': 0.0, │ │ │ │ │ │ 'top_p': 1.0 │ │ │ │ │ }, │ │ │ │ │ extra_json=None │ │ │ │ ) │ │ │ │ remaining_retries = None │ │ │ │ request = <Request('POST', 'https://api.openai.com/v1/chat/completions')> │ │ │ │ response = <Response [401 Unauthorized]> │ │ │ │ retries = 2 │ │ │ │ self = <openai.OpenAI object at 0x7f2ed4607cd0> │ │ │ │ stream = True │ │ │ │ stream_cls = openai.Stream[openai.types.chat.chat_completion_chunk.ChatCompletionChu… │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: "alalalala". You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} rhack@localhost:/Data2/Work>

@stevenfoster990
Copy link

You need to change the API_BASE_URL in ~/.config/shell_gpt/.sgptrc
You can see 10 lines from the bottom of the error you submitted, your post request is still going to api.openai.com/v1/chat/completions

@richardstevenhack
Copy link
Author

OK, did that. That seems to have fixed that problem. Got another problem after editing the config file. There's already an open issue for that. I'll add my new problem to that thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants