Skip to content

Commit

Permalink
Merge pull request #2 from WilliamJlvt/dev
Browse files Browse the repository at this point in the history
add flask example and patch date for botgenuity
  • Loading branch information
WilliamJlvt authored Oct 3, 2024
2 parents 397184f + 603597b commit 8673aaa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions examples/flask/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from flask import Flask, jsonify, request
from llm_pricing_sdk.enums import DataSources
from llm_pricing_sdk.scrapers import LlmPricingScraper

app = Flask(__name__)


@app.route('/api/pricing/', methods=['GET'])
def get_pricing():
source = request.args.get('source', default='huggingface', type=str)

try:
if source.lower() == DataSources.BOTGENUITY.value:
results = LlmPricingScraper.scrape(DataSources.BOTGENUITY)
elif source.lower() == DataSources.HUGGINGFACE.value:
results = LlmPricingScraper.scrape(DataSources.HUGGINGFACE)
else:
return jsonify(
{"error": f"Source '{source}' is not supported."}), 400

pricing_data = [
{
"model": result.model,
"provider": result.provider,
"input_tokens_price": result.input_tokens_price,
"output_tokens_price": result.output_tokens_price,
"context": result.context,
"source": result.source,
"updated": result.updated
}
for result in results
]

return jsonify({"pricing_data": pricing_data}), 200

except Exception as e:
return jsonify({"error": str(e)}), 500


if __name__ == '__main__':
app.run(debug=True)
2 changes: 1 addition & 1 deletion llm_pricing_sdk/scrapers/botgenuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def scrape():
context = cells[2].text.strip()
input_tokens_price = cells[3].text.strip().replace("$", "")
output_tokens_price = cells[4].text.strip().replace("$", "")
updated = datetime.strptime(cells[6].text.strip(), "%B %d, %Y").strftime("%B %d, %Y")
updated = datetime.strptime(cells[6].text.strip(), "%B %d, %Y").strftime("%Y-%m-%d")

pricing_info = LLMModelPricing(
provider=provider,
Expand Down

0 comments on commit 8673aaa

Please sign in to comment.