-
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 #28 from SebastianJames55/feature/file_naming_#24
- Loading branch information
Showing
17 changed files
with
120 additions
and
285 deletions.
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 |
---|---|---|
@@ -1,58 +1,24 @@ | ||
import logging | ||
|
||
from flask import Flask, g, Blueprint | ||
from flask import Blueprint | ||
from flask_restx import Api | ||
|
||
import config | ||
import constants | ||
from connectors import MindsDBConnector | ||
from endpoints.predict import predict_ns | ||
from models import MindsDBModel | ||
|
||
app = Flask(__name__) | ||
# Set up logging configuration | ||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
# Create a logger for your module | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# Function to get the connector based on the specified app in config.py | ||
def get_connector(): | ||
# Create a connector based on the specified app in config.py | ||
if config.APP_TO_CONNECT == constants.MINDSDB: | ||
logger.debug('Choosing mindsdb app') | ||
return MindsDBConnector() | ||
else: | ||
raise ValueError(constants.INVALID_APP_MESSAGE) | ||
|
||
from mindsdb.setup import initialize, app | ||
|
||
# Function to get the model based on the specified app in config.py | ||
def get_model(): | ||
if config.APP_TO_CONNECT == constants.MINDSDB: | ||
return MindsDBModel() | ||
else: | ||
raise ValueError(constants.INVALID_APP_MESSAGE) | ||
|
||
|
||
@app.before_request | ||
def before_request(): | ||
# Set the connector and model instances as application context variables | ||
g.connector = get_connector() | ||
g.model = get_model() | ||
|
||
# Create a versioned API Blueprint | ||
api_v1 = Blueprint('api_v1', __name__, url_prefix='/api/v1') | ||
|
||
# Initialize Flask-RESTx Api object | ||
api = Api(api_v1, version='0.1.0', title='Mind Reader API', description='API for the Mind Reader backend') | ||
|
||
|
||
# Register the predict_ns namespace | ||
api.add_namespace(predict_ns) | ||
|
||
# Register the API Blueprint | ||
app.register_blueprint(api_v1) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.logger.setLevel(logging.DEBUG) | ||
app.logger.addHandler(logging.StreamHandler()) | ||
app.run(debug=True) | ||
initialize() | ||
app.run(debug=False) |
File renamed without changes.
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,30 @@ | ||
import os | ||
|
||
# Data source to connect to | ||
DB_ENGINE = 'yugabyte' | ||
# Name of the database in source | ||
DB_NAME_IN_SOURCE = 'demo' | ||
# Name of the schema in source database | ||
SCHEMA_NAME_IN_SOURCE = 'public' | ||
# Port at which database is available | ||
DB_PORT = 5433 | ||
# Database connection arguments | ||
DB_CONNECTION_ARGS = { | ||
# User name | ||
"user": os.environ.get('DB_USER'), | ||
# Password for the user | ||
"password": os.environ.get('DB_PASSWORD'), | ||
# Url where database is available | ||
"host": os.environ.get('DB_HOST'), | ||
# Port to connect to database | ||
"port": DB_PORT, | ||
# Database name | ||
"database": DB_NAME_IN_SOURCE, | ||
# Schema name | ||
"schema": SCHEMA_NAME_IN_SOURCE | ||
} | ||
# Name to be given to DB in the connector | ||
DB_NAME_IN_CONNECTOR = 'yugabyte_demo' | ||
|
||
# Name of the chat input table in DB | ||
CHAT_INPUT_TABLE = 'chat_input_table' |
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,3 @@ | ||
# Configuration settings | ||
# Project name | ||
PROJECT_NAME = 'mind_reader_project' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Empty file.
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,45 @@ | ||
from flask import Flask | ||
|
||
from config.model import * | ||
from config.general import PROJECT_NAME | ||
from config.database import * | ||
from mindsdb.utils import server, is_project_created, is_model_created, is_db_created | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
def initialize(): | ||
project = server.get_project(PROJECT_NAME) if is_project_created(PROJECT_NAME) else server \ | ||
.create_project(PROJECT_NAME) | ||
project.get_model(MODEL_NAME_IN_CONNECTOR) if is_model_created(MODEL_NAME_IN_CONNECTOR) \ | ||
else project.create_model( | ||
name=MODEL_NAME_IN_CONNECTOR, | ||
predict='response', | ||
engine=MODEL_ENGINE, | ||
options={ | ||
'model_name': MODEL_NAME, | ||
'api_key': OPENAI_API_KEY, | ||
'prompt_template': ''' | ||
Hello there, I'm here to provide support and information during tough times. | ||
Whether you have questions, need encouragement, or seek resources, I'm here for you. | ||
Please share what's on your mind, and I'll do my best to assist you. Remember, you're not alone, | ||
and together, we can navigate through challenges with strength and resilience. | ||
If you're feeling down, just let me know, and I'll provide uplifting words of encouragement. | ||
If you have specific questions or need information, feel free to ask. | ||
Reply like a friend who cares and wants to help. | ||
Input message: {{text}} | ||
In less than 550 characters, when there's some sign of distress in the input share healthy habits, | ||
motivational quotes, inspirational real-life stories. | ||
Provide options to seek out in-person help if you aren't able to satisfy. | ||
Keep the conversation going by asking them to share more. Be a good listener and conversationalist. | ||
In case there's no signs of distress then reply casually like how you would engage in conversation. | ||
''', | ||
'max_tokens': 300 | ||
} | ||
) | ||
server.get_database(DB_NAME_IN_CONNECTOR) if is_db_created(DB_NAME_IN_CONNECTOR) else server \ | ||
.create_database( | ||
engine=DB_ENGINE, | ||
name=DB_NAME_IN_CONNECTOR, | ||
connection_args=DB_CONNECTION_ARGS | ||
) |
Oops, something went wrong.