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

Removing Dependence on secrets.toml for environment variables #54

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.streamlit
.venv
__pycache__
.env
_trouble/
6 changes: 5 additions & 1 deletion 1_🏠_Home.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import streamlit as st
from streamlit_pills import pills
import os

from st_utils import (
add_builder_config,
Expand Down Expand Up @@ -29,7 +30,10 @@
"To build a new agent, please make sure that 'Create a new agent' is selected.",
icon="ℹ️",
)
if "metaphor_key" in st.secrets:
# removing all use of st.secrets
# relying on good old fashioned env vars
# if "metaphor_key" in st.secrets:
if "metaphor_key" in os.environ:
st.info("**NOTE**: The ability to add web search is enabled.")


Expand Down
1 change: 1 addition & 0 deletions cache/agents/agent_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"agent_ids": []}
470 changes: 470 additions & 0 deletions content/DesignStudent.md

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions core/agent_builder/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from core.agent_builder.registry import AgentCacheRegistry
from core.agent_builder.base import RAGAgentBuilder, BaseRAGAgentBuilder
from core.agent_builder.multimodal import MultimodalRAGAgentBuilder

# importing os to get env vars
import os
####################
#### META Agent ####
####################
Expand Down Expand Up @@ -47,8 +48,10 @@ def _get_builder_agent_tools(agent_builder: RAGAgentBuilder) -> List[FunctionToo
"""Get list of builder agent tools to pass to the builder agent."""
# see if metaphor api key is set, otherwise don't add web tool
# TODO: refactor this later

if "metaphor_key" in st.secrets:
# removing all use of st.secrets
# relying on good old fashioned env vars
#if "metaphor_key" in st.secrets:
if "METAPHOR_KEY" in os.environ:
fns: List[Callable] = [
agent_builder.create_system_prompt,
agent_builder.load_data,
Expand Down
12 changes: 9 additions & 3 deletions core/builder_config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
"""Configuration."""
import streamlit as st
# no streamlit import here, to ensure we aren't relying on streamlit
# import streamlit as st
# adding os to allow for env vars
import os


### DEFINE BUILDER_LLM #####
## Uncomment the LLM you want to use to construct the meta agent

## OpenAI
from llama_index.llms import OpenAI

# nickknyc's OpenAI key routine
openai_api_key = os.getenv("OPENAI_API_KEY")
# removing Streamlit secrets in favor of env vars
# set OpenAI Key - use Streamlit secrets
os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
# os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
# load LLM
BUILDER_LLM = OpenAI(model="gpt-4-1106-preview")
BUILDER_LLM = OpenAI(model="gpt-4-1106-preview",api_key=openai_api_key)

# # Anthropic (make sure you `pip install anthropic`)
# from llama_index.llms import Anthropic
Expand Down
15 changes: 9 additions & 6 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ def _resolve_llm(llm_str: str) -> LLM:
# - if there is, resolve it
tokens = llm_str.split(":")
if len(tokens) == 1:
os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
# removing all instances of relying on st.secrets
# because using env vars is more well understood and works in all cases
# os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
llm: LLM = OpenAI(model=llm_str)
elif tokens[0] == "local":
llm = resolve_llm(llm_str)
elif tokens[0] == "openai":
os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
# os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
llm = OpenAI(model=tokens[1])
elif tokens[0] == "anthropic":
os.environ["ANTHROPIC_API_KEY"] = st.secrets.anthropic_key
# os.environ["ANTHROPIC_API_KEY"] = st.secrets.anthropic_key
llm = Anthropic(model=tokens[1])
elif tokens[0] == "replicate":
os.environ["REPLICATE_API_KEY"] = st.secrets.replicate_key
# os.environ["REPLICATE_API_KEY"] = st.secrets.replicate_key
llm = Replicate(model=tokens[1])
else:
raise ValueError(f"LLM {llm_str} not recognized.")
Expand Down Expand Up @@ -305,7 +307,8 @@ def get_web_agent_tool() -> QueryEngineTool:

# TODO: set metaphor API key
metaphor_tool = MetaphorToolSpec(
api_key=st.secrets.metaphor_key,
#api_key=st.secrets.metaphor_key,
api_key=os.environ["METAPHOR_KEY"],
)
metaphor_tool_list = metaphor_tool.to_tool_list()

Expand Down Expand Up @@ -437,7 +440,7 @@ def construct_mm_agent(
# first resolve llm and embedding model
embed_model = resolve_embed_model(rag_params.embed_model)
# TODO: use OpenAI for now
os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
# os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
openai_mm_llm = OpenAIMultiModal(model="gpt-4-vision-preview", max_new_tokens=1500)

# first let's index the data with the right parameters
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ llama-hub==0.0.44
# NOTE: this is due to a trivial dependency in the web tool, will refactor
langchain==0.0.305
pypdf
# a dependency of the web tool - was failing when not specified
metaphor-python