Simple Service Lab Solution
Look here for the simple service lab solution.
# car payment calculation (approximate)
def monthly_payment(cost, rate, years_of_loan):
n = 365.25
total_paid = cost * (((1 + ((rate/100.0)/n)) ** (n*years_of_loan)))
per_month = total_paid / (12 * years_of_loan)
return per_month
monthly_payment(40000, 2, 4)
from typing import Dict
import json
import ray
import requests
from ray import serve
from starlette.requests import Request
@serve.deployment
class Chat:
async def __call__(self, request: Request) -> Dict:
data = await request.json()
data = json.loads(data)
return {"result": self.monthly_payment(data['cost'], data['rate'], data['years_of_loan']) }
def monthly_payment(self, cost, rate, years_of_loan):
n = 365.25
total_paid = cost * (((1 + ((rate/100.0)/n)) ** (n*years_of_loan)))
per_month = total_paid / (12 * years_of_loan)
return per_month
handle = serve.run(Chat.bind(), name='car_payment')
ray.get(handle.monthly_payment.remote(40_000, 7, 6))
sample_json = '{ "cost" : 40000, "rate" : 7, "years_of_loan" : 6 }'
requests.post("http://localhost:8000/", json = sample_json).json()
serve.delete('car_payment')