This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #5 from ttt246/develop
Develop
- Loading branch information
Showing
29 changed files
with
852 additions
and
7,924 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
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,2 @@ | ||
/firebase_cred.json | ||
/.idea |
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 |
---|---|---|
|
@@ -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 |
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,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 |
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,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.
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,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) |
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,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"]) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.