From ecf2bf9fd994ecc6aa02747d1ee26b95bbd2c19c Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 25 Feb 2024 09:46:07 -0800 Subject: [PATCH] [FEAT][swarms_cloud] --- pyproject.toml | 4 ++-- requirements.txt | 3 ++- servers/cogvlm.py | 4 +--- swarms_cloud/calculate_pricing.py | 2 +- swarms_cloud/stripe_utils.py | 29 +++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 swarms_cloud/stripe_utils.py diff --git a/pyproject.toml b/pyproject.toml index 60086d9..e682de1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms-cloud" -version = "0.1.2" +version = "0.1.3" description = "Swarms Cloud - Pytorch" license = "MIT" authors = ["Kye Gomez "] @@ -29,7 +29,7 @@ skypilot = "*" torch = "*" einops = "*" pydantic = "*" - +stripe = "*" [tool.poetry.group.lint.dependencies] ruff = "^0.1.6" diff --git a/requirements.txt b/requirements.txt index a6f2dfc..d135080 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ einops tiktoken uvicorn loguru -pydantic \ No newline at end of file +pydantic +stripe diff --git a/servers/cogvlm.py b/servers/cogvlm.py index 40f5a00..dc33a00 100644 --- a/servers/cogvlm.py +++ b/servers/cogvlm.py @@ -404,9 +404,7 @@ def generate_stream_cogvlm( else: torch_type = torch.float16 - print( - f"========Use torch type as:{torch_type} with device:{DEVICE}========\n\n" - ) + print(f"========Use torch type as:{torch_type} with device:{DEVICE}========\n\n") if "cuda" in DEVICE: if QUANT_ENABLED: diff --git a/swarms_cloud/calculate_pricing.py b/swarms_cloud/calculate_pricing.py index 05404ce..45e3baa 100644 --- a/swarms_cloud/calculate_pricing.py +++ b/swarms_cloud/calculate_pricing.py @@ -13,7 +13,7 @@ def calculate_pricing( rate_img: float = 0.003, ): """ - Calculates the pricing for a given list of texts based on the number of tokens, sentences, words, characters, and paragraphs. + leCalctuple containingg for otal number of texts based on the number of tokens, sentences, words, characters, and paragraphs. Args: texts (list): A list of texts to calculate pricing for. diff --git a/swarms_cloud/stripe_utils.py b/swarms_cloud/stripe_utils.py new file mode 100644 index 0000000..72a6502 --- /dev/null +++ b/swarms_cloud/stripe_utils.py @@ -0,0 +1,29 @@ +import logging + +import stripe +from pydantic import BaseModel + +stripe.api_key = "your_stripe_api_key" + + +class StripeInterface(BaseModel): + customer_id: str + amount: float + description: str + + +def bill_customer(customer_id: str, amount: float, description: str): + try: + stripe.Charge.create( + customer=customer_id, + amount=amount, # in cents + currency="usd", + description=description, + ) + logging.info("Payment successful") + except stripe.error.StripeError as e: + logging.error(f"Payment failed: {str(e)}") + + +# Usage: +# bill_customer("429232323", 1000, "1,000 tokens")