junaid17 commited on
Commit
7a14b73
·
verified ·
1 Parent(s): d0812dd

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +16 -15
tools.py CHANGED
@@ -6,6 +6,7 @@ from langchain_openai import OpenAIEmbeddings
6
  from langchain_community.tools import WikipediaQueryRun, ArxivQueryRun
7
  from langchain_community.utilities import WikipediaAPIWrapper, ArxivAPIWrapper
8
  from langchain_community.tools.tavily_search import TavilySearchResults
 
9
  from dotenv import load_dotenv
10
  import os
11
  import requests
@@ -16,6 +17,7 @@ import requests
16
 
17
  load_dotenv()
18
 
 
19
  API_KEY = os.getenv("ALPHAVANTAGE_API_KEY")
20
  NEWS_API_KEY = os.getenv("NEWS_API_KEY")
21
  WEATHER_API_KEY = os.getenv("WEATHER_API_KEY")
@@ -102,26 +104,25 @@ def create_rag_tool():
102
 
103
  context = "\n\n".join(d.page_content for d in docs)
104
 
105
- return f"""
106
- You are given extracted content from a document.
107
 
108
- Your task:
109
- - Produce ONE concise summary only.
110
- - Use bullet points where appropriate.
111
- - Do NOT repeat information.
112
- - Do NOT restate the same idea in different words.
113
- - Do NOT explain what the document is about.
114
- - Do NOT add conclusions or meta commentary.
115
- - Stop once the summary is complete.
116
 
117
- IMPORTANT:
118
- Return ONLY the final summarized content.
119
- Do NOT add introductions, explanations, or commentary.
120
-
121
- DOCUMENT CONTENT:
122
  {context}
123
  """
124
 
 
 
 
 
 
 
125
 
126
  return rag_search
127
 
 
6
  from langchain_community.tools import WikipediaQueryRun, ArxivQueryRun
7
  from langchain_community.utilities import WikipediaAPIWrapper, ArxivAPIWrapper
8
  from langchain_community.tools.tavily_search import TavilySearchResults
9
+ from langchain_openai import ChatOpenAI
10
  from dotenv import load_dotenv
11
  import os
12
  import requests
 
17
 
18
  load_dotenv()
19
 
20
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
21
  API_KEY = os.getenv("ALPHAVANTAGE_API_KEY")
22
  NEWS_API_KEY = os.getenv("NEWS_API_KEY")
23
  WEATHER_API_KEY = os.getenv("WEATHER_API_KEY")
 
104
 
105
  context = "\n\n".join(d.page_content for d in docs)
106
 
107
+ summary_prompt = f"""
108
+ Summarize the following content clearly and concisely.
109
 
110
+ Rules:
111
+ - Use bullet points when helpful
112
+ - Do NOT repeat ideas
113
+ - Do NOT mention the document
114
+ - Stop after the summary
 
 
 
115
 
116
+ CONTENT:
 
 
 
 
117
  {context}
118
  """
119
 
120
+ llm = ChatOpenAI(model="gpt-4.1-nano", temperature=0.2)
121
+
122
+ summary = llm.invoke(summary_prompt)
123
+
124
+ return summary.content.strip()
125
+
126
 
127
  return rag_search
128