From c268cbdd1cd511f331e9eee7e844f7637e5eaf08 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Mon, 1 Sep 2025 16:00:08 -0400 Subject: [PATCH] genarative cores --- .env | 1 + .env.live | 1 + .env.qa | 1 + app/api/integrations/__init__.py | 3 +- app/api/integrations/generative_engine.py | 47 +++++++++++++++++++++++ app/api/routes/routes.py | 12 +++++- app/api/services/__init__.py | 1 + app/api/services/genaratives.py | 30 +++++++++++++++ app/config.py | 2 + requirements.txt | 4 +- 10 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 app/api/integrations/generative_engine.py create mode 100644 app/api/services/genaratives.py diff --git a/.env b/.env index c9a6944..e137775 100644 --- a/.env +++ b/.env @@ -34,6 +34,7 @@ MAIL_PORT= 465 MAIL_USERNAME=message@chiefsoft.com MAIL_PASSWORD=may12002! JWT_SECRET_KEY=dce6bd64f7d7101de4fed7cfc185a12851611a79bd60bbfdcc5b414b85f1fdb75e0905691c2a77ce94a7351b261fab4e183e17731ed40089f68f7290a793119f285d8ec7902d248ce15e8b1d4996ebacf5e7bcb06a38ac7ce0736f17d5c2895a499661d27095ac20aa174f9af2fba9a849dd2e6fd0aad8aa7e1ecc030c11eb8dc8dcb71d32233de3530d04f85918b9582f8b02587a7350aa34232825d4831707c7c5775026f3fdd92c5df555e6ff8b785525922709830206bbd49c371fb6e16bcab01ffccaf904108bb9789c578bce6afbb33bc77960051e680b2428d1f026473e71ef0f9997b2a6dc496e1c40509a1d289e3ff8b384c2d49e1d7719f9f4aaa1 +OPENAI_API_KEY = "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" #Publishable key diff --git a/.env.live b/.env.live index 8085d5d..6568191 100644 --- a/.env.live +++ b/.env.live @@ -34,6 +34,7 @@ MAIL_PORT= 465 MAIL_USERNAME=message@chiefsoft.com MAIL_PASSWORD=may12002! JWT_SECRET_KEY=dce6bd64f7d7101de4fed7cfc185a12851611a79bd60bbfdcc5b414b85f1fdb75e0905691c2a77ce94a7351b261fab4e183e17731ed40089f68f7290a793119f285d8ec7902d248ce15e8b1d4996ebacf5e7bcb06a38ac7ce0736f17d5c2895a499661d27095ac20aa174f9af2fba9a849dd2e6fd0aad8aa7e1ecc030c11eb8dc8dcb71d32233de3530d04f85918b9582f8b02587a7350aa34232825d4831707c7c5775026f3fdd92c5df555e6ff8b785525922709830206bbd49c371fb6e16bcab01ffccaf904108bb9789c578bce6afbb33bc77960051e680b2428d1f026473e71ef0f9997b2a6dc496e1c40509a1d289e3ff8b384c2d49e1d7719f9f4aaa1 +OPENAI_API_KEY = "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" #Publishable key STRIPE_PUB_KEY="pk_live_51RqL5OQ8vepTmh4AbXAnFmbgWDNJys2sfDcsLPVnOKRFx8EVOBOlO2RRN4lRNh6wNPhAj1A28xL3R0wHlMJ4WECo00rOM5iOto" diff --git a/.env.qa b/.env.qa index 216e4f0..f6f3a4f 100644 --- a/.env.qa +++ b/.env.qa @@ -45,6 +45,7 @@ MAIL_PORT= 465 MAIL_USERNAME=message@chiefsoft.com MAIL_PASSWORD=may12002! JWT_SECRET_KEY=dce6bd64f7d7101de4fed7cfc185a12851611a79bd60bbfdcc5b414b85f1fdb75e0905691c2a77ce94a7351b261fab4e183e17731ed40089f68f7290a793119f285d8ec7902d248ce15e8b1d4996ebacf5e7bcb06a38ac7ce0736f17d5c2895a499661d27095ac20aa174f9af2fba9a849dd2e6fd0aad8aa7e1ecc030c11eb8dc8dcb71d32233de3530d04f85918b9582f8b02587a7350aa34232825d4831707c7c5775026f3fdd92c5df555e6ff8b785525922709830206bbd49c371fb6e16bcab01ffccaf904108bb9789c578bce6afbb33bc77960051e680b2428d1f026473e71ef0f9997b2a6dc496e1c40509a1d289e3ff8b384c2d49e1d7719f9f4aaa1 +OPENAI_API_KEY = "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" #Publishable key STRIPE_PUB_KEY="pk_test_51RqL5WLjZLojw6IZmEpwFidNZSl9lLlVUHNvuFZNEz1eTR9XXepnyyVhfvXe9cp4eMnqkDPpoe9wxLLRSV0dxRee00UfhayUOT" diff --git a/app/api/integrations/__init__.py b/app/api/integrations/__init__.py index d04e269..a5c465f 100644 --- a/app/api/integrations/__init__.py +++ b/app/api/integrations/__init__.py @@ -1,2 +1,3 @@ from .kafka import KafkaIntegration -from .merms_stripe import StripeIntegration \ No newline at end of file +from .merms_stripe import StripeIntegration +from .generative_engine import GenerativeEngineIntegration \ No newline at end of file diff --git a/app/api/integrations/generative_engine.py b/app/api/integrations/generative_engine.py new file mode 100644 index 0000000..1d63c2b --- /dev/null +++ b/app/api/integrations/generative_engine.py @@ -0,0 +1,47 @@ +import stripe +import json +import logging +from app.config import settings, Config +# import openai +from flask import jsonify +from openai import OpenAI + +logger = logging.getLogger(__name__) + + +class GenerativeEngineIntegration: + OPENAI_API_KEY = Config.OPENAI_API_KEY + + @staticmethod + def ask_generative(generative_prompt): + try: + # response = GenerativeEngine.openai.chat.completions.create( + # model="gpt-3.5-turbo", # Or other suitable model + # messages=[{"role": "user", "content": generative_prompt}] + # ) + + client = OpenAI(api_key=GenerativeEngineIntegration.OPENAI_API_KEY) + + + response = client.responses.create( + model="gpt-4.1", + input=generative_prompt + ) + + # input = "Tell me a three sentence bedtime story about a unicorn." + logger.info(response) + json_response = json.loads(response.json()) + # json_response = response.json() + # logger.info(json_response.keys()) + logger.info(json_response) + # logger.info(json_response["output"]) + logger.info(json_response["output"]) + logger.info(json_response["output"][0]) + logger.info(json_response["output"][0]["content"][0]["text"]) + # return json_response["generated_text"] + + # chatgpt_response = response.choices[0].message.content + return json_response + except Exception as e: + logger.error(f"ChatGpt Call Error {e}") + return None diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 3afa4d9..ebbda0b 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -12,7 +12,8 @@ from app.api.services import ( WebContentsService, SubscriptionsService, CommonDataService, - OfficeCustomerService + OfficeCustomerService, + GenerativesService ) from app.utils.logger import logger from app.api.middlewares import enforce_json, require_auth @@ -376,6 +377,15 @@ def get_web_contents(): result = WebContentsService.get_web_contents_data(provision_uid) return jsonify(result) +#===================================================== +@api.route('/web/generatives', methods=['GET']) +def get_refresh_generatives(): + logger.info("START TO ENTER GENERATIVE") + # Call the dashboard service + data = [] + result = GenerativesService.process_generatives_list(data) + return jsonify(result) + #=================================================== # Common Data #===================================================== diff --git a/app/api/services/__init__.py b/app/api/services/__init__.py index 0af21d6..d2cd066 100644 --- a/app/api/services/__init__.py +++ b/app/api/services/__init__.py @@ -9,6 +9,7 @@ from app.api.services.office_auth import OfficeAuthService from app.api.services.web_contents import WebContentsService from app.api.services.subscriptions import SubscriptionsService from app.api.services.common_data import CommonDataService +from app.api.services.genaratives import GenerativesService # OFFICE diff --git a/app/api/services/genaratives.py b/app/api/services/genaratives.py new file mode 100644 index 0000000..7e45c4c --- /dev/null +++ b/app/api/services/genaratives.py @@ -0,0 +1,30 @@ +from urllib import request + +from flask import session, jsonify +from app.api.integrations import GenerativeEngineIntegration +from app.utils.logger import logger +from app.api.services.base_service import BaseService +from marshmallow import ValidationError +from app.extensions import db +from app.models import MembersProducts, Products, Members, ProductsDetails, ProductsDetails, ProvisionActions, \ + MembersProductsSettings, ProductsTemplates +from app.api.helpers.response_helper import ResponseHelper +from app.api.schemas.myproduct import MyProductSchema +from app.api.schemas.provision import ProvisionSchema +from app.api.schemas.myproduct_settings import MyProductSettingsSchema +from threading import Thread + +import datetime +import random +from app.config import Config + + +class GenerativesService(BaseService): + + @staticmethod + def process_generatives_list(data): + logger.info("ENTER GENERATIVE") + + res = [] + # res = GenerativeEngineIntegration.ask_generative("write 3 pharagraphs on a dentist website ") + logger.info(res) diff --git a/app/config.py b/app/config.py index 5f12c1b..808e3c3 100644 --- a/app/config.py +++ b/app/config.py @@ -14,6 +14,8 @@ class Config: THIS_SITE_URL = os.getenv("THIS_SITE_URL", "https://qa-panel.mermsemr.com") + OPENAI_API_KEY = os.getenv("OPENAI_API_KEY","qOLBHLMpSTfFrG9TEwA") + #Email Server SEND_EMAIL_FROM = os.environ.get("SEND_EMAIL_FROM","message@chiefsoft.com") SEND_EMAIL_PASS = os.environ.get("SEND_EMAIL_PASS","may12002!") diff --git a/requirements.txt b/requirements.txt index 8690c0f..a2c044e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -45,4 +45,6 @@ pycountry stripe -requests \ No newline at end of file +requests + +openai \ No newline at end of file