-
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.
Merge pull request #2 from WilliamJlvt/dev
add flask example and patch date for botgenuity
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
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
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) |
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