Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Chat2VIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
st.sidebar.markdown('<a style="text-align: center;padding-top: 0rem;" href="https://blog.streamlit.io/chat2vis-ai-driven-visualisations-with-streamlit-and-natural-language">Blog </a> by Paula Maddigan', unsafe_allow_html=True)


available_models = {"ChatGPT-4": "gpt-4","ChatGPT-3.5": "gpt-3.5-turbo","GPT-3": "text-davinci-003",
available_models = {"azure ChatGPT-3.5": "azure-gpt-35-turbo", "ChatGPT-4": "gpt-4","ChatGPT-3.5": "gpt-3.5-turbo","GPT-3": "text-davinci-003",
"GPT-3.5 Instruct": "gpt-3.5-turbo-instruct","Code Llama":"CodeLlama-34b-Instruct-hf"}

# List to hold datasets
Expand All @@ -59,6 +59,10 @@
openai_key = key_col1.text_input(label = ":key: OpenAI Key:", help="Required for ChatGPT-4, ChatGPT-3.5, GPT-3, GPT-3.5 Instruct.",type="password")
hf_key = key_col2.text_input(label = ":hugging_face: HuggingFace Key:",help="Required for Code Llama", type="password")

key_col3,key_col4 = st.columns(2)
azure_api_key = key_col3.text_input(label = "Azure OpenAI Key:", help="Required for Azure ChatGPT-3.5",type="password")
azure_end_point = key_col4.text_input(label = "Azure API Base",help="Required for Azure ChatGPT-3.5", type="password")

with st.sidebar:
# First we want to choose the dataset, but we will fill it with choices once we've loaded one
dataset_container = st.empty()
Expand Down Expand Up @@ -100,6 +104,14 @@
if go_btn and model_count > 0:
api_keys_entered = True
# Check API keys are entered.
if "azure ChatGPT-3.5" in selected_models:
# check the keys input is empty or not
if azure_api_key.__len__() < 16:
st.error("Please enter a valid Azure OpenAI API key.")
api_keys_entered = False
if not azure_end_point.startswith('https://'):
st.error("Please enter a valid Azure API Base.")
api_keys_entered = False
if "ChatGPT-4" in selected_models or "ChatGPT-3.5" in selected_models or "GPT-3" in selected_models or "GPT-3.5 Instruct" in selected_models:
if not openai_key.startswith('sk-'):
st.error("Please enter a valid OpenAI API key.")
Expand All @@ -122,7 +134,8 @@
question_to_ask = format_question(primer1, primer2, question, model_type)
# Run the question
answer=""
answer = run_request(question_to_ask, available_models[model_type], key=openai_key,alt_key=hf_key)
answer = run_request(question_to_ask, available_models[model_type], key=openai_key,alt_key=hf_key,
azure_api_key=azure_api_key,azure_end_point=azure_end_point)
# the answer is the completed Python script so add to the beginning of the script to it.
answer = primer2 + answer
print("Model: " + model_type)
Expand Down
23 changes: 21 additions & 2 deletions classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@
import openai
from langchain import HuggingFaceHub, LLMChain,PromptTemplate

def run_request(question_to_ask, model_type, key, alt_key):
if model_type == "gpt-4" or model_type == "gpt-3.5-turbo" :
def run_request(question_to_ask, model_type, key, alt_key, azure_api_key, azure_end_point):
if model_type == "azure-gpt-35-turbo":
task = "Generate Python Code Script."
openai.api_type = "azure"
openai.api_key = azure_api_key
openai.api_base = azure_end_point
openai.api_version = "2023-05-15" # subject to change
print("question_to_ask : {}".format(question_to_ask))
message = [{"role": "system", "content": task},
{"role": "user", "content": question_to_ask}]
response = openai.ChatCompletion.create(
engine="gpt-35-turbo",
messages=message,
temperature=0.5,
top_p=0.9,
frequency_penalty=0,
presence_penalty=0,
)
llm_response = response["choices"][0]["message"]["content"]

elif model_type == "gpt-4" or model_type == "gpt-3.5-turbo" :
# Run OpenAI ChatCompletion API
task = "Generate Python Code Script."
if model_type == "gpt-4":
Expand Down