Skip to content

Instantly share code, notes, and snippets.

@izikeros
Last active March 15, 2024 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izikeros/5bfad1731b8a67eb7ceed792138a09ed to your computer and use it in GitHub Desktop.
Save izikeros/5bfad1731b8a67eb7ceed792138a09ed to your computer and use it in GitHub Desktop.
[azure openai config] Configure azure openai with data from .env file #openai #llm
import os
import openai
from dotenv import find_dotenv
from dotenv import load_dotenv
def configure_openai():
# Configure OpenAI using load dotenv and find .env file
env_file = find_dotenv()
load_dotenv(env_file, verbose=True, override=True)
openai.api_type = "azure"
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.api_base = os.getenv("OPENAI_API_BASE")
openai.api_version = os.getenv("OPENAI_API_VERSION")
completion_deployment_name = os.getenv("OPENAI_QA_DEPLOYMENT_NAME")
print(f"using {completion_deployment_name}")
return openai, completion_deployment_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment