Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
current_context.txt
current_context.config
contexts/test.txt
src/__pycache__/
src/openaiapirc
__pycache__/
src/openaiapirc
49 changes: 26 additions & 23 deletions Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,22 @@ In order to run the Codex CLI, ensure that you have python installed. To install
python -m pip install -r requirements.txt
```

Additionally, the OpenAI API key, organization id, and engine id are required to execute the Codex CLI tool.
Additionally, a MiniMax API key, API base URL, and model id are required to execute the Codex CLI tool. An organization id is optional.

To obtain the OpenAI API key information, go to (https://beta.openai.com/account/api-keys) and login into your account.
## MiniMax configuration

Once logged in you will see:
![](images/OpenAI-apikey.png)
The setup scripts accept an API base URL and model id. Use one of these regional base URLs:

Copy the API key by clicking the _Copy_ button and save the copied key where you can retrieve it.
* Global: `https://api.minimax.io/v1`
* China: `https://api.minimaxi.com/v1`

To obtain the OpenAI organization id, go to OpenAI Settings page (https://beta.openai.com/account/org-settings) and copy the id shown underneath the _Organization ID_ heading. Save the copied id with the API key that was stored in previous step.
The current model ids are `MiniMax-M3` and `MiniMax-M2.7`. For example:

See image below for reference:
![](images/OpenAI-orgid.png)

To obtain the OpenAI engine id, go to OpenAI Engines page (https://beta.openai.com/docs/engines/codex-series-private-beta) for the engines available for Codex models. Select the desired engine and save the engine id with the API key and organization id stored in previous steps.
```bash
source bash_setup.sh -k YOUR_API_KEY -b https://api.minimax.io/v1 -m MiniMax-M3
```

See image below for reference:
![](images/OpenAI-engineid.png)
The generated `src/openaiapirc` stores `base_url` and `model`; `organization_id` is optional.

## Bash instructions

Expand All @@ -57,7 +55,7 @@ To leverage the Codex CLI on WSL and Linux environments using Bash please follow
In the Codex CLI folder, there is a folder named `scripts` where you will find a `bash_setup.sh` script which is used to setup the Bash environment.

Run the following commands to setup your environment, the script will prompt
for Organization id, API key and engine id:
for an optional organization id, API key, API base URL, and model id:
```
cd scripts
source bash_setup.sh
Expand All @@ -82,13 +80,15 @@ By default `bash_setup.sh` will prompt for the required settings. It's also poss
| Parameter | Description |
|--------------|-------------|
| `-o <value>` | To pass your [OpenAI Organization Id](https://beta.openai.com/account/org-settings) |
| `-k <value>` | To pass your [OpenAI API key](https://beta.openai.com/account/api-keys) |
| `-e <value>` | To specify the [OpenAI Engine Id](https://beta.openai.com/docs/engines/codex-series-private-beta) |
| `-k <value>` | To pass your API key |
| `-b <value>` | To specify the API base URL |
| `-m <value>` | To specify the model id |
| `-e <value>` | Legacy alias for `-m` |

Example:

```
source bash_setup.sh -o myorgid -k myapikey -e someengineid
source bash_setup.sh -k YOUR_API_KEY -b https://api.minimax.io/v1 -m MiniMax-M3
```

For help running the Codex CLI Bash setup, please run the following command:
Expand All @@ -106,7 +106,7 @@ source bash_setup.sh -h
$ git clone https://github.com/microsoft/Codex-CLI.git ~/your/custom/path/
```

2. In zsh, go to `~/your/custom/path/` (the folder contains Codex CLI code), then run the following command to setup your zsh environment. The script will prompt for Organization id, API key and engine id:
2. In zsh, go to `~/your/custom/path/` (the folder contains Codex CLI code), then run the following command to setup your zsh environment. The script will prompt for an optional organization id, API key, API base URL, and model id:

```
./scripts/zsh_setup.sh
Expand All @@ -126,8 +126,10 @@ Once you are done, go to `~/your/custom/path/` (the folder contains Codex CLI co
| Parameter | Description |
|--------------|-------------|
| `-o <value>` | To pass your [OpenAI Organization Id](https://beta.openai.com/account/org-settings) |
| `-k <value>` | To pass your [OpenAI API key](https://beta.openai.com/account/api-keys) |
| `-e <value>` | To specify the [OpenAI Engine Id](https://beta.openai.com/docs/engines/codex-series-private-beta) |
| `-k <value>` | To pass your API key |
| `-b <value>` | To specify the API base URL |
| `-m <value>` | To specify the model id |
| `-e <value>` | Legacy alias for `-m` |


## Powershell instructions
Expand All @@ -148,10 +150,10 @@ For more information about Execution Policies, see
[about_Execution_Policies](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_execution_policies).


3. In the same Powershell terminal, go to `C:\your\custom\path\Codex-CLI\` (the folder that contains the cloned Codex CLI project). Copy the following command, then replace `YOUR_OPENAI_ORGANIZATION_ID` and `ENGINE_ID` with your OpenAI organization Id and OpenAI engine Id. Run the command to setup your PowerShell environment. It will prompt you for OpenAI access key.
3. In the same Powershell terminal, go to `C:\your\custom\path\Codex-CLI\` (the folder that contains the cloned Codex CLI project). Run the command below with your API base URL and model id. It will prompt you for an API key.

```PowerShell
.\scripts\powershell_setup.ps1 -OpenAIOrganizationId 'YOUR_OPENAI_ORGANIZATION_ID' -OpenAIEngineId 'ENGINE_ID'
.\scripts\powershell_setup.ps1 -OpenAIApiBaseUrl 'https://api.minimax.io/v1' -OpenAIModelId 'MiniMax-M3'
```
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;See [About powershell_setup.ps1](#about-powershell_setupps1) section to learn script parameters.

Expand All @@ -173,6 +175,7 @@ Set-ExecutionPolicy Undefined -Scope CurrentUser
| Parameter | Type | Description |
|--|--|--|
| `-OpenAIApiKey` | [SecureString](https://docs.microsoft.com/en-us/dotnet/api/system.security.securestring) | Required. If is not supplied, the script will prompt you to input the value. You can find this value at [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys). To provide the value via PowerShell parameter, this is an example for PowerShell 7: <br/> `.\scripts\powershell_setup.ps1 -OpenAIApiKey (ConvertTo-SecureString "YOUR_OPENAI_API_KEY" -AsPlainText -Force)` |
| `-OpenAIOrganizationId` | String | Required. Your [OpenAI organization Id](https://beta.openai.com/account/org-settings). |
| `-OpenAIEngineId` | String | Required. The [OpenAI engine Id](https://beta.openai.com/docs/engines/codex-series-private-beta) that provides access to a model.|
| `-OpenAIOrganizationId` | String | Optional organization id. |
| `-OpenAIApiBaseUrl` | String | Required API base URL. |
| `-OpenAIModelId` | String | Required model id. `-OpenAIEngineId` remains available as an alias. |
| `-RepoRoot` | [FileInfo](https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo) | Optional. Default to the current folder.<br>The value should be the path of Codex CLI folder. Example:<br/>`.\scripts\powershell_setup.ps1 -RepoRoot 'C:\your\custom\path'`|
34 changes: 8 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ This repository aims to grow the understanding of using Codex in applications by
## Requirements
* [Python 3.7.1+](https://www.python.org/downloads/)
* \[Windows\]: Python is added to PATH.
* An [OpenAI account](https://openai.com/api/)
* [OpenAI API Key](https://beta.openai.com/account/api-keys).
* [OpenAI Organization Id](https://beta.openai.com/account/org-settings). If you have multiple organizations, please update your [default organization](https://beta.openai.com/account/api-keys) to the one that has access to codex engines before getting the organization Id.
* [OpenAI Engine Id](https://beta.openai.com/docs/engines/codex-series-private-beta). It provides access to a model. For example, `code-davinci-002` or `code-cushman-001`. See [here](#what-openai-engines-are-available-to-me) for checking available engines.
* MiniMax API credentials
* API key.
* API base URL: `https://api.minimax.io/v1` globally or `https://api.minimaxi.com/v1` in China.
* Model id: `MiniMax-M3` or `MiniMax-M2.7`.

## Installation

Expand Down Expand Up @@ -68,7 +68,7 @@ Any time the model seems to output consistently incorrect commands, you can use
| `set <config-key> <config-value>` | Sets the configuration of your interaction with the model |


Feel free to improve your experience by changing the token limit, engine id and temperature using the set command. For example, `# set engine cushman-codex`, `# set temperature 0.5`, `# set max_tokens 50`.
Feel free to improve your experience by changing the token limit, model id and temperature using the set command. For example, `# set model MiniMax-M3`, `# set temperature 0.5`, `# set max_tokens 50`.

## Prompt Engineering and Context Files

Expand Down Expand Up @@ -114,27 +114,9 @@ Use `DEBUG_MODE` to use a terminal input instead of the stdin and debug the code
Sometimes the `openai` package will throws errors that aren't caught by the tool, you can add a catch block at the end of `codex_query.py` for that exception and print a custom error message.

## FAQ
### What OpenAI engines are available to me?
You might have access to different [OpenAI engines](https://beta.openai.com/docs/api-reference/engines) per OpenAI organization. To check what engines are available to you, one can query the [List engines API](https://beta.openai.com/docs/api-reference/engines/list) for available engines. See the following commands:

* Shell
```
curl https://api.openai.com/v1/engines \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'OpenAI-Organization: YOUR_ORG_ID'
```

* PowerShell

PowerShell v5 (The default one comes with Windows)
```powershell
(Invoke-WebRequest -Uri https://api.openai.com/v1/engines -Headers @{"Authorization" = "Bearer YOUR_API_KEY"; "OpenAI-Organization" = "YOUR_ORG_ID"}).Content
```

PowerShell v7
```powershell
(Invoke-WebRequest -Uri https://api.openai.com/v1/engines -Authentication Bearer -Token (ConvertTo-SecureString "YOUR_API_KEY" -AsPlainText -Force) -Headers @{"OpenAI-Organization" = "YOUR_ORG_ID"}).Content
```
### Which MiniMax models are supported?

Set `model` to `MiniMax-M3` or `MiniMax-M2.7` in `src/openaiapirc`. The client sends requests to the configured `base_url` using the chat completions API.

### Can I run the sample on Azure?
The sample code can be currently be used with Codex on OpenAI’s API. In the coming months, the sample will be updated so you can also use it with the [Azure OpenAI Service](https://aka.ms/azure-openai).
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
openai>=0.18.1
openai>=1.0.0
psutil>=5.9.0
50 changes: 27 additions & 23 deletions scripts/bash_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Usage: source bash_setup.sh [optional parameters]

-o orgId Set the OpenAI organization id.
-k apiKey Set the OpenAI API key.
-e engineId Set the OpenAI engine id.
-b baseUrl Set the API base URL.
-m modelId Set the model id.
-e modelId Legacy alias for -m.
-d Print some system information for debugging.
-h Print this help content.

Expand All @@ -28,7 +30,8 @@ readParameters()
case $1 in
-o ) shift; ORG_ID=$1 ;;
-k ) shift; SECRET_KEY=$1 ;;
-e ) shift; ENGINE_ID=$1 ;;
-b ) shift; BASE_URL=$1 ;;
-m | -e ) shift; MODEL_ID=$1 ;;
-d ) systemInfo
exitScript
;;
Expand All @@ -50,35 +53,35 @@ askSettings()
if [ -z "$SECRET_KEY" ]; then
echo -n 'OpenAI API key: '; read -s SECRET_KEY; echo
fi
if [ -z "$ENGINE_ID" ]; then
echo -n 'OpenAI Engine Id: '; read ENGINE_ID
if [ -z "$BASE_URL" ]; then
echo -n 'API base URL: '; read BASE_URL
fi
if [ -z "$MODEL_ID" ]; then
echo -n 'Model Id: '; read MODEL_ID
fi
}

