Skip to content

Commit

Permalink
App init: rename OPENAI_KEY for consistent naming convention
Browse files Browse the repository at this point in the history
Rename this variable in your .env or production environment and restart
your app to pick up the changes.

OPENAI_KEY -> OPENAI_API_KEY
  • Loading branch information
oshoma committed Aug 17, 2023
1 parent a3e9b6d commit 9c0ea28
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/slackbot/.env-sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OpenAI. Mandatory. Enables language modeling.
OPENAI_KEY= # OpenAI API key
OPENAI_API_KEY= # OpenAI API key

# Serper.dev. Optional. Enables Google web search capability
# SERPER_API_KEY= # Serper.dev API key
Expand Down
6 changes: 3 additions & 3 deletions apps/slackbot/bolt_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

if cfg.PINECONE_API_KEY is None:
print("Setting up local Chroma database")
local_memory = LocalChromaStore.from_folder('files', cfg.OPENAI_KEY).as_retriever()
local_memory = LocalChromaStore.from_folder('files', cfg.OPENAI_API_KEY).as_retriever()

###########################################################################
# Define Slack client functionality:
Expand Down Expand Up @@ -183,13 +183,13 @@ def show_commands_only(logger):

def get_response(question, previous_messages):
llm = ChatOpenAI(
openai_api_key=cfg.OPENAI_KEY, request_timeout=120
openai_api_key=cfg.OPENAI_API_KEY, request_timeout=120
)

if cfg.PINECONE_API_KEY:
# If pinecone API is specified, then use the Pinecone Database
memory = ConversationStore.get_vector_retrieval(
cfg.PINECONE_NAMESPACE, cfg.OPENAI_KEY, index_name=cfg.PINECONE_INDEX, search_type='similarity_score_threshold', search_kwargs={'score_threshold': 0.0}
cfg.PINECONE_NAMESPACE, cfg.OPENAI_API_KEY, index_name=cfg.PINECONE_INDEX, search_type='similarity_score_threshold', search_kwargs={'score_threshold': 0.0}
)
else:
# use the local Chroma database
Expand Down
7 changes: 2 additions & 5 deletions apps/slackbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SLACK_OAUTH_TOKEN = environ.get('SLACK_OAUTH_TOKEN')
SLACK_VERIFICATION_TOKEN = environ.get('SLACK_VERIFICATION_TOKEN')
SLACK_PORT = environ.get('SLACK_PORT', 3000)
OPENAI_KEY=environ.get('OPENAI_KEY')
OPENAI_API_KEY=environ.get('OPENAI_API_KEY')
PINECONE_API_KEY = environ.get('PINECONE_API_KEY')
PINECONE_NAMESPACE = environ.get('PINECONE_NAMESPACE', 'ReadTheDocs')
PINECONE_ENV = environ.get('PINECONE_ENV')
Expand All @@ -42,15 +42,12 @@
else:
print('Config: Slack environment variables are set')

if this.OPENAI_KEY is None:
if this.OPENAI_API_KEY is None:
print('Config: OpenAI environment variables not set, unable to run')
raise SystemExit(1)
else:
print('Config: OpenAI environment variables are set')

# TODO verify we need OPENAI_API_KEY; can we just use OPENAI_KEY instead?
os.environ['OPENAI_API_KEY'] = this.OPENAI_KEY

if this.PINECONE_API_KEY is None:
print('Config: Pinecone environment variables not set')
else:
Expand Down
2 changes: 1 addition & 1 deletion apps/slackbot/scrape/extract_github_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def extract_github_readme(repo_url):
def save_to_pine_cone(content,metadatas):
pinecone.init(api_key=cfg.PINECONE_API_KEY, environment=cfg.PINECONE_ENV)
index = pinecone.Index("langchain")
embeddings = OpenAIEmbeddings(openai_api_key=cfg.OPENAI_KEY)
embeddings = OpenAIEmbeddings(openai_api_key=cfg.OPENAI_API_KEY)

vectorstore = ConversationStore("Github_data", index, embeddings, 'text')
vectorstore.add_texts(content,metadatas)
4 changes: 2 additions & 2 deletions apps/slackbot/scrape/prompt_reconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def reconstruct_prompt(self):

chunk_summary = chunk_and_summerize(
link=link,
open_ai_key=cfg.OPENAI_KEY,
open_ai_key=cfg.OPENAI_API_KEY,
question=question,
text_data=scraped_data["data"]
)
Expand All @@ -47,7 +47,7 @@ def reconstruct_prompt(self):

chunk_summary = chunk_and_summerize(
link=link,
open_ai_key=cfg.OPENAI_KEY,
open_ai_key=cfg.OPENAI_API_KEY,
question=question,
text_data=chunk_summary
)
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/slackbot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ After you clone the repository, you can find the slackbot project under `apps/sl

.. image:: slackbot_imgs/slackbot2.png
:width: 400
* The `OPENAI_KEY` can be found in your OpenAI account page. If you don't have an account, create one at https://platform.openai.com/overview. Remember to upgrade to a paid account after using any free credits you're given by OpenAI, or you will encounter `openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details`.
* The `OPENAI_API_KEY` can be found in your OpenAI account page. If you don't have an account, create one at https://platform.openai.com/overview. Remember to upgrade to a paid account after using any free credits you're given by OpenAI, or you will encounter `openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details`.
* Serper is a search engine that we will use to search for relevant articles. You can find the API key in your Serper account page. If you don't have an account, create one at https://serpapi.com/. Serper is optional -- you don't need it to run the app -- but adding Serper will enable the Internet search function of the SlackBot. If you don't want to have this functionality, leave the `SERPER_API_KEY` empty.
* You may also find there are *PINECONE_xxx* key/value pairs in the `.env` file. Pinecone is a cloud-based vector database. By default, this app runs with an in-memory (local) vector database called Chroma. However, if you want to build your own cloud vector database with Pinecone, you can learn more about that here: https://www.pinecone.io/.

Expand Down
2 changes: 1 addition & 1 deletion scripts/transcript_summarizer_aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# instantiate chat model
chat = ChatOpenAI(
openai_api_key=cfg.OPENAI_KEY,
openai_api_key=cfg.OPENAI_API_KEY,
temperature=0,
model='gpt-3.5-turbo')

Expand Down

0 comments on commit 9c0ea28

Please sign in to comment.