Spaces:
Runtime error
Runtime error
| # DEPRECATED: This file has been replaced by gemini_chat_model.py | |
| # Please use GeminiChatModel instead of Gaio for LLM integration | |
| import os | |
| import requests | |
| class Gaio: | |
| def __init__(self, api_key, api_url): | |
| self.api_key = api_key | |
| self.api_url = api_url | |
| def InvokeGaio(self, userPrompt): | |
| payload = { | |
| "model": "azure/gemini-2.5-pro", | |
| "messages": [ | |
| { | |
| "role": "user", | |
| "content": userPrompt | |
| } | |
| ], | |
| "temperature": 0.00, | |
| "max_tokens": 100000, | |
| "stream": False | |
| } | |
| headers = { | |
| "Authorization": f"Bearer {self.api_key}", | |
| "Content-Type": "application/json" | |
| } | |
| # Make the POST request | |
| response = requests.post( | |
| self.api_url, | |
| headers=headers, | |
| json=payload, | |
| timeout=30 | |
| ) | |
| # Parse the JSON response | |
| result = response.json() | |
| message = result["choices"][0]["message"]["content"] | |
| return message | |
| def main(): | |
| """Test Gaio with a simple question and verify the answer.""" | |
| print("Testing Gaio with a simple math question...") | |
| # Get API credentials from environment variables | |
| api_key = os.getenv("GAIO_API_TOKEN") | |
| api_url = os.getenv("GAIO_URL") | |
| if not api_key or not api_url: | |
| print("β Test failed: Missing environment variables.") | |
| print("Please set the following environment variables:") | |
| print("- GAIO_API_TOKEN: Your API token") | |
| print("- GAIO_URL: The API URL") | |
| return | |
| try: | |
| # Create Gaio instance | |
| gaio = Gaio(api_key, api_url) | |
| # Test with the specific question | |
| test_question = "How much is 2 + 2 ? Only answer with the response number and nothing else." | |
| print(f"\nQuestion: {test_question}") | |
| # Get the answer | |
| answer = gaio.InvokeGaio(test_question) | |
| print(f"Answer: '{answer}'") | |
| # Check if the answer is exactly "4" | |
| answer_stripped = answer.strip() | |
| if answer_stripped == "4": | |
| print("β Test passed! The answer is exactly '4'.") | |
| else: | |
| print(f"β Test failed. Expected '4', but got '{answer_stripped}'.") | |
| except Exception as e: | |
| print(f"β Test failed with error: {e}") | |
| if __name__ == "__main__": | |
| main() |