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

Add OPENAI_BASE_PATH into env #188

Open
zkewind opened this issue Oct 24, 2023 · 2 comments
Open

Add OPENAI_BASE_PATH into env #188

zkewind opened this issue Oct 24, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@zkewind
Copy link

zkewind commented Oct 24, 2023

Background story explaining the current situation:
Can't change the API endpoint.
Desired new situation:
Alow custom API endpoint.
Implementation details:
Add OPENAI_BASE_PATH into ,env file.

@zkewind zkewind added the enhancement New feature or request label Oct 24, 2023
@codeautopilot
Copy link

codeautopilot bot commented Oct 24, 2023

Disclaimer: This comment was entirely generated using AI. Be aware that the information provided may be incorrect.

Potential solution

The task requires us to allow a custom API endpoint by adding an environment variable OPENAI_BASE_PATH into the .env file. This variable will then be used in the modules/gpt.js file to set the base path for the OpenAI API. The ui.js file might need to be checked if it uses the API endpoint directly, but from the given information, it seems that it doesn't.

Code

In the .env file, add the following line:

OPENAI_BASE_PATH=your_custom_api_endpoint

Replace your_custom_api_endpoint with the actual API endpoint you want to use.

In the modules/gpt.js file, add the following line at the top, right after the OPENAI_API_KEY is imported:

const OPENAI_BASE_PATH = process.env.OPENAI_BASE_PATH;

Then, modify the Configuration object to include the OPENAI_BASE_PATH as the base path for the API. Change the following lines of code:

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

to:

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
  basePath: OPENAI_BASE_PATH,
});

In the ui.js file, check if the runAgent function uses the API endpoint directly. If it does, modify it to use the OPENAI_BASE_PATH environment variable. If it doesn't, no changes are needed in this file.

Changes on ui.js

The ui.js file is responsible for the user interface and the main execution of the program. It doesn't seem to directly interact with the API endpoint. However, it does import and use the runAgent function from ./modules/interactiveAgent, which might be using the API endpoint.

To ensure the new environment variable OPENAI_BASE_PATH is used for setting the API endpoint, you should check the runAgent function in the interactiveAgent module. If the API endpoint is set there, modify it to use the new environment variable OPENAI_BASE_PATH.

If the runAgent function doesn't set the API endpoint, then no changes are needed in this file.

Changes on modules/gpt.js

To solve this task, we need to modify the callGPT function in the modules/gpt.js file to use the new environment variable OPENAI_BASE_PATH for setting the API endpoint.

Here is a step-by-step plan:

  1. Import the OPENAI_BASE_PATH from the environment variables at the top of the file, right after the OPENAI_API_KEY is imported. This can be done by adding the following line of code:
const OPENAI_BASE_PATH = process.env.OPENAI_BASE_PATH;
  1. Modify the Configuration object to include the OPENAI_BASE_PATH as the base path for the API. This can be done by changing the following lines of code:
const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

to:

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
  basePath: OPENAI_BASE_PATH,
});

This will set the base path for the OpenAI API to the value of the OPENAI_BASE_PATH environment variable.

Please note that this change assumes that the OPENAI_BASE_PATH environment variable is correctly set in the .env file and that the OpenAI library supports the basePath configuration option. If the OpenAI library does not support this option, you may need to modify the library code or find a different way to set the API endpoint.

Changes on .env

To solve this task, you need to add the new environment variable OPENAI_BASE_PATH into the .env file. This variable will hold the value of the custom API endpoint.

Here is how you can do it:

  1. Open the .env file.
  2. Add the following line at the end of the file:
OPENAI_BASE_PATH=your_custom_api_endpoint

Replace your_custom_api_endpoint with the actual API endpoint you want to use.

Please note that the .env file is usually not committed to the repository for security reasons. Therefore, each developer or environment should create their own .env file and set the OPENAI_BASE_PATH variable accordingly.


Current plan usage: 88.13%


Have feedback or need help?

Discord
Documentation
[email protected]

@codeautopilot
Copy link

codeautopilot bot commented Oct 24, 2023

Disclaimer: This comment was entirely generated using AI. Be aware that the information provided may be incorrect.

🤖 I'm working on a solution for this issue. Please don't create new issues or edit this one until I reply back.


Current plan usage: 81.74%


Have feedback or need help?

Discord
Documentation
[email protected]

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

No branches or pull requests

1 participant