Spaces:
Sleeping
Sleeping
Download additional_function.py from harshadh01/ai-rest-api-generator: direct link, hf CLI and curl.
- Browser
- Download file 803 Bytes
-
https://huggingface.co/spaces/harshadh01/ai-rest-api-generator/resolve/main/additional_function.py
- Command line
-
hf download hf://spaces/harshadh01/ai-rest-api-generator/additional_function.py
-
curl -L -o additional_function.py https://huggingface.co/spaces/harshadh01/ai-rest-api-generator/resolve/main/additional_function.py
803 Bytes
| from langchain_groq import ChatGroq | |
| from langchain_openai import ChatOpenAI | |
| import os | |
| def get_llm(provider: str, api_key: str): | |
| if not api_key or not api_key.strip(): | |
| raise ValueError("API key is missing or empty") | |
| provider = provider.lower() | |
| if provider == "groq": | |
| # ✅ Set env var as fallback (Groq SDK expects this sometimes) | |
| os.environ["GROQ_API_KEY"] = api_key | |
| return ChatGroq( | |
| model="openai/gpt-oss-120b", | |
| api_key=api_key, | |
| temperature=0 | |
| ) | |
| elif provider == "openai": | |
| return ChatOpenAI( | |
| model="gpt-4o-mini", | |
| api_key=api_key, | |
| temperature=0 | |
| ) | |
| else: | |
| raise ValueError(f"Unsupported LLM provider: {provider}") | |