Download connection.py from abdullah9873/js-engineer-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 768 Bytes
-
https://huggingface.co/spaces/abdullah9873/js-engineer-chatbot/resolve/main/connection.py
- Command line
-
hf download hf://spaces/abdullah9873/js-engineer-chatbot/connection.py
-
curl -L -o connection.py https://huggingface.co/spaces/abdullah9873/js-engineer-chatbot/resolve/main/connection.py
768 Bytes
| from dotenv import load_dotenv | |
| import os | |
| from agents import AsyncOpenAI, ModelSettings, OpenAIChatCompletionsModel, RunConfig | |
| load_dotenv() | |
| # Load OpenAI API key | |
| openai_api_key = os.getenv("OPENAI_API_KEY") | |
| if not openai_api_key: | |
| print("WARNING: OPENAI_API_KEY is not set. The chatbot will fail when processing requests.") | |
| openai_api_key = "missing-key" # Prevent AsyncOpenAI from crashing immediately on init | |
| # Create OpenAI client (NO base_url needed) | |
| openai_client = AsyncOpenAI( | |
| api_key=openai_api_key | |
| ) | |
| # Choose OpenAI model | |
| model = OpenAIChatCompletionsModel( | |
| model="gpt-4o-mini", | |
| openai_client=openai_client, | |
| ) | |
| # Run configuration | |
| config = RunConfig( | |
| model=model, | |
| model_provider=openai_client | |
| ) | |