# Call OpenAI API with the given settings to verify everythin is in order
# Validate the settings before writing the configuration file
validateSettings()
{
echo -n "*** Testing Open AI access... "
local TEST=$(curl -s 'https://api.openai.com/v1/engines' -H "Authorization: Bearer $SECRET_KEY" -H "OpenAI-Organization: $ORG_ID" -w '%{http_code}')
local STATUS_CODE=$(echo "$TEST"|tail -n 1)
if [ $STATUS_CODE -ne 200 ]; then
echo "ERROR [$STATUS_CODE]"
echo "Failed to access OpenAI API, result: $STATUS_CODE"
echo "Please check your OpenAI API key (https://beta.openai.com/account/api-keys)"
echo "and Organization ID (https://beta.openai.com/account/org-settings)."
echo "*************"
exitScript
return
fi
local ENGINE_FOUND=$(echo "$TEST"|grep '"id"'|grep "\"$ENGINE_ID\"")
if [ -z "$ENGINE_FOUND" ]; then
echo -n "*** Validating API settings... "
if [ -z "$SECRET_KEY" ] || [ -z "$BASE_URL" ] || [ -z "$MODEL_ID" ]; then
echo "ERROR"
echo "Cannot find OpenAI engine: $ENGINE_ID"
echo "Please check the OpenAI engine id (https://beta.openai.com/docs/engines/codex-series-private-beta)."
echo "API key, base URL, and model id are required."
echo "*************"
exitScript
return
fi
case "$BASE_URL" in
http://* | https://* ) ;;
* )
echo "ERROR"
echo "API base URL must start with http:// or https://."
echo "*************"
exitScript
return
;;
esac
echo "OK ***"
}

Expand All @@ -89,7 +92,8 @@ configureApp()
echo '[openai]' > $OPENAI_RC_FILE
echo "organization_id=$ORG_ID" >> $OPENAI_RC_FILE
echo "secret_key=$SECRET_KEY" >> $OPENAI_RC_FILE
echo "engine=$ENGINE_ID" >> $OPENAI_RC_FILE
echo "base_url=$BASE_URL" >> $OPENAI_RC_FILE
echo "model=$MODEL_ID" >> $OPENAI_RC_FILE
chmod +x "$CODEX_CLI_PATH/src/codex_query.py"
}

Expand Down Expand Up @@ -149,7 +153,7 @@ systemInfo()
# Remove variables and functions from the environment, in case the script was sourced
cleanupEnv()
{
unset ORG_ID SECRET_KEY ENGINE_ID SOURCED OPENAI_RC_FILE BASH_RC_FILE
unset ORG_ID SECRET_KEY BASE_URL MODEL_ID SOURCED OPENAI_RC_FILE BASH_RC_FILE
unset -f askSettings validateSettings configureApp configureBash enableApp readParameters
}

Expand Down
35 changes: 13 additions & 22 deletions scripts/powershell_setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ param
[SecureString]
$OpenAIApiKey,

[Parameter()]
$OpenAIOrganizationId,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
$OpenAIOrganizationId,
$OpenAIApiBaseUrl,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
$OpenAIEngineId
[Alias("OpenAIEngineId")]
$OpenAIModelId
)

