File size: 1,472 Bytes
88c5b30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e249ad6
88c5b30
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from src.langgraph_agenticai.state.state import State
from langchain_core.prompts import ChatPromptTemplate
from langchain.agents import create_openai_tools_agent, AgentExecutor

class ChatbotAINewsNode:
    
    def __init__(self, model):
        self.llm = model
        
        
    def create_ai_new_chatbot(self, tools):
        
       # AI expert system prompt
        system_prompt = """You are a professional AI news analyst with expertise in:
        - Breaking technology news
        - Emerging AI research trends
        - Industry developments in artificial intelligence
        - Analysis of AI ethics and policy

        Guidelines:
        1. Provide up-to-date, accurate information
        2. Always verify facts using Tavily search
        3. Include relevant sources from search results
        4. Explain technical terms when needed
        5. Maintain neutral, objective tone
        6. Provide a summary of key points and future trends
        
        Provide only information about the AI News and Trends. For other queries, please respond with the reson that you are only the AI News Expert.
        """


        llm_with_tools = self.llm.bind_tools(tools)

        def chatbot_node(state: State):
            """
            Chatbot logic for processing the input state and returning a response.
            """
            return {"messages": [llm_with_tools.invoke([system_prompt] + state["messages"])]}
        
        return chatbot_node