PLBot commited on
Commit
434c919
·
verified ·
1 Parent(s): 382c69f

change to openai API

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -8,12 +8,26 @@ from Gradio_UI import GradioUI
8
  from smolagents.agent_types import AgentImage
9
  import os
10
  from smolagents import LiteLLMModel
 
11
 
12
  # Import tools
13
  from tools.final_answer import FinalAnswerTool
14
  from tools.web_search import DuckDuckGoSearchTool
15
  from agents.tour_guide_agent import TourGuideAgent
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
18
  @tool
19
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
@@ -53,13 +67,18 @@ def get_current_time_in_timezone(timezone: str) -> str:
53
  # custom_role_conversions=None,
54
  # )
55
 
56
- # Use LLM API directly
57
- model = LiteLLMModel(
58
- model="gemini-1.5-pro",
59
- api_key=os.environ.get("GEMINI_API_KEY"),
60
- max_tokens=2096,
61
- temperature=0.5
62
- )
 
 
 
 
 
63
 
64
 
65
  # Import tool from Hub
 
8
  from smolagents.agent_types import AgentImage
9
  import os
10
  from smolagents import LiteLLMModel
11
+ import logging
12
 
13
  # Import tools
14
  from tools.final_answer import FinalAnswerTool
15
  from tools.web_search import DuckDuckGoSearchTool
16
  from agents.tour_guide_agent import TourGuideAgent
17
 
18
+ logging.basicConfig(level=logging.INFO)
19
+ logger = logging.getLogger(__name__)
20
+
21
+ try:
22
+ import litellm
23
+ print("✅ liteLLM is properly installed")
24
+ except ImportError:
25
+ print("❌ liteLLM is not installed. Installing now...")
26
+ import subprocess
27
+ subprocess.check_call(["pip", "install", "litellm"])
28
+ import litellm
29
+ print("✅ liteLLM has been installed")
30
+
31
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
32
  @tool
33
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
67
  # custom_role_conversions=None,
68
  # )
69
 
70
+ try:
71
+ # Try to use OpenAI
72
+ model = LiteLLMModel(
73
+ model="gpt-4o",
74
+ api_key=os.environ.get("OPENAI_API_KEY"),
75
+ max_tokens=2096,
76
+ temperature=0.5
77
+ )
78
+ logger.info("Using OpenAI model")
79
+ except Exception as e:
80
+ logger.warning(f"Failed to initialize OpenAI model: {str(e)}")
81
+
82
 
83
 
84
  # Import tool from Hub