$plugInScriptPath = Join-Path $RepoRoot -ChildPath "scripts\powershell_plugin.ps1"
Expand All @@ -42,25 +46,11 @@ if ($PSMajorVersion -lt 7) {
$openAIApiKeyPlainText = ConvertFrom-SecureString -SecureString $OpenAIApiKey -AsPlainText
}

# Check the access with OpenAI API
Write-Host "Checking OpenAI access..."
$enginesApiUri = "https://api.openai.com/v1/engines"
$response = $null
try {
if ($PSMajorVersion -lt 7) {
$response = (Invoke-WebRequest -Uri $enginesApiUri -Headers @{"Authorization" = "Bearer $openAIApiKeyPlainText"; "OpenAI-Organization" = "$OpenAIOrganizationId"})
} else {
$response = (Invoke-WebRequest -Uri $enginesApiUri -Authentication Bearer -Token $OpenAIApiKey -Headers @{"OpenAI-Organization" = "$OpenAIOrganizationId"})
}
} catch {
$statusCode = $_.Exception.Response.StatusCode.value__
Write-Error "Failed to access OpenAI api [$statusCode]. Please check your OpenAI API key (https://beta.openai.com/account/api-keys) and Organization ID (https://beta.openai.com/account/org-settings)."
exit 1
}

# Check if target engine is available to the user
if ($null -eq (($response.Content | ConvertFrom-Json).data | Where-Object {$_.id -eq $OpenAIEngineId})) {
Write-Error "Cannot find OpenAI engine: $OpenAIEngineId. Please check the OpenAI engine id (https://beta.openai.com/docs/engines/codex-series-private-beta) and your Organization ID (https://beta.openai.com/account/org-settings)."
# Validate the API base URL before writing the configuration file
$apiBaseUri = $null
if (-not [Uri]::TryCreate($OpenAIApiBaseUrl, [UriKind]::Absolute, [ref]$apiBaseUri) -or
$apiBaseUri.Scheme -notin @("http", "https")) {
Write-Error "API base URL must be an absolute HTTP or HTTPS URL."
exit 1
}

Expand Down Expand Up @@ -90,7 +80,8 @@ if (!(Test-Path -Path $openAIConfigPath)) {
Set-Content -Path $openAIConfigPath "[openai]
organization_id=$OpenAIOrganizationId
secret_key=$openAIApiKeyPlainText
engine=$OpenAIEngineId"
base_url=$OpenAIApiBaseUrl
model=$OpenAIModelId"
Write-Host "Updated OpenAI configuration file with secrets."

Write-Host -ForegroundColor Blue "Codex CLI PowerShell (v$PSMajorVersion) setup completed. Please open a new PowerShell session, type in # followed by your natural language command and hit Ctrl+G!"
Loading