bulltrackers-module 1.0.75 → 1.0.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,21 +21,30 @@ async function getSentimentFromGemini(dependencies, snippet) {
|
|
|
21
21
|
return 'Neutral';
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const prompt = `You are a financial sentiment analyzer
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const prompt = `You are a financial sentiment analyzer specializing in social media posts about trading.
|
|
25
|
+
Your task is to determine the sentiment of the author toward the mentioned asset(s).
|
|
26
|
+
|
|
27
|
+
Possible labels:
|
|
28
|
+
- Bullish: Positive outlook, confidence, or optimism about the asset.
|
|
29
|
+
- Bearish: Negative outlook, loss, or pessimism about the asset.
|
|
30
|
+
- Neutral: Informational or balanced, with no clear positive or negative tone.
|
|
31
|
+
|
|
32
|
+
Important: If the author reports selling at a loss, expresses regret, or uses negative emojis or language about the asset, classify as Bearish.
|
|
33
|
+
|
|
34
|
+
Return only one word: Bullish, Bearish, or Neutral.
|
|
35
|
+
|
|
36
|
+
Post: "${snippet}"`
|
|
27
37
|
|
|
28
|
-
Post: "${snippet}"`;
|
|
29
38
|
|
|
30
39
|
try {
|
|
31
|
-
// --- START FIX ---
|
|
32
|
-
// The
|
|
33
|
-
//
|
|
34
|
-
// 2. `generationConfig` must be a nested object.
|
|
40
|
+
// --- START FIX: Corrected Request Payload ---
|
|
41
|
+
// The payload must include `role: 'user'` and a `parts` array.
|
|
42
|
+
// Generation settings are nested under `generationConfig`.
|
|
35
43
|
const request = {
|
|
36
44
|
contents: [
|
|
37
|
-
{
|
|
38
|
-
|
|
45
|
+
{
|
|
46
|
+
role: "user",
|
|
47
|
+
parts: [ { text: prompt } ]
|
|
39
48
|
}
|
|
40
49
|
],
|
|
41
50
|
generationConfig: {
|
|
@@ -49,16 +58,18 @@ Post: "${snippet}"`;
|
|
|
49
58
|
const result = await geminiModel.generateContent(request);
|
|
50
59
|
const response = result.response;
|
|
51
60
|
|
|
52
|
-
// --- START FIX ---
|
|
53
|
-
//
|
|
61
|
+
// --- START FIX: Corrected Response Parsing ---
|
|
62
|
+
// The text is located at `content.parts[0].text`,
|
|
63
|
+
// not `content[0].text` as in the original file.
|
|
54
64
|
const text = response?.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || '';
|
|
55
65
|
// --- END FIX ---
|
|
56
66
|
|
|
57
67
|
// Robust parsing: Find the keyword, case-insensitive.
|
|
58
|
-
const match = text.match(
|
|
68
|
+
const match = text.match(/\b(Bullish|Bearish|Neutral)\b/i);
|
|
59
69
|
if (match && match[0]) {
|
|
60
70
|
// Capitalize first letter, e.g., "bullish" -> "Bullish"
|
|
61
71
|
const sentiment = match[0].charAt(0).toUpperCase() + match[0].slice(1).toLowerCase();
|
|
72
|
+
logger.log('TRACE', `[getSentimentFromGemini] Raw Gemini response: ${JSON.stringify(response)}`);
|
|
62
73
|
logger.log('INFO', `[getSentimentFromGemini] Classified sentiment: ${sentiment}`);
|
|
63
74
|
return sentiment;
|
|
64
75
|
}
|