Commit
·
49687ab
1
Parent(s):
c61547d
add openai req
Browse files- app.py +24 -3
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -21,6 +21,27 @@ import yaml
|
|
| 21 |
import os
|
| 22 |
from dotenv import load_dotenv
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# with open("prompts.yaml", 'r') as stream:
|
| 25 |
# prompt_templates = yaml.safe_load(stream)
|
| 26 |
# 1) load your .env (skip if you set it in the shell)
|
|
@@ -39,10 +60,10 @@ model = OpenAIServerModel(
|
|
| 39 |
) # :contentReference[oaicite:1]{index=1}
|
| 40 |
|
| 41 |
# 4) create a CodeAgent powered by that model
|
| 42 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool
|
| 43 |
|
| 44 |
OpenAIAgent = CodeAgent(
|
| 45 |
-
tools=[
|
| 46 |
model=model,
|
| 47 |
max_steps=6,
|
| 48 |
verbosity_level=1,
|
|
@@ -107,7 +128,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 107 |
|
| 108 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 109 |
try:
|
| 110 |
-
agent =
|
| 111 |
except Exception as e:
|
| 112 |
print(f"Error instantiating agent: {e}")
|
| 113 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 21 |
import os
|
| 22 |
from dotenv import load_dotenv
|
| 23 |
|
| 24 |
+
|
| 25 |
+
import wikipediaapi
|
| 26 |
+
|
| 27 |
+
@tool
|
| 28 |
+
def wikipedia_search(query: str) -> str:
|
| 29 |
+
"""
|
| 30 |
+
Searches for a page on Wikipedia and returns a summary of the page.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
query (str): The search query for the Wikipedia page.
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
str: A summary of the Wikipedia page, or an error message if the page is not found.
|
| 37 |
+
"""
|
| 38 |
+
wiki_wiki = wikipediaapi.Wikipedia('MyProjectName (merci@example.com)', 'en')
|
| 39 |
+
page = wiki_wiki.page(query)
|
| 40 |
+
if page.exists():
|
| 41 |
+
return page.summary
|
| 42 |
+
else:
|
| 43 |
+
return "Could not find a Wikipedia page for that query."
|
| 44 |
+
|
| 45 |
# with open("prompts.yaml", 'r') as stream:
|
| 46 |
# prompt_templates = yaml.safe_load(stream)
|
| 47 |
# 1) load your .env (skip if you set it in the shell)
|
|
|
|
| 60 |
) # :contentReference[oaicite:1]{index=1}
|
| 61 |
|
| 62 |
# 4) create a CodeAgent powered by that model
|
| 63 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool
|
| 64 |
|
| 65 |
OpenAIAgent = CodeAgent(
|
| 66 |
+
tools=[ wikipedia_search],
|
| 67 |
model=model,
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
|
|
|
| 128 |
|
| 129 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 130 |
try:
|
| 131 |
+
agent = OpenAIAgent()
|
| 132 |
except Exception as e:
|
| 133 |
print(f"Error instantiating agent: {e}")
|
| 134 |
return f"Error initializing agent: {e}", None
|
requirements.txt
CHANGED
|
@@ -13,4 +13,5 @@ beautifulsoup4
|
|
| 13 |
openai-whisper
|
| 14 |
torch
|
| 15 |
IMDbPY
|
| 16 |
-
pyyaml
|
|
|
|
|
|
| 13 |
openai-whisper
|
| 14 |
torch
|
| 15 |
IMDbPY
|
| 16 |
+
pyyaml
|
| 17 |
+
wikipedia-api
|