From c8f961b483feefa1674048c0271b5076b611b75b Mon Sep 17 00:00:00 2001 From: kimyd Date: Tue, 10 Oct 2023 16:39:12 +0900 Subject: [PATCH] added azure openai model --- Chat2VIS.py | 17 +++++++++++++++-- classes.py | 23 +++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Chat2VIS.py b/Chat2VIS.py index fcc0eee..85c15a1 100644 --- a/Chat2VIS.py +++ b/Chat2VIS.py @@ -36,7 +36,7 @@ st.sidebar.markdown('Blog 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 @@ -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() @@ -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.") @@ -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) diff --git a/classes.py b/classes.py index e789a70..b2ca144 100644 --- a/classes.py +++ b/classes.py @@ -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":