Spaces:
Sleeping
Sleeping
Download ai_engine.py from 404chain/Signal_bot: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/404chain/Signal_bot/resolve/main/ai_engine.py
- Command line
-
hf download hf://spaces/404chain/Signal_bot/ai_engine.py
-
curl -L -o ai_engine.py https://huggingface.co/spaces/404chain/Signal_bot/resolve/main/ai_engine.py
2.15 kB
| import os | |
| import requests | |
| OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY") | |
| OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions" | |
| MODEL_NAME = "openai/gpt-4o-mini" | |
| def ask_ai(ta, symbol, question, regime): | |
| if not OPENROUTER_API_KEY: | |
| return "❌ OPENROUTER_API_KEY belum diset" | |
| try: | |
| prompt = f""" | |
| Kamu adalah AI hedge fund crypto analyst profesional. | |
| Style: | |
| - Natural | |
| - Tidak kaku | |
| - Seperti trader institusional | |
| - Fokus probabilitas | |
| - Fokus risk management | |
| - Fokus market psychology | |
| - Jangan terlalu optimistic | |
| ================================================ | |
| MARKET DATA | |
| Symbol: {symbol}/USDT | |
| Trend: {ta['trend']} | |
| Market Regime: {regime['regime']} | |
| Confidence: {ta['confidence']}% | |
| Price: {ta['price']} | |
| EMA20: {ta['ema20']} | |
| EMA50: {ta['ema50']} | |
| EMA100: {ta['ema100']} | |
| RSI: {ta['rsi']} | |
| MACD: {ta['macd']} | |
| Support: {ta['support']} | |
| Resistance: {ta['resistance']} | |
| ================================================ | |
| USER QUESTION | |
| {question} | |
| ================================================ | |
| WAJIB: | |
| 1. Jelaskan kondisi market | |
| 2. Jelaskan momentum | |
| 3. Jelaskan risk | |
| 4. Jelaskan kemungkinan bullish dan bearish | |
| 5. Berikan insight trading | |
| 6. Jangan terlalu pendek | |
| 7. Gunakan bahasa trader profesional | |
| """ | |
| payload = { | |
| "model": MODEL_NAME, | |
| "messages": [ | |
| { | |
| "role": "system", | |
| "content": "Kamu AI crypto analyst profesional." | |
| }, | |
| { | |
| "role": "user", | |
| "content": prompt | |
| } | |
| ], | |
| "temperature": 0.7, | |
| "max_tokens": 1200 | |
| } | |
| headers = { | |
| "Authorization": f"Bearer {OPENROUTER_API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| response = requests.post( | |
| OPENROUTER_URL, | |
| headers=headers, | |
| json=payload, | |
| timeout=60 | |
| ) | |
| response.raise_for_status() | |
| data = response.json() | |
| return data["choices"][0]["message"]["content"] | |
| except Exception as e: | |
| return f"❌ AI Error: {e}" |