Skip to content

Commit

Permalink
Merge pull request #19 from doccano/feature/api-key-fallback
Browse files Browse the repository at this point in the history
API key fallback
  • Loading branch information
Hironsan authored Mar 24, 2023
2 parents 18cd80f + 7aa84a0 commit 8255306
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion doccano_mini/components.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional

import streamlit as st
from langchain.llms import OpenAI
Expand Down Expand Up @@ -33,7 +34,7 @@ def task_instruction_editor(prompt: FewShotPromptTemplate) -> FewShotPromptTempl
return prompt


def openai_model_form() -> BaseLanguageModel:
def openai_model_form() -> Optional[BaseLanguageModel]:
# https://platform.openai.com/docs/models/gpt-3-5
AVAILABLE_MODELS = (
"gpt-3.5-turbo",
Expand All @@ -43,6 +44,8 @@ def openai_model_form() -> BaseLanguageModel:
"code-davinci-002",
)
api_key = st.text_input("API key", value=os.environ.get("OPENAI_API_KEY", ""), type="password")
if not api_key:
return None
model_name = st.selectbox("Model", AVAILABLE_MODELS, index=2)
temperature = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.01)
top_p = st.slider("Top-p", min_value=0.0, max_value=1.0, value=1.0, step=0.01)
Expand Down
7 changes: 5 additions & 2 deletions doccano_mini/pages/01_Text_Classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
with st.expander("See your prompt"):
st.markdown(f"```\n{prompt.format(**inputs)}\n```")

if st.button("Predict"):
chain = LLMChain(llm=llm, prompt=prompt)
if llm is None:
st.error("Enter your API key.")

if st.button("Predict", disabled=llm is None):
chain = LLMChain(llm=llm, prompt=prompt) # type:ignore
response = chain.run(**inputs)
st.text(response)

Expand Down
7 changes: 5 additions & 2 deletions doccano_mini/pages/09_Task_Free.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
with st.expander("See your prompt"):
st.markdown(f"```\n{prompt.format(**inputs)}\n```")

if st.button("Predict"):
chain = LLMChain(llm=llm, prompt=prompt)
if llm is None:
st.error("Enter your API key.")

if st.button("Predict", disabled=llm is None):
chain = LLMChain(llm=llm, prompt=prompt) # type:ignore
response = chain.run(**inputs)
st.text(response)

Expand Down

0 comments on commit 8255306

Please sign in to comment.