Skip to content

allow to pass api key also for ollama #429

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

Open
wants to merge 11 commits into
base: development
Choose a base branch
from
Open

Conversation

mschwoer
Copy link
Contributor

@mschwoer mschwoer commented Apr 17, 2025

@JuliaS92 please check if this works for you

This pull request refines the handling of API keys and improves flexibility in configuring LLM integrations. Key updates include making API key input optional for certain models, generalizing API key management, and enabling dynamic configuration of base URLs for specific models.

Improvements in API key handling:

  • alphastats/gui/utils/llm_helper.py: Updated the llm_config function to make API key input optional for models that do not require it. The prompt now dynamically reflects whether the API key is mandatory.
  • alphastats/gui/utils/llm_helper.py: Generalized API key management in the set_api_key function by removing references to "OpenAI" and aligning the logic to support multiple providers. Updated error and info messages accordingly.

Enhancements in LLM integration:

  • alphastats/llm/llm_integration.py: Modified the initialization of the OpenAI client to use the provided api_key dynamically instead of hardcoding it for specific models. This change improves flexibility for different LLM configurations.

@mschwoer mschwoer requested a review from Copilot April 17, 2025 06:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@JuliaS92 JuliaS92 changed the base branch from fix_pickle to development April 29, 2025 07:37
Copy link

The following feedback could not be added to specific lines, but still contains valuable information:

{"change_id": 1, "file_name": "./alphastats/gui/utils/llm_helper.py", "start_line": 287, "end_line": 321, "proposed_code": "def set_api_key(api_key: str = None) -> None:\n    \"\"\"Put the API key in the session state.\n\n    If provided, use the `api_key`.\n    If not, take the key from the secrets.toml file.\n    Show a message if the file is not found.\n\n    Args:\n        api_key (str, optional): The API key. Defaults to None.\n    \"\"\"\n    if not api_key:\n        api_key = st.session_state.get(StateKeys.OPENAI_API_KEY, None)\n\n    if api_key:\n        st.info(f\"API key set: {api_key[:3]}{(len(api_key)-6)*'*'}{api_key[-3:]}\")\n    else:\n        try:\n            if Path(\"./.streamlit/secrets.toml\").exists():\n                api_key = st.secrets[\"api_key\"]\n                st.toast(\"API key loaded from secrets.toml.\", icon=\"\u2705\")\n            else:\n                st.info(\n                    \"Please enter an API key or provide it in a secrets.toml file in the \"\n                    \"alphastats/gui/.streamlit directory like \"\n                    \"`api_key = <key>`\"\n                )\n        except KeyError:\n            st.error(\"API key not found in secrets.toml.\")\n        except Exception as e:\n            st.error(f\"Error loading API key: {e}.\")\n\n    st.session_state[StateKeys.OPENAI_API_KEY] = api_key", "comment": "The reference to 'OpenAI' should be replaced with a more generic 'API' since the function now handles API keys for various LLM providers, not just OpenAI. Similarly, the key in secrets.toml should be 'api_key' rather than 'openai_api_key'."}

Copy link

Number of tokens: input_tokens=33968 output_tokens=2379 max_tokens=4096
review_instructions=''
config={}
thinking: ```
[]

@JuliaS92 JuliaS92 marked this pull request as ready for review April 29, 2025 09:44
@JuliaS92 JuliaS92 requested a review from boopthesnoot April 29, 2025 09:44
@JuliaS92 JuliaS92 requested a review from PatriciaSkowronek May 8, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants