/ final_orchestrator.py
final_orchestrator.py
1 #!/usr/bin/env python3 2 """ 3 FINAL WORKING ORCHESTRATOR for Kali Linux 4 """ 5 6 import urllib.request 7 import json 8 import sys 9 from datetime import datetime 10 11 # API Keys 12 GEMINI_KEY = "AIzaSyC9g4B4sY9xeaUntjNmN2MeWFyp5gL3_EM" 13 GROQ_KEY = "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" 14 15 def call_api(api_name, prompt): 16 """Call API using urllib (works on Kali)""" 17 18 if api_name == "gemini": 19 # Working Gemini endpoint 20 url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={GEMINI_KEY}" 21 22 data = json.dumps({ 23 "contents": [{"parts": [{"text": prompt}]}], 24 "generationConfig": {"maxOutputTokens": 300} 25 }) 26 27 try: 28 req = urllib.request.Request( 29 url, 30 data=data.encode('utf-8'), 31 headers={'Content-Type': 'application/json'} 32 ) 33 34 with urllib.request.urlopen(req, timeout=15) as response: 35 result = json.loads(response.read().decode('utf-8')) 36 return result['candidates'][0]['content']['parts'][0]['text'] 37 38 except Exception as e: 39 return f"Error: {str(e)[:100]}" 40 41 elif api_name == "groq": 42 # Groq API 43 url = "https://api.groq.com/openai/v1/chat/completions" 44 45 data = json.dumps({ 46 "model": "llama3-8b-8192", 47 "messages": [{"role": "user", "content": prompt}], 48 "max_tokens": 300, 49 "temperature": 0.7 50 }) 51 52 try: 53 req = urllib.request.Request( 54 url, 55 data=data.encode('utf-8'), 56 headers={ 57 'Authorization': f'Bearer {GROQ_KEY}', 58 'Content-Type': 'application/json' 59 } 60 ) 61 62 with urllib.request.urlopen(req, timeout=15) as response: 63 result = json.loads(response.read().decode('utf-8')) 64 return result['choices'][0]['message']['content'] 65 66 except Exception as e: 67 return f"Error: {str(e)[:100]}" 68 69 return "API not available" 70 71 def main(): 72 print("š AI ORCHESTRATOR - KALI EDITION") 73 print("="*50) 74 75 # Get question 76 if len(sys.argv) > 1: 77 question = " ".join(sys.argv[1:]) 78 else: 79 print("\nWhat would you like to know?") 80 print("Example: 'Explain quantum computing'") 81 question = sys.stdin.readline().strip() or "What is artificial intelligence?" 82 83 print(f"\nš¤ Question: {question}") 84 print("\nš Getting answers from multiple AIs...") 85 86 # Query both APIs 87 print("\n1. Querying Google Gemini...") 88 gemini_response = call_api("gemini", question) 89 90 print("2. Querying Groq (Llama 3)...") 91 groq_response = call_api("groq", question) 92 93 # Display results 94 print("\n" + "="*50) 95 print("š AI RESPONSES") 96 print("="*50) 97 98 print(f"\nš¤ GOOGLE GEMINI:") 99 print("-"*30) 100 print(gemini_response[:500] + ("..." if len(gemini_response) > 500 else "")) 101 102 print(f"\nā” GROQ (LLAMA 3):") 103 print("-"*30) 104 print(groq_response[:500] + ("..." if len(groq_response) > 500 else "")) 105 106 # Save results 107 timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") 108 filename = f"ai_comparison_{timestamp}.txt" 109 110 with open(filename, 'w', encoding='utf-8') as f: 111 f.write(f"Question: {question}\n") 112 f.write(f"Time: {datetime.now()}\n\n") 113 f.write("GOOGLE GEMINI:\n") 114 f.write(gemini_response + "\n\n") 115 f.write("GROQ (LLAMA 3):\n") 116 f.write(groq_response + "\n\n") 117 118 print(f"\nš¾ Saved to: {filename}") 119 print("="*50) 120 121 if __name__ == "__main__": 122 main()