-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5296c52
commit 6fe7721
Showing
6 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from enum import Enum | ||
|
||
class DataSources(Enum): | ||
DOCSBOT = "docsbot" # Most likely to be used | ||
BOTGENUITY = "botgenuity" | ||
HUGGINGFACE = "huggingface" | ||
HUHUHANG = "huhuhang" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from datetime import datetime | ||
from llm_pricing_sdk.models import LLMModelPricing | ||
|
||
|
||
class DocsBotScraper: | ||
@staticmethod | ||
def scrape(): | ||
url = "https://docsbot.ai/tools/gpt-openai-api-pricing-calculator" | ||
response = requests.get(url) | ||
|
||
if response.status_code != 200: | ||
raise Exception( | ||
f"Failed to fetch data from {url}. Status code: {response.status_code}") | ||
|
||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
table = soup.find("table") | ||
if not table: | ||
raise Exception("No table found on the page.") | ||
|
||
rows = [] | ||
for tr in table.find("tbody").find_all("tr"): | ||
cells = tr.find_all("td") | ||
|
||
if len(cells) >= 7: | ||
provider = cells[0].text.strip() | ||
|
||
model_td = cells[1] | ||
model_name = model_td.text.strip() | ||
model_name_div = model_td.find("div") | ||
if model_name_div: | ||
# Use the <div> inside the <td> to get the accurate model name | ||
model_name = model_name_div.text.strip() | ||
|
||
context = cells[2].text.strip() | ||
input_tokens_price = cells[3].text.strip().replace("$", "") | ||
output_tokens_price = cells[4].text.strip().replace("$", "") | ||
updated = datetime.now().strftime("%Y-%m-%d") | ||
|
||
pricing_info = LLMModelPricing( | ||
model=model_name, | ||
provider=provider, | ||
input_tokens_price=float( | ||
input_tokens_price) if input_tokens_price else 0.0, | ||
output_tokens_price=float( | ||
output_tokens_price) if output_tokens_price else 0.0, | ||
context=context, | ||
source=url, | ||
updated=updated | ||
) | ||
|
||
rows.append(pricing_info) | ||
|
||
return rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters