#How can I get the assistant API to hit webpages?
1 messages · Page 1 of 1 (latest)
Hi @ornate vale. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You're correct that the OpenAI Assistant API does not directly support web browsing or hitting webpages. However, there are a few ways you can work around this limitation.
One approach is to fetch the webpage content yourself, and then pass that content to the Assistant API. For example, you could use a library like requests in Python to fetch the webpage content, and then pass that content as part of the prompt to the Assistant API. Here's an example of how you might do this:
import requests
from openai import OpenAI
client = OpenAI()
def fetch_html(url):
response = requests.get(url)
if response.status_code == 200:
return response.text
else:
return None
url = "<https://en.wikipedia.org/wiki/List_of_largest_companies_in_the_United_States_by_revenue">
html_content = fetch_html(url)
o1_response = client.chat.completions.create(
model="o1-preview",
messages=[
{
"role": "user",
"content": f"You are a business analyst designed to understand how AI technology could be used across large corporations. Read the following html and return which companies would benefit from using AI technology: {html_content}."
}
]
)
(Source: OpenAI Cookbook (https://cookbook.openai.com/examples/o1/using_chained_calls_for_o1_structured_outputs#prompting))
Another approach is to use a third-party tool to perform the web browsing, and then pass the results of that browsing to the Assistant API. For example, you could use the Google Custom Search API to fetch search results, and then pass those results to the Assistant API. You would need a Google Custom Search API key and Custom Search Engine ID (CSE ID) to do this.
(Source: OpenAI Cookbook (https://cookbook.openai.com/examples/third_party/web_search_with_google_api_bring_your_own_browser_tool#setting-up-a-byob-tool))