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

Refactor new_session method for better API key handling #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Toukaya
Copy link

@Toukaya Toukaya commented Jul 3, 2024

  • Moved the logic for determining the API key environment variable to a new static method get_api_key_env_var.
  • Updated new_session method to use get_api_key_env_var for retrieving the correct API key environment variable based on the model name.
  • Set the default model to gpt-3.5-turbo using kwargs.setdefault for cleaner code.
  • Added support for setting the API URL if base_url is provided in kwargs.
  • Ensured that the API key is validated before creating a new ChatGPTSession.

Therefore, it is now possible to temporarily support more large language models, such as QWEN, MoonShot, etc., through the setting of the base URL.

like:

qwen_ai = AIChat(
    console=False, 
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", 
    model="qwen-plus"
)

- Moved the logic for determining the API key environment variable to a new static method `get_api_key_env_var`.
- Updated `new_session` method to use `get_api_key_env_var` for retrieving the correct API key environment variable based on the model name.
- Set the default model to `gpt-3.5-turbo` using `kwargs.setdefault` for cleaner code.
- Added support for setting the API URL if `base_url` is provided in `kwargs`.
- Ensured that the API key is validated before creating a new `ChatGPTSession`.
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

Successfully merging this pull request may close these issues.

1 participant