File size: 2,585 Bytes
20d720d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Mistral LLM Tools for CrewAI
"""

from crewai.tools import BaseTool
from models.mistral_model import MistralModel
from typing import Dict, List

class MistralChatTool(BaseTool):
    name: str = "mistral_chat"
    description: str = "Chat with Mistral AI for intelligent responses"
    
    def __init__(self):
        super().__init__()
        self.model = MistralModel()
    
    def _run(self, prompt: str, context: dict = None) -> str:
        """Generate response using Mistral"""
        if context:
            full_prompt = f"""
            Context: {context}
            
            User Query: {prompt}
            
            Provide a thoughtful, compassionate response.
            """
        else:
            full_prompt = prompt
        
        return self.model.generate(full_prompt)

class GenerateAdviceTool(BaseTool):
    name: str = "generate_personalized_advice"
    description: str = "Generate personalized advice based on user's situation"
    
    def __init__(self):
        super().__init__()
        self.model = MistralModel()
    
    def _run(self, user_analysis: dict, wisdom_quotes: list) -> str:
        """Generate personalized advice"""
        prompt = f"""
        Based on this user analysis:
        - Emotional state: {user_analysis.get('primary_emotion')}
        - Concerns: {user_analysis.get('concerns')}
        - Needs: {user_analysis.get('needs')}
        
        And these relevant wisdom quotes:
        {wisdom_quotes}
        
        Generate compassionate, personalized advice that:
        1. Acknowledges their feelings
        2. Offers practical guidance
        3. Includes relevant wisdom
        4. Suggests actionable steps
        5. Maintains hope and encouragement
        
        Be specific to their situation, not generic.
        """
        
        return self.model.generate(prompt, max_length=500)

class SummarizeTool(BaseTool):
    name: str = "summarize_conversation"
    description: str = "Summarize conversation maintaining key insights"
    
    def __init__(self):
        super().__init__()
        self.model = MistralModel()
    
    def _run(self, conversation: list) -> str:
        """Summarize conversation history"""
        prompt = f"""
        Summarize this coaching conversation:
        {conversation}
        
        Include:
        1. Main concerns discussed
        2. Key insights shared
        3. Progress made
        4. Next steps suggested
        
        Keep it concise but meaningful.
        """
        
        return self.model.generate(prompt, max_length=200)