Skip to content

Commit

Permalink
Merge pull request #10 from ttpss930141011/revert-9-development
Browse files Browse the repository at this point in the history
Revert "Development"
  • Loading branch information
ttpss930141011 authored Oct 8, 2023
2 parents 709f67a + 46ec66a commit fd03fe5
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 130 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ psycopg2==2.9.7
openai==0.27.8
tiktoken==0.4.0
google-search-results==2.4.2
flake8==6.1.0
flake8==6.1.0
20 changes: 3 additions & 17 deletions src/app/flask_postgresql/api/response.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
from typing import List

from linebot.v3.messaging import (
ApiClient,
Configuration,
MessagingApi,
ReplyMessageRequest,
TextMessage,
)
from linebot.v3.messaging.api_response import ApiResponse
from linebot.v3.messaging.models.message import Message


def create_response(
configuration: Configuration, reply_token: str, messages: List[Message]
) -> ApiResponse:
"""
Creates a response using the Line Bot API.

Args:
configuration (Configuration): The configuration object for the API client.
reply_token (str): The token used to identify the reply message.
messages (List[Message]): The list of messages to be included in the response.

Returns:
ApiResponse: The API response object.
"""
def create_response(configuration: Configuration, reply_token: str, *results) -> ApiResponse:
messages = [TextMessage(text=result) for result in results]

with ApiClient(configuration) as api_client:
line_bot_api = MessagingApi(api_client)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
""" Module for the EventPresenter
"""

from typing import List

from linebot.v3.messaging.models.message import Message

from src.interactor.dtos.event_dto import EventOutputDto
from src.interactor.interfaces.presenters.message_reply_presenter import EventPresenterInterface


class EventPresenter(EventPresenterInterface):
"""Class for the EventPresenter"""

def present(self, output_dto: EventOutputDto) -> List[Message]:
def present(self, output_dto: EventOutputDto) -> str:
"""
Present the output DTO.
Expand Down
2 changes: 0 additions & 2 deletions src/infrastructure/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from src.app.flask_postgresql.configs import Config

from .google_calendar import GoogleCalendarTool
from .stock import CurrentStockPriceTool, StockPerformanceTool

# initialize LangChain services
Expand All @@ -17,5 +16,4 @@
),
CurrentStockPriceTool(),
StockPerformanceTool(),
GoogleCalendarTool(),
]
70 changes: 0 additions & 70 deletions src/infrastructure/tools/google_calendar.py

This file was deleted.

6 changes: 2 additions & 4 deletions src/interactor/dtos/event_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@


from dataclasses import asdict, dataclass
from typing import Dict, List

from linebot.v3.messaging.models.message import Message
from typing import Dict


@dataclass
Expand All @@ -26,7 +24,7 @@ class EventOutputDto:

window: Dict
user_input: str
response: List[Message]
response: str

def to_dict(self):
"""Convert data into dictionary"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@


from abc import ABC, abstractmethod
from typing import List

from linebot.v3.messaging.models.message import Message
from typing import Dict

from src.interactor.dtos.event_dto import EventOutputDto

Expand All @@ -14,5 +12,5 @@ class EventPresenterInterface(ABC):
"""Class for the Interface of the WindowPresenter"""

@abstractmethod
def present(self, output_dto: EventOutputDto) -> List[Message]:
def present(self, output_dto: EventOutputDto) -> Dict:
"""Present the Window"""
25 changes: 3 additions & 22 deletions src/interactor/use_cases/create_text_message_reply.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
""" This module is responsible for creating a new window.
"""
from typing import List

from langchain.agents import AgentExecutor
from linebot.v3.messaging.models import TextMessage
from linebot.v3.messaging.models.message import Message

from src.interactor.dtos.event_dto import EventInputDto, EventOutputDto
from src.interactor.interfaces.logger.logger import LoggerInterface
Expand Down Expand Up @@ -47,30 +43,15 @@ def _get_agent_executor(self, input_dto: EventInputDto) -> AgentExecutor:
)
return agent_executor

def execute(self, input_dto: EventInputDto):
"""
Executes the given event input DTO.
Args:
input_dto (EventInputDto): The event input DTO containing the necessary information for execution.
Returns:
EventOutputDto: The output DTO containing the result of the execution.
Raises:
None.
"""
def execute(self, input_dto: EventInputDto) -> str:
validator = EventInputDtoValidator(input_dto.to_dict())
validator.validate()

response: List[Message] = []

if input_dto.window.get("is_muting") is True:
response.append(TextMessage(text="靜悄悄的,什麼都沒有發生。"))
response = "靜悄悄的,什麼都沒有發生。"
else:
agent_executor = self._get_agent_executor(input_dto)
result = agent_executor.run(input=input_dto.user_input)
response.append(TextMessage(text=result))
response = agent_executor.run(input=input_dto.user_input)

output_dto = EventOutputDto(
window=input_dto.window,
Expand Down
8 changes: 3 additions & 5 deletions src/interactor/use_cases/create_text_message_reply_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from unittest import mock

from linebot.v3.messaging.models import TextMessage

from src.interactor.dtos.event_dto import EventInputDto, EventOutputDto
from src.interactor.interfaces.logger.logger import LoggerInterface
from src.interactor.interfaces.presenters.message_reply_presenter import EventPresenterInterface
Expand Down Expand Up @@ -37,7 +35,7 @@ def test_new_user_create_text_message_reply(mocker: mock, fixture_window):
logger_mock.log_info.assert_called_once_with("Create reply successfully")

output_dto = EventOutputDto(
window=fixture_window, user_input="Test input", response=[TextMessage(text="Test output")]
window=fixture_window, user_input="Test input", response="Test output"
)
presenter_mock.present.assert_called_once_with(output_dto)
assert result == "Test output"
Expand Down Expand Up @@ -71,7 +69,7 @@ def test_regular_create_text_message_reply(mocker: mock, fixture_window):
logger_mock.log_info.assert_called_once_with("Create reply successfully")

output_dto = EventOutputDto(
window=fixture_window, user_input="Test input", response=[TextMessage(text="Test output")]
window=fixture_window, user_input="Test input", response="Test output"
)
presenter_mock.present.assert_called_once_with(output_dto)
assert result == "Test output"
Expand Down Expand Up @@ -106,7 +104,7 @@ def test_create_text_message_reply_if_window_is_muting(mocker: mock, fixture_win
logger_mock.log_info.assert_called_once_with("Create reply successfully")

output_dto = EventOutputDto(
window=fixture_window, user_input="Test input", response=[TextMessage(text="靜悄悄的,什麼都沒有發生。")]
window=fixture_window, user_input="Test input", response="靜悄悄的,什麼都沒有發生。"
)
presenter_mock.present.assert_called_once_with(output_dto)
assert result == "Test output"

0 comments on commit fd03fe5

Please sign in to comment.