增加大模型
This commit is contained in:
@@ -96,6 +96,17 @@ def init_db() -> None:
|
||||
mark_price REAL NOT NULL DEFAULT 0,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS llm_interpretations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
symbol TEXT NOT NULL,
|
||||
batch_id TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_llm_symbol_batch
|
||||
ON llm_interpretations(symbol, batch_id);
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -353,6 +364,87 @@ def save_funding_current_bulk(data: dict[str, dict[str, Any]]) -> None:
|
||||
)
|
||||
|
||||
|
||||
def save_llm_interpretation(symbol: str, batch_id: str, content: str) -> None:
|
||||
with get_conn() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO llm_interpretations (symbol, batch_id, content, created_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""",
|
||||
(symbol.upper(), batch_id, content, datetime.now().isoformat()),
|
||||
)
|
||||
|
||||
|
||||
def get_llm_interpretations(batch_id: str | None = None, limit: int = 50) -> list[dict[str, Any]]:
|
||||
with get_conn() as conn:
|
||||
if batch_id:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT symbol, batch_id, content, created_at
|
||||
FROM llm_interpretations
|
||||
WHERE batch_id = ?
|
||||
ORDER BY id DESC
|
||||
LIMIT ?
|
||||
""",
|
||||
(batch_id, limit),
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT symbol, batch_id, content, created_at
|
||||
FROM llm_interpretations
|
||||
WHERE batch_id = (
|
||||
SELECT batch_id FROM llm_interpretations ORDER BY id DESC LIMIT 1
|
||||
)
|
||||
ORDER BY id ASC
|
||||
LIMIT ?
|
||||
""",
|
||||
(limit,),
|
||||
).fetchall()
|
||||
return [
|
||||
{
|
||||
"symbol": r["symbol"],
|
||||
"batch_id": r["batch_id"],
|
||||
"content": r["content"],
|
||||
"created_at": r["created_at"],
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
|
||||
|
||||
def get_llm_interpretation(symbol: str, batch_id: str | None = None) -> dict[str, Any] | None:
|
||||
sym = symbol.upper()
|
||||
with get_conn() as conn:
|
||||
if batch_id:
|
||||
row = conn.execute(
|
||||
"""
|
||||
SELECT symbol, batch_id, content, created_at
|
||||
FROM llm_interpretations
|
||||
WHERE symbol = ? AND batch_id = ?
|
||||
ORDER BY id DESC LIMIT 1
|
||||
""",
|
||||
(sym, batch_id),
|
||||
).fetchone()
|
||||
else:
|
||||
row = conn.execute(
|
||||
"""
|
||||
SELECT symbol, batch_id, content, created_at
|
||||
FROM llm_interpretations
|
||||
WHERE symbol = ?
|
||||
ORDER BY id DESC LIMIT 1
|
||||
""",
|
||||
(sym,),
|
||||
).fetchone()
|
||||
if not row:
|
||||
return None
|
||||
return {
|
||||
"symbol": row["symbol"],
|
||||
"batch_id": row["batch_id"],
|
||||
"content": row["content"],
|
||||
"created_at": row["created_at"],
|
||||
}
|
||||
|
||||
|
||||
def was_pushed_today(period_start: str, period_end: str) -> bool:
|
||||
with get_conn() as conn:
|
||||
row = conn.execute(
|
||||
|
||||
Reference in New Issue
Block a user