ffreemt commited on
Commit
76cbc50
·
1 Parent(s): 0a72279

Update app.py from m-ric's repo, using litellm.dattw

Browse files
Files changed (4) hide show
  1. app.py +29 -11
  2. requirements.txt +2 -1
  3. scripts/text_web_browser.py +2 -2
  4. set-env.bat +6 -6
app.py CHANGED
@@ -5,13 +5,15 @@ import re
5
  import shutil
6
  import threading
7
  from typing import Optional
 
8
 
9
  import gradio as gr
10
  from dotenv import load_dotenv
11
- from huggingface_hub import login
12
  from smolagents import (
13
  CodeAgent,
14
  HfApiModel,
 
15
  Tool,
16
  GoogleSearchTool
17
  )
@@ -36,9 +38,10 @@ from scripts.text_web_browser import (
36
  from scripts.visual_qa import visualizer
37
 
38
 
39
- web_search = GoogleSearchTool(provider="serper")
40
 
41
- print(web_search(query="Donald Trump news"))
 
42
 
43
  # quit()
44
  AUTHORIZED_IMPORTS = [
@@ -66,7 +69,7 @@ AUTHORIZED_IMPORTS = [
66
  "csv",
67
  ]
68
  load_dotenv(override=True)
69
- login(os.getenv("HF_TOKEN"))
70
 
71
  append_answer_lock = threading.Lock()
72
 
@@ -86,9 +89,24 @@ BROWSER_CONFIG = {
86
 
87
  os.makedirs(f"./{BROWSER_CONFIG['downloads_folder']}", exist_ok=True)
88
 
89
- model = HfApiModel(
90
- custom_role_conversions=custom_role_conversions,
91
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  text_limit = 20000
94
  ti_tool = TextInspectorTool(model, text_limit)
@@ -96,7 +114,7 @@ ti_tool = TextInspectorTool(model, text_limit)
96
  browser = SimpleTextBrowser(**BROWSER_CONFIG)
97
 
98
  WEB_TOOLS = [
99
- web_search,
100
  VisitTool(browser),
101
  PageUpTool(browser),
102
  PageDownTool(browser),
@@ -268,11 +286,11 @@ class GradioUI:
268
  with gr.Sidebar():
269
  gr.Markdown("""# open Deep Research - free the AI agents!
270
 
271
- OpenAI just published [Deep Research](https://openai.com/index/introducing-deep-research/), an amazing assistant that can perform deep searches on the web to answer user questions.
272
 
273
- However, their agent has a huge downside: it's not open. So we've started a 24-hour rush to replicate and open-source it. Our resulting [open-Deep-Research agent](https://github.com/huggingface/smolagents/tree/main/examples/open_deep_research) took the #1 rank of any open submission on the GAIA leaderboard! ✨
274
 
275
- You can try a simplified version here that uses `Qwen-Coder-32B` instead of `o1`.<br><br>""")
276
  with gr.Group():
277
  gr.Markdown("**Your request**", container=True)
278
  text_input = gr.Textbox(
 
5
  import shutil
6
  import threading
7
  from typing import Optional
8
+ from loguru import logger
9
 
10
  import gradio as gr
11
  from dotenv import load_dotenv
12
+ # from huggingface_hub import login
13
  from smolagents import (
14
  CodeAgent,
15
  HfApiModel,
16
+ LiteLLMModel,
17
  Tool,
18
  GoogleSearchTool
19
  )
 
38
  from scripts.visual_qa import visualizer
39
 
40
 
41
+ # web_search = GoogleSearchTool(provider="serper")
42
 
43
+ # print(web_search(query="Donald Trump news"))
44
+ # TODO fix ValueError: {'message': 'Unauthorized.', 'statusCode': 403}
45
 
46
  # quit()
47
  AUTHORIZED_IMPORTS = [
 
69
  "csv",
70
  ]
71
  load_dotenv(override=True)
72
+ # login(os.getenv("HF_TOKEN")) # this is not necessary if env var HF_TOKEN is set
73
 
74
  append_answer_lock = threading.Lock()
75
 
 
89
 
90
  os.makedirs(f"./{BROWSER_CONFIG['downloads_folder']}", exist_ok=True)
91
 
92
+ model_id = os.getenv("MODEL_ID", "deepseek-ai/DeepSeek-V3")
93
+ _ = "" if os.getenv("OPENAI_API_KEY") is None else os.getenv("OPENAI_API_KEY")[:8] + "..."
94
+
95
+ if os.getenv("MODEL_ID") and os.getenv("OPENAI_API_BASE"):
96
+ logger.debug(f"""using LiteLLMModel: {model_id=}, {os.getenv("OPENAI_API_BASE")=}, os.getenv("OPENAI_API_BASE")={_}""")
97
+ model = LiteLLMModel(
98
+ # "gpt-4o",
99
+ # os.getenv("MODEL_ID", "gpt-4o-mini"),
100
+ model_id,
101
+ custom_role_conversions=custom_role_conversions,
102
+ api_base=os.getenv("OPENAI_API_BASE"),
103
+ api_key=os.getenv("OPENAI_API_KEY"),
104
+ )
105
+ else:
106
+ logger.debug(f"""using LiteLLMModel: HfApiModel default model_id=Qwen/Qwen2.5-Coder-32B-Instruct""")
107
+ model = HfApiModel(
108
+ custom_role_conversions=custom_role_conversions,
109
+ )
110
 
111
  text_limit = 20000
112
  ti_tool = TextInspectorTool(model, text_limit)
 
114
  browser = SimpleTextBrowser(**BROWSER_CONFIG)
115
 
116
  WEB_TOOLS = [
117
+ # web_search, # TODO
118
  VisitTool(browser),
119
  PageUpTool(browser),
120
  PageDownTool(browser),
 
286
  with gr.Sidebar():
287
  gr.Markdown("""# open Deep Research - free the AI agents!
288
 
289
+ OpenAI just (February 2, 2025) published [Deep Research](https://openai.com/index/introducing-deep-research/), an amazing assistant that can perform deep searches on the web to answer user questions.
290
 
291
+ However, their agent has a huge downside: it's not open. So we've started a 24-hour rush to replicate and open-source it. Our (Huggingface's) resulting [open-Deep-Research agent](https://github.com/huggingface/smolagents/tree/main/examples/open_deep_research) took the #1 rank of any open submission on the GAIA leaderboard! ✨
292
 
293
+ You can try a simplified version here that uses `Qwen-Coder-32B` (via smolagnet.HfApiModel) instead of `o1`. Modified: if you set MODEL_ID, OPENAI_API_BASE and OPENAI_API_KEY in the .env or env vars (in hf space these can be set in settings, .env will override env vars), the correspoding model will be used. N.B. if you see errors, it might be because whatever quota is exceeded, clone this space and plug in your own resources and run your own deep-research.<br><br>""")
294
  with gr.Group():
295
  gr.Markdown("**Your request**", container=True)
296
  text_input = gr.Textbox(
requirements.txt CHANGED
@@ -47,4 +47,5 @@ litellm
47
  google-api-python-client
48
  google-auth-httplib2
49
  google-auth-oauthlib
50
- gradio
 
 
47
  google-api-python-client
48
  google-auth-httplib2
49
  google-auth-oauthlib
50
+ gradio
51
+ loguru
scripts/text_web_browser.py CHANGED
@@ -11,8 +11,8 @@ from urllib.parse import unquote, urljoin, urlparse
11
 
12
  import pathvalidate
13
  import requests
14
- # from serpapi import GoogleSearch
15
- from serpapi.google_search import GoogleSearch
16
 
17
  from smolagents import Tool
18
 
 
11
 
12
  import pathvalidate
13
  import requests
14
+ from serpapi import GoogleSearch
15
+ # from serpapi.google_search import GoogleSearch
16
 
17
  from smolagents import Tool
18
 
set-env.bat CHANGED
@@ -1,11 +1,11 @@
1
- set OPENAI_BASE_URL=h=tps://api.siliconflow.cn/v1
2
- set OPENAI_API_BASE=https://api.siliconflow.cn/v1
3
- set OPENAI_API_KEY=%SILICONFLOW_API_KEY%
4
- set MODEL_ID=deepseek-ai/DeepSeek-V3
5
 
6
- set OPENAI_BASE_URL=https://litellm.dattw.eu.org/v1
7
  set OPENAI_API_BASE=https://litellm.dattw.eu.org/v1
8
  set OPENAI_API_KEY=%LITELLM_API_KEY%
9
  set MODEL_ID=gpt-4o-mini
10
 
11
- REM set SERPAPI_API_KEY b84...
 
 
1
+ REM siliconflow rate limited, wont work for deep-research
2
+ REM set OPENAI_API_BASE=https://api.siliconflow.cn/v1
3
+ REM set OPENAI_API_KEY=%SILICONFLOW_API_KEY%
4
+ REM set MODEL_ID=openai/deepseek-ai/DeepSeek-V3
5
 
 
6
  set OPENAI_API_BASE=https://litellm.dattw.eu.org/v1
7
  set OPENAI_API_KEY=%LITELLM_API_KEY%
8
  set MODEL_ID=gpt-4o-mini
9
 
10
+ REM set SERPAPI_API_KEY=b84...
11
+ REM set HF_TOKEN=hf_yC...