MCPcopy Create free account
hub / github.com/Azure-Samples/rag-postgres-openai-python / get_openai_config

Function get_openai_config

evals/evaluate.py:42–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40
41
42def get_openai_config() -> dict:
43 openai_config: dict[str, Any]
44 if os.environ.get("OPENAI_CHAT_HOST") == "azure":
45 azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"]
46 azure_deployment = os.environ["AZURE_OPENAI_EVAL_DEPLOYMENT"]
47 if os.environ.get("AZURE_OPENAI_KEY"):
48 logger.info("Using Azure OpenAI Service with API Key from AZURE_OPENAI_KEY")
49 openai_config = {
50 "azure_endpoint": azure_endpoint,
51 "azure_deployment": azure_deployment,
52 "api_key": os.environ["AZURE_OPENAI_KEY"],
53 }
54 else:
55 if tenant_id := os.getenv("AZURE_TENANT_ID"):
56 logger.info("Authenticating to Azure using Azure Developer CLI Credential for tenant %s", tenant_id)
57 azure_credential = azure.identity.AzureDeveloperCliCredential(tenant_id=tenant_id, process_timeout=60)
58 else:
59 logger.info("Authenticating to Azure using Azure Developer CLI Credential")
60 azure_credential = azure.identity.AzureDeveloperCliCredential(process_timeout=60)
61 openai_config = {
62 "azure_endpoint": azure_endpoint,
63 "azure_deployment": azure_deployment,
64 "credential": azure_credential,
65 }
66 # azure-ai-evaluate will call DefaultAzureCredential behind the scenes,
67 # so we must be logged in to Azure CLI with the correct tenant
68 openai_config["model"] = os.environ["AZURE_OPENAI_EVAL_MODEL"]
69 elif os.environ.get("OPENAI_CHAT_HOST") == "ollama":
70 raise NotImplementedError("Ollama is not supported. Switch to Azure or OpenAI.com")
71 else:
72 logger.info("Using OpenAI Service with API Key from OPENAICOM_KEY")
73 openai_config = {"api_key": os.environ["OPENAICOM_KEY"], "model": "gpt-4"}
74 return openai_config
75
76
77if __name__ == "__main__":

Callers 1

evaluate.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected