Files

1 line
4.6 KiB
JSON

{"repo": "ali-glitchh/krypt", "files": {"update_api_key.py": {"f8511f4a811d94ffbd54e6f538036d9e1b5a49fe": {"t": 1785674100.1404088, "n": 4303, "h": "e555a2b4cfd06f40", "c": "#!/usr/bin/env python3\n\"\"\"\nMoonshotAI API Key Updater\nScript to easily update the API key when you get a new one\n\"\"\"\n\nimport os\n\ndef update_api_key():\n \"\"\"Interactive script to update MoonshotAI API key\"\"\"\n \n print(\"🔑 MoonshotAI API Key Updater\")\n print(\"=\" * 40)\n \n # Get new API key from user\n print(\"\\n📝 Enter your new MoonshotAI API key:\")\n print(\" Format should be: sk-xxxxxxxxxxxxxxxxxxxxxxx\")\n print(\" (Leave blank to cancel)\")\n \n new_key = input(\"\\nAPI Key: \").strip()\n \n if not new_key:\n print(\"❌ No key entered. Operation cancelled.\")\n return\n \n if not new_key.startswith('sk-'):\n print(\"⚠️ Warning: API key doesn't start with 'sk-'. Continue anyway? (y/N)\")\n confirm = input().strip().lower()\n if confirm != 'y':\n print(\"❌ Operation cancelled.\")\n return\n \n # Update the main chatbot file\n file_path = \"improved_dual_personality_chatbot.py\"\n \n try:\n # Read current file\n with open(file_path, 'r', encoding='utf-8') as f:\n content = f.read()\n \n # Find and replace the old API key\n old_key_start = 'moonshot_api_key = \"sk-'\n new_key_line = f'moonshot_api_key = \"{new_key}\"'\n \n if old_key_start in content:\n # Find the line with the old key\n lines = content.split('\\n')\n for i, line in enumerate(lines):\n if line.strip().startswith('moonshot_api_key = \"sk-'):\n lines[i] = f' {new_key_line}'\n print(f\"✅ Found old API key on line {i+1}\")\n break\n \n # Write updated content\n updated_content = '\\n'.join(lines)\n \n with open(file_path, 'w', encoding='utf-8') as f:\n f.write(updated_content)\n \n print(f\"✅ API key updated in {file_path}\")\n \n else:\n print(f\"⚠️ Could not find old API key in {file_path}\")\n print(\"You may need to update it manually.\")\n \n # Also update the MoonshotAI integration file if needed\n moonshot_file = \"moonshot_ai_integration.py\"\n if os.path.exists(moonshot_file):\n print(f\"\\n🔍 Checking {moonshot_file}...\")\n with open(moonshot_file, 'r', encoding='utf-8') as f:\n moonshot_content = f.read()\n \n if 'sk-or-v1-' in moonshot_content:\n moonshot_content = moonshot_content.replace(\n '\"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\"',\n f'\"{new_key}\"'\n )\n \n with open(moonshot_file, 'w', encoding='utf-8') as f:\n f.write(moonshot_content)\n \n print(f\"✅ API key also updated in {moonshot_file}\")\n \n print(f\"\\n🧪 Testing new API key...\")\n \n # Test the new key\n try:\n from moonshot_ai_integration import MoonshotAIIntegration\n \n test_moonshot = MoonshotAIIntegration(api_key=new_key)\n test_response = test_moonshot.get_crypto_specific_response(\"Hello, test message\")\n \n if test_response:\n print(\"✅ New API key works! Test response received.\")\n print(f\" Model: {test_response.get('model_used', 'N/A')}\")\n print(f\" Tokens: {test_response.get('tokens_used', 0)}\")\n else:\n print(\"⚠️ Test response failed. Key may be invalid or have no credits.\")\n \n except Exception as e:\n print(f\"⚠️ API test failed: {e}\")\n print(\"This might be due to network issues or key problems.\")\n \n print(f\"\\n🎉 API Key Update Complete!\")\n print(\"Your KoinToss AI chatbot is now ready with the new MoonshotAI key!\")\n print(\"\\nNext steps:\")\n print(\"1. Test with: python test_moonshot_direct.py\")\n print(\"2. Launch app: streamlit run streamlit_app.py\")\n \n except Exception as e:\n print(f\"❌ Error updating API key: {e}\")\n print(\"You may need to update the key manually in the source files.\")\n\nif __name__ == \"__main__\":\n update_api_key()\n"}}}}