Update app.py
Browse files
app.py
CHANGED
|
@@ -4,13 +4,11 @@ import gradio as gr
|
|
| 4 |
import openai
|
| 5 |
import google.generativeai as palm
|
| 6 |
|
| 7 |
-
#from dotenv import load_dotenv
|
| 8 |
-
#load_dotenv()
|
| 9 |
-
|
| 10 |
|
| 11 |
llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
|
| 12 |
TEST_MESSAGE = "Write an introductory paragraph to explain Generative AI to the reader of this content."
|
| 13 |
-
openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-turbo",
|
|
|
|
| 14 |
"gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
|
| 15 |
"text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
|
| 16 |
|
|
@@ -19,7 +17,8 @@ google_palm_models = ["models/text-bison-001", "models/chat-bison-001","models/e
|
|
| 19 |
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
|
| 20 |
azure_deployment_name = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
|
| 21 |
google_palm_key = os.getenv("GOOGLE_PALM_AI_API_KEY")
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
def openai_text_completion(prompt: str, model: str):
|
| 25 |
try:
|
|
@@ -34,7 +33,7 @@ def openai_text_completion(prompt: str, model: str):
|
|
| 34 |
{"role": "assistant", "content": f"{assistant_prompt}"}
|
| 35 |
]
|
| 36 |
|
| 37 |
-
openai.api_key =
|
| 38 |
openai.api_version = '2020-11-07'
|
| 39 |
|
| 40 |
completion = openai.ChatCompletion.create(
|
|
@@ -61,7 +60,7 @@ def azure_openai_text_completion(prompt: str, model: str):
|
|
| 61 |
{"role": "assistant", "content": f"{assistant_prompt}"}
|
| 62 |
]
|
| 63 |
|
| 64 |
-
openai.api_key =
|
| 65 |
openai.api_type = "azure"
|
| 66 |
openai.api_version = "2023-05-15"
|
| 67 |
openai.api_base = f"https://{azure_endpoint}.openai.azure.com"
|
|
|
|
| 4 |
import openai
|
| 5 |
import google.generativeai as palm
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
llm_api_options = ["OpenAI API","Azure OpenAI API","Google PaLM API", "Llama 2"]
|
| 9 |
TEST_MESSAGE = "Write an introductory paragraph to explain Generative AI to the reader of this content."
|
| 10 |
+
openai_models = ["gpt-4", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-turbo",
|
| 11 |
+
|
| 12 |
"gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "text-davinci-003",
|
| 13 |
"text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"]
|
| 14 |
|
|
|
|
| 17 |
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
|
| 18 |
azure_deployment_name = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
|
| 19 |
google_palm_key = os.getenv("GOOGLE_PALM_AI_API_KEY")
|
| 20 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 21 |
+
azure_openai_api_key = os.getenv("AZURE_OPENAI_KEY")
|
| 22 |
|
| 23 |
def openai_text_completion(prompt: str, model: str):
|
| 24 |
try:
|
|
|
|
| 33 |
{"role": "assistant", "content": f"{assistant_prompt}"}
|
| 34 |
]
|
| 35 |
|
| 36 |
+
openai.api_key = openai_api_key
|
| 37 |
openai.api_version = '2020-11-07'
|
| 38 |
|
| 39 |
completion = openai.ChatCompletion.create(
|
|
|
|
| 60 |
{"role": "assistant", "content": f"{assistant_prompt}"}
|
| 61 |
]
|
| 62 |
|
| 63 |
+
openai.api_key = azure_openai_api_key
|
| 64 |
openai.api_type = "azure"
|
| 65 |
openai.api_version = "2023-05-15"
|
| 66 |
openai.api_base = f"https://{azure_endpoint}.openai.azure.com"
|