mirror of
https://github.com/chrisnov-it/quantumbotx.git
synced 2026-07-28 11:17:44 +00:00
aa984c4909
- Update `.gitignore` to include `lab/` for backtesting and raw data. - Refactor `app.py` to improve error handling and logging. - Remove deprecated files: `core/bot_logic.py`, `core/bots/base_bot.py`, `core/bots/manager.py`, `core/db/database.py`, `core/routes/api_analysis.py`, `core/routes/api_bots_analysis.py`, `core/strategies/logic_ma.py`, `core/strategies/logic_rsi.py`. - Modify multiple files to enhance bot management, routing, and strategy handling. - Update JavaScript and HTML templates for better UI and functionality.
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
# core/utils/ai.py - VERSI PERBAIKAN
|
|
|
|
import ollama
|
|
import logging
|
|
# Hapus impor ini dari bagian atas file untuk memutus lingkaran
|
|
# from core.bots.controller import get_bot_analysis_data, get_bot_instance_by_id
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Fungsi lain di file ini... (jika ada)
|
|
|
|
def get_ai_analysis(bot_id, market_data):
|
|
"""
|
|
Menganalisis data pasar menggunakan model AI dari Ollama dan memberikan keputusan.
|
|
"""
|
|
# Lakukan impor di dalam fungsi (impor lokal)
|
|
from core.bots.controller import get_bot_instance_by_id
|
|
|
|
try:
|
|
bot = get_bot_instance_by_id(bot_id)
|
|
if not bot:
|
|
return {
|
|
"ai_decision": "ERROR",
|
|
"ai_explanation": "Bot instance not found in controller.",
|
|
"ai_suggested_strategy": "N/A"
|
|
}
|
|
|
|
# ... (sisa kode fungsi Anda tetap sama) ...
|
|
|
|
# Contoh sisa kode:
|
|
prompt = f"Analyze the following market data for {bot.market} and decide whether to BUY, SELL, or HOLD..."
|
|
|
|
response = ollama.chat(
|
|
model='llama3',
|
|
messages=[{'role': 'user', 'content': prompt}]
|
|
)
|
|
|
|
# Logika untuk mem-parsing response AI
|
|
decision = "HOLD" # Default
|
|
explanation = response['message']['content']
|
|
|
|
if "BUY" in explanation.upper():
|
|
decision = "BUY"
|
|
elif "SELL" in explanation.upper():
|
|
decision = "SELL"
|
|
|
|
return {
|
|
"ai_decision": decision,
|
|
"ai_explanation": explanation,
|
|
"ai_suggested_strategy": "Based on analysis"
|
|
}
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error during AI analysis for bot {bot_id}: {e}", exc_info=True)
|
|
return {
|
|
"ai_decision": "ERROR",
|
|
"ai_explanation": str(e),
|
|
"ai_suggested_strategy": "N/A"
|
|
} |