From bf189a986e0bb4961991f2f781e1b235f626b48c Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Wed, 31 Jul 2024 22:23:31 +0000 Subject: [PATCH 01/24] Added argcomplete to the dependencies Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c4d5bbd1aa..9ea40a584f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,8 @@ dependencies = [ "distro>=1.7.0, <2", "sniffio", "cached-property; python_version < '3.8'", - "tqdm > 4" + "tqdm > 4", + "argcomplete >= 1.12.0" ] requires-python = ">= 3.7.1" classifiers = [ From f75f8a5b7b8f3b13cff4d995f727a6080fe55485 Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:21:02 +0000 Subject: [PATCH 02/24] Added argcomplete to _cli.py Co-authored-by: hoonman Co-authored-by: JesusG2022 --- src/openai/cli/_cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/openai/cli/_cli.py b/src/openai/cli/_cli.py index 72e5c923bd..e5fe983a50 100644 --- a/src/openai/cli/_cli.py +++ b/src/openai/cli/_cli.py @@ -1,8 +1,11 @@ +#!usr/bin/env python +# PYTHON_ARGCOMPLETE_OK from __future__ import annotations import sys import logging import argparse +import argcomplete from typing import Any, List, Type, Optional from typing_extensions import ClassVar @@ -162,6 +165,7 @@ def _parse_args(parser: argparse.ArgumentParser) -> tuple[argparse.Namespace, Ar def _main() -> None: parser = _build_parser() + argcomplete.autocomplete(parser) parsed, args, unknown = _parse_args(parser) if args.verbosity != 0: From 5a7d06e3a9aa9d7317e2d5b7de3328a4713541b9 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:06:55 +0000 Subject: [PATCH 03/24] Added bash command requirement for bash Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 525c1b5aaf..2251688ea0 100644 --- a/README.md +++ b/README.md @@ -642,3 +642,31 @@ We are keen for your feedback; please open an [issue](https://www.github.com/ope ## Requirements Python 3.7 or higher. + +## Activating CLI Autocomplete + +### Using CLI Autocomplete (Temporary) +Using the following sequence of commands for each shell will temporarily activate autocompletion for the CLI. However, when the terminal is restarted or closed, the autocompletion commands will need to be run again to reactivate it. + +#### Bash +1. Install openai if not installed yet. +```shell +pip install openai +``` + +2. Configure your shell to support global auto completion for python scripts by running: +```shell +activate-global-python-argcomplete +``` + +3. Restart your terminal + +4. Register ‘openai’ command for argument completion by running: +```shell +eval "$(register-python-argcomplete openai)" +``` + +5. Try on CLI +```shell +openai +``` From f95433c906b1b2b6b6d7af61c4a66f6143bbfa71 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:19:35 +0000 Subject: [PATCH 04/24] edit readme structure Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2251688ea0..95bfbb1d90 100644 --- a/README.md +++ b/README.md @@ -645,9 +645,8 @@ Python 3.7 or higher. ## Activating CLI Autocomplete -### Using CLI Autocomplete (Temporary) -Using the following sequence of commands for each shell will temporarily activate autocompletion for the CLI. However, when the terminal is restarted or closed, the autocompletion commands will need to be run again to reactivate it. - +### Using CLI Autocomplete +Using the following sequence of commands for each shell will activate the autocompletion feature for the CLI. #### Bash 1. Install openai if not installed yet. ```shell @@ -658,7 +657,6 @@ pip install openai ```shell activate-global-python-argcomplete ``` - 3. Restart your terminal 4. Register ‘openai’ command for argument completion by running: @@ -666,7 +664,32 @@ activate-global-python-argcomplete eval "$(register-python-argcomplete openai)" ``` +Alternatively, run this command to enable argcomplete persistently, eliminating the need to run the eval command every time the terminal is restarted or reloaded. Restart your terminal after using this command. +```shell +register-python-argcomplete openai >> ~/.bashrc +``` + 5. Try on CLI ```shell openai ``` + +#### Powershell +1. Install openai if not installed already. +```shell +pip install openai +``` +2. Create new completion file: +```shell +register-python-argcomplete --shell powershell openai > ~/openai.psm1 +``` + +3. Open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: +```shell +Import-Module "~/openai.psm1" +``` + +4. Restart the terminal and try: +```shell +openai +``` \ No newline at end of file From f724c8b8e6cab6f31b8cc05aab87a3c7cff876b4 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:22:02 +0000 Subject: [PATCH 05/24] edit readme structure Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 95bfbb1d90..9e5bd35c5d 100644 --- a/README.md +++ b/README.md @@ -684,12 +684,17 @@ pip install openai register-python-argcomplete --shell powershell openai > ~/openai.psm1 ``` -3. Open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: +3. If you don't already have a ``$PROFILE`` you can add this by running: +```shell +New-Item -ItemType File -Path $PROFILE -Force +``` + +4. Open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: ```shell Import-Module "~/openai.psm1" ``` -4. Restart the terminal and try: +5. Restart the terminal and try: ```shell openai ``` \ No newline at end of file From 38dc4add19d95f25860456a73dbfb3ac2e5a6439 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:25:04 +0000 Subject: [PATCH 06/24] simplified step to register argcomplete Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 9e5bd35c5d..a8904eee16 100644 --- a/README.md +++ b/README.md @@ -661,11 +661,6 @@ activate-global-python-argcomplete 4. Register ‘openai’ command for argument completion by running: ```shell -eval "$(register-python-argcomplete openai)" -``` - -Alternatively, run this command to enable argcomplete persistently, eliminating the need to run the eval command every time the terminal is restarted or reloaded. Restart your terminal after using this command. -```shell register-python-argcomplete openai >> ~/.bashrc ``` From 9ba029d7956e7c5fdda8c470b5bbdf1396eec45e Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Fri, 2 Aug 2024 22:46:47 +0000 Subject: [PATCH 07/24] refactored readme structure Co-authored-by: hoonman Co-authored-by: JesusG2022 --- README.md | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a8904eee16..39489e0dcf 100644 --- a/README.md +++ b/README.md @@ -639,57 +639,50 @@ We take backwards-compatibility seriously and work hard to ensure you can rely o We are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-python/issues) with questions, bugs, or suggestions. -## Requirements - -Python 3.7 or higher. - ## Activating CLI Autocomplete ### Using CLI Autocomplete Using the following sequence of commands for each shell will activate the autocompletion feature for the CLI. #### Bash -1. Install openai if not installed yet. +1. Register ‘openai’ command for argument completion by running: ```shell -pip install openai +register-python-argcomplete openai >> ~/.bashrc ``` -2. Configure your shell to support global auto completion for python scripts by running: +#### Zsh +1. Register ‘openai’ command for argument completion by running: ```shell -activate-global-python-argcomplete +register-python-argcomplete openai >> ~/.zshrc ``` -3. Restart your terminal -4. Register ‘openai’ command for argument completion by running: +#### Fish +1. Register ‘openai’ command for argument completion by running: ```shell -register-python-argcomplete openai >> ~/.bashrc -``` - -5. Try on CLI -```shell -openai +register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish ``` #### Powershell -1. Install openai if not installed already. -```shell -pip install openai -``` -2. Create new completion file: +1. Create new completion file: ```shell register-python-argcomplete --shell powershell openai > ~/openai.psm1 ``` -3. If you don't already have a ``$PROFILE`` you can add this by running: +2. If you don't already have a ``$PROFILE`` you can add this by running: ```shell New-Item -ItemType File -Path $PROFILE -Force ``` -4. Open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: +3. Open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: ```shell Import-Module "~/openai.psm1" ``` -5. Restart the terminal and try: +#### Usage +After completing the appropriate steps for your shell, restart the terminal and try: ```shell openai -``` \ No newline at end of file +``` + +## Requirements + +Python 3.7 or higher. \ No newline at end of file From 11f36709532a642f941f1b0a355991e405ea9699 Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Fri, 2 Aug 2024 22:53:49 +0000 Subject: [PATCH 08/24] modified ordering of readme sections Co-authored-by: hoonman Co-authored-by: JesusG2022 --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 39489e0dcf..06037464bb 100644 --- a/README.md +++ b/README.md @@ -627,18 +627,6 @@ In addition to the options provided in the base `OpenAI` client, the following o An example of using the client with Microsoft Entra ID (formerly known as Azure Active Directory) can be found [here](https://github.com/openai/openai-python/blob/main/examples/azure_ad.py). -## Versioning - -This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions: - -1. Changes that only affect static types, without breaking runtime behavior. -2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_. -3. Changes that we do not expect to impact the vast majority of users in practice. - -We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. - -We are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-python/issues) with questions, bugs, or suggestions. - ## Activating CLI Autocomplete ### Using CLI Autocomplete @@ -683,6 +671,18 @@ After completing the appropriate steps for your shell, restart the terminal and openai ``` +## Versioning + +This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions: + +1. Changes that only affect static types, without breaking runtime behavior. +2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_. +3. Changes that we do not expect to impact the vast majority of users in practice. + +We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. + +We are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-python/issues) with questions, bugs, or suggestions. + ## Requirements Python 3.7 or higher. \ No newline at end of file From 97426789414a9cda0081f34c7f9ad06a3fb31d30 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:52:18 +0000 Subject: [PATCH 09/24] Modified readme to include both temporary and permanent autocomplete activation Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 06037464bb..e439b362b1 100644 --- a/README.md +++ b/README.md @@ -628,44 +628,51 @@ In addition to the options provided in the base `OpenAI` client, the following o An example of using the client with Microsoft Entra ID (formerly known as Azure Active Directory) can be found [here](https://github.com/openai/openai-python/blob/main/examples/azure_ad.py). ## Activating CLI Autocomplete +Use the following commands to activate CLI autocompletion for each shell. -### Using CLI Autocomplete -Using the following sequence of commands for each shell will activate the autocompletion feature for the CLI. -#### Bash -1. Register ‘openai’ command for argument completion by running: +### Bash & Zsh +Configure your shell to support global auto completion for python scripts by running: ```shell -register-python-argcomplete openai >> ~/.bashrc +activate-global-python-argcomplete ``` - -#### Zsh -1. Register ‘openai’ command for argument completion by running: +Use this command to register `openai` for argument completion using argcomplete for the current terminal session: ```shell +eval "$(register-python-argcomplete openai)" +``` +Alternatively, run this command to register `openai` for argument completion permanently, eliminating the need to run the `eval` command each time the terminal is restarted or killed. +For Bash: +```shell +register-python-argcomplete openai >> ~/.bashrc +``` +For Zsh: +```shell register-python-argcomplete openai >> ~/.zshrc ``` -#### Fish -1. Register ‘openai’ command for argument completion by running: +### Powershell +To activate completions for Powershell use: ```shell -register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish +register-python-argcomplete --shell powershell openai | Out-String | Invoke-Expression ``` - -#### Powershell -1. Create new completion file: +Alternatively, create a new completion file. This command will persist even if the terminal is killed or restarted. ```shell register-python-argcomplete --shell powershell openai > ~/openai.psm1 ``` - -2. If you don't already have a ``$PROFILE`` you can add this by running: +To activate the completions file, open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: ```shell -New-Item -ItemType File -Path $PROFILE -Force +Import-Module "~/openai.psm1" ``` - -3. Open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: +### Fish +To activate completions for fish use: ```shell -Import-Module "~/openai.psm1" +register-python-argcomplete --shell fish openai | source +``` +Alternatively, create a new completion file. This command will persist even if the terminal is killed or restarted. +```shell +register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish ``` -#### Usage +### Usage After completing the appropriate steps for your shell, restart the terminal and try: ```shell openai From 1ce382cadabeb30bd1115c8d813f24e333fc2db2 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Sun, 4 Aug 2024 21:16:21 +0000 Subject: [PATCH 10/24] Added subsection for different shells Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e439b362b1..f82ab1b857 100644 --- a/README.md +++ b/README.md @@ -639,6 +639,7 @@ Use this command to register `openai` for argument completion using argcomplete ```shell eval "$(register-python-argcomplete openai)" ``` +#### Permanent Argument Completion Setup for Bash/Zsh Alternatively, run this command to register `openai` for argument completion permanently, eliminating the need to run the `eval` command each time the terminal is restarted or killed. For Bash: ```shell @@ -654,6 +655,7 @@ To activate completions for Powershell use: ```shell register-python-argcomplete --shell powershell openai | Out-String | Invoke-Expression ``` +#### Permanent Argument Completion Setup for Powershell Alternatively, create a new completion file. This command will persist even if the terminal is killed or restarted. ```shell register-python-argcomplete --shell powershell openai > ~/openai.psm1 @@ -667,6 +669,7 @@ To activate completions for fish use: ```shell register-python-argcomplete --shell fish openai | source ``` +#### Permanent Argument Completion Setup for Fish Alternatively, create a new completion file. This command will persist even if the terminal is killed or restarted. ```shell register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish From cbb5052847f5d6b0c7be910e36099794cf8d9772 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Sun, 4 Aug 2024 21:18:00 +0000 Subject: [PATCH 11/24] removed global completion command Co-authored-by: Tienbruh Co-authored-by: JesusG2022 --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index f82ab1b857..ff4373814c 100644 --- a/README.md +++ b/README.md @@ -631,10 +631,6 @@ An example of using the client with Microsoft Entra ID (formerly known as Azure Use the following commands to activate CLI autocompletion for each shell. ### Bash & Zsh -Configure your shell to support global auto completion for python scripts by running: -```shell -activate-global-python-argcomplete -``` Use this command to register `openai` for argument completion using argcomplete for the current terminal session: ```shell eval "$(register-python-argcomplete openai)" From 016be6ed13ae7246279f67259c64a927c2933e82 Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Sun, 4 Aug 2024 22:44:44 +0000 Subject: [PATCH 12/24] Fixed vague wording in readme Co-authored-by: hoonman Co-authored-by: JesusG2022 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff4373814c..4de575fd79 100644 --- a/README.md +++ b/README.md @@ -672,7 +672,8 @@ register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish ``` ### Usage -After completing the appropriate steps for your shell, restart the terminal and try: +After completing the appropriate steps for your shell, try doing the following action: +_(If you have activated permanent argument completion, restart your terminal before proceeding)_ ```shell openai ``` From 0566711e0df378901f9b04c325de547859a6e28b Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Sun, 4 Aug 2024 22:49:23 +0000 Subject: [PATCH 13/24] Modified readme layout Co-authored-by: hoonman Co-authored-by: JesusG2022 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4de575fd79..2d46205f44 100644 --- a/README.md +++ b/README.md @@ -672,8 +672,8 @@ register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish ``` ### Usage -After completing the appropriate steps for your shell, try doing the following action: -_(If you have activated permanent argument completion, restart your terminal before proceeding)_ +After completing the appropriate steps for your shell, try the following action: +>_If you have activated permanent argument completion, restart your terminal before proceeding._ ```shell openai ``` From 3c22cdaa4ee94255fc799349ca075d0aff018cc1 Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Sun, 4 Aug 2024 22:55:12 +0000 Subject: [PATCH 14/24] Fixed readme typo Co-authored-by: hoonman Co-authored-by: JesusG2022 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d46205f44..dbe634c0b0 100644 --- a/README.md +++ b/README.md @@ -636,7 +636,7 @@ Use this command to register `openai` for argument completion using argcomplete eval "$(register-python-argcomplete openai)" ``` #### Permanent Argument Completion Setup for Bash/Zsh -Alternatively, run this command to register `openai` for argument completion permanently, eliminating the need to run the `eval` command each time the terminal is restarted or killed. +Alternatively, run this command to register `openai` for argument completion permanently, eliminating the need to run the `eval` command each time the terminal is restarted or killed. For Bash: ```shell register-python-argcomplete openai >> ~/.bashrc From 361f10d43520b193f337cc1188facc6c17bff9cc Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:28:51 +0000 Subject: [PATCH 15/24] Moved argcomplete to become an optional dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 39bf368c14..d87bd03d39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ dependencies = [ "cached-property; python_version < '3.8'", "tqdm > 4", "jiter>=0.4.0, <1", - "argcomplete >= 1.12.0" ] requires-python = ">= 3.7.1" classifiers = [ @@ -40,6 +39,7 @@ classifiers = [ [project.optional-dependencies] datalib = ["numpy >= 1", "pandas >= 1.2.3", "pandas-stubs >= 1.1.0.11"] +cli = ["argcomplete >= 1.12.0"] [project.urls] Homepage = "https://github.com/openai/openai-python" From 8e70ec3b6e6b4347e0c81181921f53366ea41587 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Tue, 3 Sep 2024 19:05:17 +0000 Subject: [PATCH 16/24] add proxy for argcomplete and use it in _cli.py file --- src/openai/_extras/argcomplete_proxy.py | 37 +++++++++++++++++++++++++ src/openai/cli/_cli.py | 6 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/openai/_extras/argcomplete_proxy.py diff --git a/src/openai/_extras/argcomplete_proxy.py b/src/openai/_extras/argcomplete_proxy.py new file mode 100644 index 0000000000..ad48498b9c --- /dev/null +++ b/src/openai/_extras/argcomplete_proxy.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any +from typing_extensions import override + +from .._utils import LazyProxy +from ._common import MissingDependencyError, format_instructions + +if TYPE_CHECKING: + import argcomplete as argcomplete + + +ARGCOMPLETE_INSTRUCTIONS = format_instructions(library="argcomplete", extra="cli") + + +class ArgcompleteProxy(LazyProxy[Any]): + @override + def __load__(self) -> Any: + try: + import argcomplete + except ImportError as err: + raise MissingDependencyError(ARGCOMPLETE_INSTRUCTIONS) from err + + return argcomplete + + +if not TYPE_CHECKING: + argcomplete = ArgcompleteProxy() + + +def has_argcomplete() -> bool: + try: + import argcomplete # noqa: F401 # pyright: ignore[reportUnusedImport] + except ImportError: + return False + + return True diff --git a/src/openai/cli/_cli.py b/src/openai/cli/_cli.py index e5fe983a50..97393909ff 100644 --- a/src/openai/cli/_cli.py +++ b/src/openai/cli/_cli.py @@ -5,7 +5,7 @@ import sys import logging import argparse -import argcomplete + from typing import Any, List, Type, Optional from typing_extensions import ClassVar @@ -23,6 +23,7 @@ from .._compat import PYDANTIC_V2, ConfigDict, model_parse from .._models import BaseModel from .._exceptions import APIError +from .._extras import argcomplete as argcomplete, has_argcomplete logger = logging.getLogger() formatter = logging.Formatter("[%(asctime)s] %(message)s") @@ -165,7 +166,8 @@ def _parse_args(parser: argparse.ArgumentParser) -> tuple[argparse.Namespace, Ar def _main() -> None: parser = _build_parser() - argcomplete.autocomplete(parser) + if has_argcomplete(): + argcomplete.autocomplete(parser) parsed, args, unknown = _parse_args(parser) if args.verbosity != 0: From 889c3b93854e45756319d803eecd12b1bb568956 Mon Sep 17 00:00:00 2001 From: hoonman Date: Tue, 3 Sep 2024 14:42:36 -0700 Subject: [PATCH 17/24] add argcomplete proxy in the __init__ file --- src/openai/_extras/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/openai/_extras/__init__.py b/src/openai/_extras/__init__.py index 864dac4171..22bfef8d97 100644 --- a/src/openai/_extras/__init__.py +++ b/src/openai/_extras/__init__.py @@ -1,2 +1,3 @@ from .numpy_proxy import numpy as numpy, has_numpy as has_numpy from .pandas_proxy import pandas as pandas +from .argcomplete_proxy import argcomplete as argcomplete, has_argcomplete as has_argcomplete From 8ef585d097d3f3f89d1f39c84dafb23d11a8301f Mon Sep 17 00:00:00 2001 From: hoonman Date: Tue, 3 Sep 2024 15:27:26 -0700 Subject: [PATCH 18/24] add try except block and remove proxy --- src/openai/_extras/__init__.py | 1 - src/openai/_extras/argcomplete_proxy.py | 37 ------------------------- src/openai/cli/_cli.py | 7 +++-- 3 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 src/openai/_extras/argcomplete_proxy.py diff --git a/src/openai/_extras/__init__.py b/src/openai/_extras/__init__.py index 22bfef8d97..864dac4171 100644 --- a/src/openai/_extras/__init__.py +++ b/src/openai/_extras/__init__.py @@ -1,3 +1,2 @@ from .numpy_proxy import numpy as numpy, has_numpy as has_numpy from .pandas_proxy import pandas as pandas -from .argcomplete_proxy import argcomplete as argcomplete, has_argcomplete as has_argcomplete diff --git a/src/openai/_extras/argcomplete_proxy.py b/src/openai/_extras/argcomplete_proxy.py deleted file mode 100644 index ad48498b9c..0000000000 --- a/src/openai/_extras/argcomplete_proxy.py +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING, Any -from typing_extensions import override - -from .._utils import LazyProxy -from ._common import MissingDependencyError, format_instructions - -if TYPE_CHECKING: - import argcomplete as argcomplete - - -ARGCOMPLETE_INSTRUCTIONS = format_instructions(library="argcomplete", extra="cli") - - -class ArgcompleteProxy(LazyProxy[Any]): - @override - def __load__(self) -> Any: - try: - import argcomplete - except ImportError as err: - raise MissingDependencyError(ARGCOMPLETE_INSTRUCTIONS) from err - - return argcomplete - - -if not TYPE_CHECKING: - argcomplete = ArgcompleteProxy() - - -def has_argcomplete() -> bool: - try: - import argcomplete # noqa: F401 # pyright: ignore[reportUnusedImport] - except ImportError: - return False - - return True diff --git a/src/openai/cli/_cli.py b/src/openai/cli/_cli.py index 97393909ff..016e195d4b 100644 --- a/src/openai/cli/_cli.py +++ b/src/openai/cli/_cli.py @@ -23,7 +23,6 @@ from .._compat import PYDANTIC_V2, ConfigDict, model_parse from .._models import BaseModel from .._exceptions import APIError -from .._extras import argcomplete as argcomplete, has_argcomplete logger = logging.getLogger() formatter = logging.Formatter("[%(asctime)s] %(message)s") @@ -166,8 +165,12 @@ def _parse_args(parser: argparse.ArgumentParser) -> tuple[argparse.Namespace, Ar def _main() -> None: parser = _build_parser() - if has_argcomplete(): + try: + import argcomplete argcomplete.autocomplete(parser) + except ImportError: + pass + parsed, args, unknown = _parse_args(parser) if args.verbosity != 0: From ca2bd273c14e5c823ef2d491e99bcaa8f819205e Mon Sep 17 00:00:00 2001 From: hoonman Date: Tue, 3 Sep 2024 15:36:38 -0700 Subject: [PATCH 19/24] include guide on installing argcomplete optionally --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index dbe634c0b0..af54886b3e 100644 --- a/README.md +++ b/README.md @@ -630,6 +630,11 @@ An example of using the client with Microsoft Entra ID (formerly known as Azure ## Activating CLI Autocomplete Use the following commands to activate CLI autocompletion for each shell. +Install openai with `[cli]` option to install argcomplete. +```shell +pip install openai[cli] +``` + ### Bash & Zsh Use this command to register `openai` for argument completion using argcomplete for the current terminal session: ```shell From 77c2841ad1961ceab796a94913dacd15a3ef54d1 Mon Sep 17 00:00:00 2001 From: hoonman Date: Tue, 3 Sep 2024 15:41:26 -0700 Subject: [PATCH 20/24] edit convention and guide on installing autocomplete optionally --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af54886b3e..5cf2976ea4 100644 --- a/README.md +++ b/README.md @@ -630,7 +630,7 @@ An example of using the client with Microsoft Entra ID (formerly known as Azure ## Activating CLI Autocomplete Use the following commands to activate CLI autocompletion for each shell. -Install openai with `[cli]` option to install argcomplete. +Install `openai` with `[cli]` option to install argcomplete. ```shell pip install openai[cli] ``` From 6d2e5fa739a4466f7c9c7d8dc9354172a8b2aca6 Mon Sep 17 00:00:00 2001 From: hoonman Date: Tue, 3 Sep 2024 15:48:53 -0700 Subject: [PATCH 21/24] remove unnecessary newline --- src/openai/cli/_cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/openai/cli/_cli.py b/src/openai/cli/_cli.py index 016e195d4b..744184fad5 100644 --- a/src/openai/cli/_cli.py +++ b/src/openai/cli/_cli.py @@ -170,7 +170,6 @@ def _main() -> None: argcomplete.autocomplete(parser) except ImportError: pass - parsed, args, unknown = _parse_args(parser) if args.verbosity != 0: From 6041733a0d7e050c5424a3d1198a72c3875fd359 Mon Sep 17 00:00:00 2001 From: Jaehoon <77257966+hoonman@users.noreply.github.com> Date: Wed, 4 Sep 2024 03:19:03 +0000 Subject: [PATCH 22/24] remove whiteline --- src/openai/cli/_cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/openai/cli/_cli.py b/src/openai/cli/_cli.py index 744184fad5..6d6c89df58 100644 --- a/src/openai/cli/_cli.py +++ b/src/openai/cli/_cli.py @@ -5,7 +5,6 @@ import sys import logging import argparse - from typing import Any, List, Type, Optional from typing_extensions import ClassVar From 611e255452ce99131e30c3e982544620086cdbca Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:26:24 -0700 Subject: [PATCH 23/24] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a485385295..3156c2bd6b 100644 --- a/README.md +++ b/README.md @@ -768,4 +768,8 @@ print(openai.__version__) ## Requirements -Python 3.7 or higher. \ No newline at end of file +Python 3.7 or higher. + +## Contributing + +See [the contributing documentation](./CONTRIBUTING.md). From 0eb98cab2f08a1220015df520bbfc3ccc2f08564 Mon Sep 17 00:00:00 2001 From: Tien Pham <97005404+Tienbruh@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:38:18 -0700 Subject: [PATCH 24/24] Refactored README.md for autocompletion instructions --- README.md | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 3156c2bd6b..726f447615 100644 --- a/README.md +++ b/README.md @@ -695,11 +695,10 @@ Install `openai` with `[cli]` option to install argcomplete. pip install openai[cli] ``` -### Bash & Zsh -Use this command to register `openai` for argument completion using argcomplete for the current terminal session: -```shell -eval "$(register-python-argcomplete openai)" -``` +### Argument Completion Activation +See argcomplete's [documentation](https://github.com/kislyuk/argcomplete/tree/develop?tab=readme-ov-file#synopsis) for temporary Bash/Zsh setup. +See argcomplete's [contributing documentation](https://github.com/kislyuk/argcomplete/tree/develop/contrib) for Fish and Powershell setup. + #### Permanent Argument Completion Setup for Bash/Zsh Alternatively, run this command to register `openai` for argument completion permanently, eliminating the need to run the `eval` command each time the terminal is restarted or killed. For Bash: @@ -711,31 +710,6 @@ For Zsh: register-python-argcomplete openai >> ~/.zshrc ``` -### Powershell -To activate completions for Powershell use: -```shell -register-python-argcomplete --shell powershell openai | Out-String | Invoke-Expression -``` -#### Permanent Argument Completion Setup for Powershell -Alternatively, create a new completion file. This command will persist even if the terminal is killed or restarted. -```shell -register-python-argcomplete --shell powershell openai > ~/openai.psm1 -``` -To activate the completions file, open the [``$PROFILE``](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4&viewFallbackFrom=powershell-7.3#how-to-create-a-profile) by running ``notepad $PROFILE`` and add this following line: -```shell -Import-Module "~/openai.psm1" -``` -### Fish -To activate completions for fish use: -```shell -register-python-argcomplete --shell fish openai | source -``` -#### Permanent Argument Completion Setup for Fish -Alternatively, create a new completion file. This command will persist even if the terminal is killed or restarted. -```shell -register-python-argcomplete --shell fish openai > ~/.config/fish/config.fish -``` - ### Usage After completing the appropriate steps for your shell, try the following action: >_If you have activated permanent argument completion, restart your terminal before proceeding._