mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 05:45:00 +00:00
Add web page
This commit is contained in:
parent
6e5e195ea8
commit
dcb6100ce9
3 changed files with 53 additions and 19 deletions
|
@ -42,7 +42,9 @@ class Commands:
|
||||||
if content:
|
if content:
|
||||||
self.io.tool_output(content)
|
self.io.tool_output(content)
|
||||||
|
|
||||||
self.scraper.show_playwright_instructions()
|
instructions = self.scraper.get_playwright_instructions()
|
||||||
|
if instructions:
|
||||||
|
self.io.tool_error(instructions)
|
||||||
|
|
||||||
content = f"{url}:\n\n" + content
|
content = f"{url}:\n\n" + content
|
||||||
|
|
||||||
|
|
64
aider/gui.py
64
aider/gui.py
|
@ -9,19 +9,7 @@ import streamlit as st
|
||||||
from aider.coders import Coder
|
from aider.coders import Coder
|
||||||
from aider.dump import dump # noqa: F401
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.main import main as cli_main
|
from aider.main import main as cli_main
|
||||||
|
from aider.scrape import Scraper
|
||||||
MESSAGES = [
|
|
||||||
"write a python program that shows off some python features",
|
|
||||||
"write a tsx program that shows off some language features",
|
|
||||||
"refactor the Frobulator.simplify method to be a stand alone function",
|
|
||||||
"lorem ipsum dolor",
|
|
||||||
"lorem adipiscing adipiscing et dolore sit elit aliqua dolore ut incididunt",
|
|
||||||
(
|
|
||||||
"sed magna consectetur et quis do magna labore ad elit et elit ad eiusmod sed"
|
|
||||||
" labore aliqua eiusmod enim ad nostrud\n\namet consectetur magna tempor do enim"
|
|
||||||
" aliqua enim tempor adipiscing sit et"
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def search(text=None):
|
def search(text=None):
|
||||||
|
@ -166,8 +154,8 @@ class GUI:
|
||||||
self.messages.info(f"Removed {fname} from the chat")
|
self.messages.info(f"Removed {fname} from the chat")
|
||||||
|
|
||||||
with st.popover("Add web page"):
|
with st.popover("Add web page"):
|
||||||
st.markdown("www")
|
self.do_web()
|
||||||
st.text_input("URL?")
|
|
||||||
with st.popover("Add image"):
|
with st.popover("Add image"):
|
||||||
st.markdown("Hello World 👋")
|
st.markdown("Hello World 👋")
|
||||||
st.file_uploader("Image file", disabled=self.prompt_pending())
|
st.file_uploader("Image file", disabled=self.prompt_pending())
|
||||||
|
@ -276,7 +264,9 @@ class GUI:
|
||||||
self.state.init("messages", messages)
|
self.state.init("messages", messages)
|
||||||
self.state.init("last_aider_commit_hash", self.coder.last_aider_commit_hash)
|
self.state.init("last_aider_commit_hash", self.coder.last_aider_commit_hash)
|
||||||
self.state.init("recent_msgs_num", 0)
|
self.state.init("recent_msgs_num", 0)
|
||||||
|
self.state.init("web_content_num", 0)
|
||||||
self.state.init("prompt")
|
self.state.init("prompt")
|
||||||
|
self.state.init("scraper")
|
||||||
|
|
||||||
if "input_history" not in self.state.keys:
|
if "input_history" not in self.state.keys:
|
||||||
input_history = list(self.coder.io.get_input_history())
|
input_history = list(self.coder.io.get_input_history())
|
||||||
|
@ -294,7 +284,9 @@ class GUI:
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
self.last_undo_button = None
|
self.last_undo_button = None
|
||||||
|
|
||||||
self.recent_msgs_empty = None
|
self.recent_msgs_empty = None
|
||||||
|
self.web_content_empty = None
|
||||||
|
|
||||||
# Force the coder to cooperate, regardless of cmd line args
|
# Force the coder to cooperate, regardless of cmd line args
|
||||||
self.coder.yield_stream = True
|
self.coder.yield_stream = True
|
||||||
|
@ -313,7 +305,10 @@ class GUI:
|
||||||
if self.prompt_pending():
|
if self.prompt_pending():
|
||||||
self.process_chat()
|
self.process_chat()
|
||||||
|
|
||||||
prompt = prompt if prompt else self.old_prompt
|
for prompt in [prompt, self.old_prompt, self.web_content]:
|
||||||
|
if prompt:
|
||||||
|
break
|
||||||
|
|
||||||
if not prompt:
|
if not prompt:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -377,6 +372,43 @@ class GUI:
|
||||||
self.state.messages.append(info)
|
self.state.messages.append(info)
|
||||||
self.messages.info(message)
|
self.messages.info(message)
|
||||||
|
|
||||||
|
def do_web(self):
|
||||||
|
st.markdown("Add the text content of a web page to the chat")
|
||||||
|
|
||||||
|
if not self.web_content_empty:
|
||||||
|
self.web_content_empty = st.empty()
|
||||||
|
|
||||||
|
if self.prompt_pending():
|
||||||
|
self.web_content_empty.empty()
|
||||||
|
self.state.web_content_num += 1
|
||||||
|
|
||||||
|
with self.web_content_empty:
|
||||||
|
self.web_content = st.text_input(
|
||||||
|
"URL",
|
||||||
|
placeholder="https://...",
|
||||||
|
key=f"web_content_{self.state.web_content_num}",
|
||||||
|
)
|
||||||
|
|
||||||
|
if not self.web_content:
|
||||||
|
return
|
||||||
|
|
||||||
|
url = self.web_content
|
||||||
|
|
||||||
|
if not self.state.scraper:
|
||||||
|
self.scraper = Scraper(print_error=self.info)
|
||||||
|
|
||||||
|
instructions = self.scraper.get_playwright_instructions()
|
||||||
|
if instructions:
|
||||||
|
self.info(instructions)
|
||||||
|
|
||||||
|
content = self.scraper.scrape(url) or ""
|
||||||
|
if content.strip():
|
||||||
|
content = f"{url}:\n\n" + content
|
||||||
|
self.web_content = content
|
||||||
|
else:
|
||||||
|
self.info(f"No web content found for `{url}`.")
|
||||||
|
self.web_content = None
|
||||||
|
|
||||||
|
|
||||||
def gui_main():
|
def gui_main():
|
||||||
coder = get_coder()
|
coder = get_coder()
|
||||||
|
|
|
@ -66,14 +66,14 @@ class Scraper:
|
||||||
except Exception:
|
except Exception:
|
||||||
self.playwright_available = False
|
self.playwright_available = False
|
||||||
|
|
||||||
def show_playwright_instructions(self):
|
def get_playwright_instructions(self):
|
||||||
if self.playwright_available in (True, None):
|
if self.playwright_available in (True, None):
|
||||||
return
|
return
|
||||||
if self.playwright_instructions_shown:
|
if self.playwright_instructions_shown:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.playwright_instructions_shown = True
|
self.playwright_instructions_shown = True
|
||||||
self.print_error(PLAYWRIGHT_INFO)
|
return PLAYWRIGHT_INFO
|
||||||
|
|
||||||
def scrape_with_httpx(self, url):
|
def scrape_with_httpx(self, url):
|
||||||
headers = {"User-Agent": f"Mozilla./5.0 ({aider_user_agent})"}
|
headers = {"User-Agent": f"Mozilla./5.0 ({aider_user_agent})"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue