Skip to content

Commit

Permalink
fix pydantic error
Browse files Browse the repository at this point in the history
  • Loading branch information
sborms committed Oct 22, 2023
1 parent 4cf29f2 commit e62807f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions webapp/pages/05_📣_Coachbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@


@st.cache_resource()
def load_chain(openai_api_key="sk-...", context=""):
def load_chain(input_openai_api_key="sk-...", context=""):
"""Configures a conversational chain for answering user questions."""
if input_openai_api_key is None: # avoid pydantic.v1.error_wrappers.ValidationError
input_openai_api_key = "sk-..."
# load OpenAI's language model
llm = ChatOpenAI(
temperature=0.5, model="gpt-3.5-turbo", openai_api_key=openai_api_key
temperature=0.5, model="gpt-3.5-turbo", openai_api_key=input_openai_api_key
)
del openai_api_key
del input_openai_api_key

# create chat history memory
memory = ConversationBufferWindowMemory(
Expand Down Expand Up @@ -110,15 +112,15 @@ def prepare_prompt_team_context(dict_info):
)

if "Basic" in bot_type:
openai_api_key = st.secrets["openai"]["api_key_free"]
input_openai_api_key = st.secrets["openai"]["api_key_free"]
elif "Advanced" in bot_type:
st.info(
"""
Enter your OpenAI API key (we won't expose it!) to use your own account.
For pricing info see [here](https://openai.com/pricing#language-models).
"""
)
openai_api_key = st.text_input(
input_openai_api_key = st.text_input(
"Paste your key here:",
type="password",
placeholder="sk-...",
Expand Down Expand Up @@ -151,7 +153,7 @@ def prepare_prompt_team_context(dict_info):
context = prepare_prompt_team_context(dict_info)

# configure chain
chain = load_chain(openai_api_key, context=context)
chain = load_chain(input_openai_api_key, context=context)

# initialize chat history
if "messages" not in st.session_state:
Expand Down

0 comments on commit e62807f

Please sign in to comment.