/ working_ai_now.py
working_ai_now.py
  1  #!/usr/bin/env python3
  2  """
  3  CURRENTLY WORKING AI APIS - DEC 2025
  4  """
  5  
  6  import urllib.request
  7  import json
  8  import sys
  9  import time
 10  
 11  def query_deepseek(prompt):
 12      """DeepSeek API - Currently working and free"""
 13      url = "https://api.deepseek.com/chat/completions"
 14      
 15      data = json.dumps({
 16          "model": "deepseek-chat",
 17          "messages": [{"role": "user", "content": prompt}],
 18          "max_tokens": 300,
 19          "stream": False
 20      }).encode('utf-8')
 21      
 22      try:
 23          req = urllib.request.Request(
 24              url,
 25              data=data,
 26              headers={
 27                  'Content-Type': 'application/json',
 28                  'Authorization': 'Bearer sk-xxxx'  # You can get free key at deepseek.com
 29              }
 30          )
 31          
 32          with urllib.request.urlopen(req, timeout=15) as response:
 33              result = json.loads(response.read().decode('utf-8'))
 34              return result['choices'][0]['message']['content']
 35      except Exception as e:
 36          return f"DeepSeek Error: {str(e)[:100]}"
 37  
 38  def query_openrouter_free(prompt):
 39      """OpenRouter with completely free models"""
 40      url = "https://openrouter.ai/api/v1/chat/completions"
 41      
 42      data = json.dumps({
 43          "model": "google/gemma-7b-it:free",
 44          "messages": [{"role": "user", "content": prompt}],
 45          "max_tokens": 300
 46      }).encode('utf-8')
 47      
 48      try:
 49          req = urllib.request.Request(
 50              url,
 51              data=data,
 52              headers={
 53                  'Content-Type': 'application/json',
 54                  'Authorization': 'Bearer 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',
 55                  'HTTP-Referer': 'http://localhost:3000',
 56                  'X-Title': 'AI Tester'
 57              }
 58          )
 59          
 60          with urllib.request.urlopen(req, timeout=15) as response:
 61              result = json.loads(response.read().decode('utf-8'))
 62              return result['choices'][0]['message']['content']
 63      except Exception as e:
 64          return f"OpenRouter Error: {str(e)[:100]}"
 65  
 66  def query_local_huggingface(prompt):
 67      """Hugging Face with local inference"""
 68      try:
 69          # Use HF Inference API
 70          url = "https://api-inference.huggingface.co/models/gpt2"
 71          data = json.dumps({"inputs": prompt}).encode('utf-8')
 72          
 73          req = urllib.request.Request(
 74              url,
 75              data=data,
 76              headers={
 77                  'Content-Type': 'application/json',
 78                  'Authorization': 'Bearer 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'
 79              }
 80          )
 81          
 82          with urllib.request.urlopen(req, timeout=15) as response:
 83              result = json.loads(response.read().decode('utf-8'))
 84              if isinstance(result, list):
 85                  return result[0].get('generated_text', 'No text')[len(prompt):]
 86              return str(result)[:300]
 87      except Exception as e:
 88          return f"HF Error: {str(e)[:100]}"
 89  
 90  def query_together_ai(prompt):
 91      """Together AI - $25 free credit"""
 92      url = "https://api.together.xyz/v1/chat/completions"
 93      
 94      data = json.dumps({
 95          "model": "mistralai/Mistral-7B-Instruct-v0.2",
 96          "messages": [{"role": "user", "content": prompt}],
 97          "max_tokens": 300,
 98          "temperature": 0.7
 99      }).encode('utf-8')
100      
101      try:
102          # You need to sign up at together.ai for free $25
103          key = "YOUR_TOGETHER_KEY"  # Get from together.ai
104          req = urllib.request.Request(
105              url,
106              data=data,
107              headers={
108                  'Content-Type': 'application/json',
109                  'Authorization': f'Bearer {key}'
110              }
111          )
112          
113          with urllib.request.urlopen(req, timeout=15) as response:
114              result = json.loads(response.read().decode('utf-8'))
115              return result['choices'][0]['message']['content']
116      except Exception as e:
117          return f"Together AI: Sign up at together.ai for free $25 credit"
118  
119  def main():
120      print("šŸ¤– WORKING AI APIS - DECEMBER 2025")
121      print("="*50)
122      
123      # Get question
124      if len(sys.argv) > 1:
125          question = " ".join(sys.argv[1:])
126      else:
127          print("\nWhat would you like to know?")
128          question = sys.stdin.readline().strip() or "What is AI?"
129      
130      print(f"\nšŸ“ Question: {question}")
131      
132      # Try different APIs
133      print("\n1. Trying OpenRouter (free Gemma model)...")
134      response1 = query_openrouter_free(question)
135      print(f"   Response: {response1[:200]}...")
136      
137      print("\n2. Trying Hugging Face GPT-2...")
138      response2 = query_local_huggingface(question)
139      print(f"   Response: {response2[:200]}...")
140      
141      print("\n3. Together AI (needs free registration)...")
142      print("   " + query_together_ai(question))
143      
144      print("\n" + "="*50)
145      print("šŸ’” To get free API keys:")
146      print("1. OpenRouter: https://openrouter.ai (free models)")
147      print("2. Together AI: https://together.ai ($25 free)")
148      print("3. DeepSeek: https://platform.deepseek.com (free tier)")
149      print("="*50)
150  
151  if __name__ == "__main__":
152      main()