Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from ttt246/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
th37rose committed May 28, 2023
2 parents ece669a + c70fa5c commit 47a23ef
Show file tree
Hide file tree
Showing 29 changed files with 852 additions and 7,924 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
uses: actions/setup-python@v3
- name: install
run: pip install -r requirements.txt
- name: embed app document
run: python src/langchain/csv_embed.py
- name: test
run: python -m pytest
- name: api test with saucectl
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/firebase_cred.json
/.idea
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ Werkzeug==2.2.3
win32-setctime==1.1.0
wrapt==1.15.0
yarl==1.8.2
rising_plugin==0.1.0
16 changes: 16 additions & 0 deletions sauce_tests/06 Get Commands/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- id: global
children:
- id: variable
name: protocol
value: https://
- id: variable
name: domain
value: smartphone.herokuapp.com
- id: variable
name: endpoint
value: /commands
- id: sets
children:
- id: set
children: []
name: default
16 changes: 16 additions & 0 deletions sauce_tests/06 Get Commands/unit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
assertions:
- id: get
children: []
url: ${protocol}${domain}${endpoint}
var: payload
mode: json
- id: assert-equals
expression: payload_response.headers['Content-Type']
value: application/json
- id: assert-exists
expression: payload
- id: assert-exists
expression: payload.message
- id: assert-exists
expression: payload.result
configs: []
File renamed without changes.
100 changes: 100 additions & 0 deletions src/commands/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import json
from typing import Any, Callable, Optional

RISINGBRAIN_COMMAND_IDENTIFIER = "risingbrain_command"


class Command:
"""A class representing a command.
Attributes:
name (str): The name of the command.
description (str): A brief description of what the command does.
"""

def __init__(
self,
name: str,
description: str,
prompt: str,
tags: Any,
enabled: bool = True,
):
self.name = name
self.description = description
self.prompt = prompt
self.tags = tags
self.enabled = enabled

def __call__(self, *args, **kwargs) -> Any:
if not self.enabled:
return f"Command '{self.name}' is disabled: {self.disabled_reason}"
return self.method(*args, **kwargs)

def __str__(self) -> str:
return f"'name': {self.name}, 'description': {self.description}"

def __str_json__(self) -> str:
return json.dumps(
{
"name": self.name,
"description": self.description,
"prompt": self.prompt,
"tags": self.tags,
}
)


class CommandRegistry:
"""
The CommandRegistry class is a manager for a collection of Command objects.
It allows the registration, modification, and retrieval of Command objects,
as well as the scanning and loading of command plugins from a specified
directory.
"""

def __init__(self):
"""this is default commands for now"""
self.commands = [
Command(
"image",
"image description",
"Search a image that #description",
["#description"],
True,
).__str_json__(),
Command(
"notification",
"send notification or alert",
"send that #notification",
["#notification"],
True,
).__str_json__(),
Command(
"sms",
"send a sms",
"",
[],
True,
).__str_json__(),
Command(
"browsing",
"search browser",
"Search something that #description",
["#description"],
True,
).__str_json__(),
Command(
"social",
"search something in social",
"Search something in twitter or facebook that #description",
["#description"],
True,
).__str_json__(),
]

def get_all_commands(self) -> Any:
return self.commands

def add_command(self, command: Command):
self.commands.append(command)
26 changes: 22 additions & 4 deletions src/common/assembler.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
# assembler to mapping data into another data type.
from typing import Any, List

from flask import jsonify

from src.model.basic_model import BasicModel
from src.model.message_model import MessageModel


class Assembler:
# mapping to BasicModel
def to_basic_model(self, data: any) -> BasicModel:
"""mapping to BasicModel"""

def to_basic_model(self, data: Any) -> BasicModel:
model = BasicModel(data["image_name"], data["message"])
return model

# mapping to http response
def to_response(self, code, message, result) -> any:
"""mapping to http response"""

def to_response(self, code, message, result) -> Any:
response = jsonify({"message": message, "result": result})
response.status_code = code
return response

"""mapping data to a collection of MessageModel"""

def to_array_message_model(self, data: Any) -> List[MessageModel]:
result = []
for item in data:
result.append(self.to_message_model(item))
return result

"""mapping data to a MessageModel"""

def to_message_model(self, data: Any) -> MessageModel:
return MessageModel(data["role"], data["content"])
6 changes: 6 additions & 0 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
# open ai
GPT_MODEL = "gpt-3.5-turbo"

# AI Agent name
AGENT_NAME = "RisingBrain Assistant"

# indexes of relatedness of embedding
COMMAND_SMS_INDEXS = [4, 5]


def get_firebase_cred():
if os.path.exists("firebase_cred.json"):
Expand Down
89 changes: 0 additions & 89 deletions src/langchain/chatbot.py

This file was deleted.

24 changes: 0 additions & 24 deletions src/langchain/csv_embed.py

This file was deleted.

62 changes: 0 additions & 62 deletions src/langchain/image_embedding.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/langchain/phone.csv

This file was deleted.

0 comments on commit 47a23ef

Please sign in to comment.