Luigi D'Addona commited on
Commit
15b7f56
·
1 Parent(s): 261d8a9

impostazione temperature e parametri wikipedia tramite variabili d'ambiente

Browse files
Files changed (2) hide show
  1. agent.py +3 -1
  2. tools.py +10 -1
agent.py CHANGED
@@ -20,6 +20,7 @@ load_dotenv()
20
  GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
21
  GEMINI_MODEL = os.environ.get("GEMINI_MODEL")
22
  GEMINI_BASE_URL = os.environ.get("GEMINI_BASE_URL")
 
23
 
24
  #
25
  # Inizializza il modello e gli associa i tool
@@ -29,7 +30,8 @@ GEMINI_BASE_URL = os.environ.get("GEMINI_BASE_URL")
29
  # https://python.langchain.com/docs/integrations/chat/google_generative_ai/
30
  chat = ChatGoogleGenerativeAI(
31
  model=GEMINI_MODEL,
32
- google_api_key=GEMINI_API_KEY)
 
33
 
34
  # Imposta i tool
35
  search_tool = get_search_tool()
 
20
  GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
21
  GEMINI_MODEL = os.environ.get("GEMINI_MODEL")
22
  GEMINI_BASE_URL = os.environ.get("GEMINI_BASE_URL")
23
+ GEMINI_TEMPERATURE = float(os.environ.get("GEMINI_TEMPERATURE"))
24
 
25
  #
26
  # Inizializza il modello e gli associa i tool
 
30
  # https://python.langchain.com/docs/integrations/chat/google_generative_ai/
31
  chat = ChatGoogleGenerativeAI(
32
  model=GEMINI_MODEL,
33
+ google_api_key=GEMINI_API_KEY,
34
+ temperature = GEMINI_TEMPERATURE)
35
 
36
  # Imposta i tool
37
  search_tool = get_search_tool()
tools.py CHANGED
@@ -1,4 +1,5 @@
1
  import os, sys
 
2
 
3
  # DuckDuckGo
4
  from langchain_community.tools import DuckDuckGoSearchRun
@@ -12,6 +13,12 @@ from langchain.tools import Tool
12
  # per gestire esecuzione di codice python
13
  import subprocess
14
 
 
 
 
 
 
 
15
  def get_search_tool():
16
 
17
  search_tool = DuckDuckGoSearchRun()
@@ -21,8 +28,10 @@ def get_search_tool():
21
 
22
  def get_wikipedia_tool():
23
 
 
 
24
  # creates an instance of the Wikipedia API wrapper. top_k_results=1 means it will only fetch the top result from Wikipedia
25
- wikipedia_api_wrapper = WikipediaAPIWrapper(top_k_results=3)
26
 
27
  # converts the WikipediaAPIWrapper into a LangChain tool.
28
  wikipedia_tool = WikipediaQueryRun(api_wrapper=wikipedia_api_wrapper)
 
1
  import os, sys
2
+ from dotenv import load_dotenv
3
 
4
  # DuckDuckGo
5
  from langchain_community.tools import DuckDuckGoSearchRun
 
13
  # per gestire esecuzione di codice python
14
  import subprocess
15
 
16
+
17
+ load_dotenv()
18
+ WIKIPEDIA_TOP_K_RESULTS = int(os.environ.get("WIKIPEDIA_TOP_K_RESULTS"))
19
+ WIKIPEDIA_DOC_CONTENT_CHARS_MAX = int(os.environ.get("WIKIPEDIA_DOC_CONTENT_CHARS_MAX"))
20
+
21
+
22
  def get_search_tool():
23
 
24
  search_tool = DuckDuckGoSearchRun()
 
28
 
29
  def get_wikipedia_tool():
30
 
31
+ #print("WIKIPEDIA_TOP_K_RESULTS:{}, WIKIPEDIA_DOC_CONTENT_CHARS_MAX:{}".format(WIKIPEDIA_TOP_K_RESULTS, WIKIPEDIA_DOC_CONTENT_CHARS_MAX))
32
+
33
  # creates an instance of the Wikipedia API wrapper. top_k_results=1 means it will only fetch the top result from Wikipedia
34
+ wikipedia_api_wrapper = WikipediaAPIWrapper(top_k_results=WIKIPEDIA_TOP_K_RESULTS, doc_content_chars_max=WIKIPEDIA_DOC_CONTENT_CHARS_MAX)
35
 
36
  # converts the WikipediaAPIWrapper into a LangChain tool.
37
  wikipedia_tool = WikipediaQueryRun(api_wrapper=wikipedia_api_wrapper)