Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugful code #65

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b925c73
ignore all sqlite and bin
quan0715 Oct 22, 2023
a43d647
Merge branch 'main' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
c081ec8
Merge branch 'main' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
6f9d76c
bus langchain upgrade
quan0715 Oct 22, 2023
b826ca8
rm cache
quan0715 Oct 22, 2023
6170cf2
module name
quan0715 Oct 22, 2023
bafd857
Merge branch 'main' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
255440d
bugful code
Jack-1D Oct 22, 2023
630c411
pool save user_id
Jack-1D Oct 22, 2023
75d9fc4
Merge branch 'Jack' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
a3b9eba
fix course enum
Jack-1D Oct 22, 2023
a271213
Merge branch 'Jack' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
3fed053
use retrieve
Jack-1D Oct 22, 2023
e14ae41
Merge branch 'Jack' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
8d0f355
little fix
Jack-1D Oct 22, 2023
2e653a6
fix
Jack-1D Oct 22, 2023
16a2bf7
some little bug
quan0715 Oct 22, 2023
2a44238
Merge branch 'Jack' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
eb7cc55
chore
quan0715 Oct 22, 2023
c529c44
change posi
Jack-1D Oct 22, 2023
a51d0e0
Merge branch 'Jack' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
c742b26
add description
Jack-1D Oct 22, 2023
2e3f4e7
Merge branch 'Jack' of https://github.com/quan0715/NCU_Student_Helper…
quan0715 Oct 22, 2023
1a6580a
eeclass debug mode
quan0715 Oct 22, 2023
ccc718e
move request place
Jack-1D Oct 22, 2023
a9493b2
little fix
Jack-1D Oct 22, 2023
30cbc98
fix
Jack-1D Oct 22, 2023
1f7fbf2
move to outside
Jack-1D Oct 22, 2023
c67c51c
It work!!!!!!!!! eeclass bot
quan0715 Oct 22, 2023
f8a2afc
duplicate to all file
Jack-1D Oct 22, 2023
ba8f705
little fix
Jack-1D Oct 22, 2023
4e04c94
fix
quan0715 Oct 22, 2023
ced8dba
add get_db
Jack-1D Oct 22, 2023
6b4abe5
save db
Jack-1D Oct 22, 2023
c27130d
fix type
Jack-1D Oct 22, 2023
dae02e1
delete getTool
Jack-1D Oct 22, 2023
c6ffd8e
deletion of comment
Jack-1D Oct 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions langchain_test/tools/hw_recommendation_tool.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from langchain.tools import BaseTool
from NotionBot import *
from NotionBot.base.Database import *
# from ncu_helper_server.eeclass_notion_db_crawler.EEClassNotionDBCrawler import EEClassNotionDBCrawler

from typing import Any, Optional, Type
from pydantic import BaseModel, Field
from langchain.prompts import PromptTemplate
from langchain.output_parsers import PydanticOutputParser
import datetime
import os
from fuzzywuzzy import fuzz
import aiohttp
from datetime import datetime, timezone, timedelta, date
from dotenv import load_dotenv

from NotionBot import Notion
from NotionBot.base import Database

from NotionBot import Notion
from NotionBot.base import Database
import enum, random
# from ncu_helper_server.eeclass_notion_db_crawler.Type import Bulletin, Homework, Material

import NotionBot
Expand Down
2 changes: 2 additions & 0 deletions ncu_helper_server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

__pycache__
db.sqlite3
*.sqlite3
*.bin
2 changes: 1 addition & 1 deletion ncu_helper_server/eeclass_setting/eeclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def eeclass_pipeline(user: LineUser):
# await bot.retrieve_all_material()
# await bot.retrieve_all_materials_details()
# reply_message.append('\n'.join(f'教材:{str(m)}' for m in bot.material_list))
notion_crawler = EEClassNotionDBCrawler(user.notion_token, user.notion_template_id)
notion_crawler = EEClassNotionDBCrawler.EEClassNotionDBCrawler(user.notion_token, user.notion_template_id)
newly_upload = []
# newly_upload.extend(await update_all_bulletin_info_to_notion_db(bot.bulletins_detail_list, notion_crawler.bulletinDB))
# newly_upload.extend(await update_all_homework_info_to_notion_db(bot.homeworks_detail_list, notion_crawler.homeworkDB))
Expand Down
32 changes: 15 additions & 17 deletions ncu_helper_server/line_bot_callback/busChatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from uuid import uuid4
from .bus_api.api import BusAPI
from .bus_api.stop_data import StopData
from datetime import datetime


def set_exit_state(user_id: str) -> None:
Expand Down Expand Up @@ -45,49 +46,46 @@ class BusLine(str, Enum):

class BusInfoInput(BaseModel):
direction: int = Field(
description="If the bus is going to NCU(中央大學 or 中央), it should be 1; if the bus is leaving from NCU(中央大學 or 中央), it should be 0.")
description="If the user want to go to NCU(中央大學 or 中央), it should be 1; else, it should be 0.")
destination: int = Field(
description="Whether the bus is going to (leaving from) 火車站 (1) or 高鐵站 (0).")
description="If the user want to go to or leave from '火車站', it should be 1; if the user want to go to or leave from '高鐵站', it should be 0.")

@field_validator("line", mode="before")
def station_validator(cls, value):
if value not in list(map(lambda x: x.value, BusLine)):
value = BusLine.other
return value
# @field_validator("line", mode="before")
# def station_validator(cls, value):
# if value not in list(map(lambda x: x.value, BusLine)):
# value = BusLine.other
# return value


class BusInfoTool(BaseTool):
name = "BusInfoTool"
description = "Useful to get when the bus will arrive the bus stop."
description = f"Useful to get when the bus will arrive the bus stop. You have to ask user '請問您想要回中央、去高鐵站,還是去火車站?'. Current time is {datetime.now().strftime('%c')}"

args_schema: Optional[Type[BaseModel]] = BusInfoInput

def _run(self, direction: int, destination: str) -> str:

stop = "中央大學正門"
stop = "中央大學警衛室"
if destination == 1:
line_coll = ["172", "173"]
stop_list = list(BusAPI.get_all_stops("172"))
line_coll = ["132", "133"]
if direction == 1:
stop = "中壢火車站"
stop = "中壢公車站"
else:
line_coll = ["132", "133"]
stop_list = list(BusAPI.get_all_stops("132"))
line_coll = ["172", "173"]
if direction == 1:
stop = "高鐵桃園站"

print(stop_list)

stop_info_coll = list(
map(lambda x: BusAPI.get_bus_data(x, direction), line_coll))

result_coll: list[StopData] = []
for infos in stop_info_coll:
for info in infos:
if info.stop_name == stop:
result_coll.append(info)
sorted(result_coll, key=lambda x: x.next_bus_time)
result = result_coll[0]
return f"[System] The next bus is arriving at {result.next_bus_time} and the status is {result.stop_status} at Station {result.stop_name}"
return str({'data': result})


class BusAgentPool(BasePool):
Expand Down
17 changes: 17 additions & 0 deletions ncu_helper_server/line_bot_callback/chatBotExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ def wrapper(*a, **b):
return wrapper
return outer

def text_with_leave(func):
"""
wrap a function returning a string as legal chatBot returned message
"""
def wrapper(*a, **b):
text = func(*a, **b)
return TextSendMessage(
text=text,
quick_reply=QuickReply(
items=[QuickReplyButton(
image_url='https://scontent.xx.fbcdn.net/v/t1.15752-9/387560636_1364784567461116_3708224130470311929_n.png?stp=cp0_dst-png&_nc_cat=108&ccb=1-7&_nc_sid=510075&_nc_ohc=S5L-rQ1y9RcAX9PYIpB&_nc_ad=z-m&_nc_cid=0&_nc_ht=scontent.xx&oh=03_AdQKnpWq0ikfumqNYbstXppxcr2WW48UmGkQgabRCkjJow&oe=655C13D9',
action=MessageAction('離開', '離開'))]
)
) if text else None
return wrapper


def button_group(title="", text="", default_text='default alt text'):
"""
wrap a function returning a list of string as the button group text of chatbot
Expand Down
57 changes: 50 additions & 7 deletions ncu_helper_server/line_bot_callback/chatBotModel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from line_bot_callback.ncu_wiki import getWikiChainLLM
from .chatBotExtension import chat_status, jump_to, text, button_group, do_nothing, state_ai_agent, quick_reply
from .chatBotExtension import chat_status, jump_to, text, button_group, do_nothing, state_ai_agent, quick_reply, text_with_leave
from typing import Tuple
from eeclass_setting.models import LineUser
from eeclass_setting.appModel import check_eeclass_update_pipeline, find_user_by_user_id
Expand All @@ -17,7 +17,6 @@ def default_message(event, agent):
jump_to(main_menu, event.source.user_id)
return [
(dog_icon_url, '資料設定', '資料設定'),
(dog_icon_url, '課程查詢', '課程查詢'),
(dog_icon_url, '跟我閒聊', agent.run('請給我一個很白癡的問題')),
(dog_icon_url, 'EECLASS查詢', 'EECLASS查詢'),
(dog_icon_url, '交通查詢', '交通查詢')
Expand All @@ -34,7 +33,7 @@ def main_menu(event, aiAgent):
case '資料設定':
jump_to(default_message, event.source.user_id, propagation=True)
return settings.FRONT_END_WEB_URL
case 'EECLASS查詢':
case 'EECLASS更新':
jump_to(update_eeclass, event.source.user_id, True)
return
case '交通查詢':
Expand Down Expand Up @@ -73,7 +72,7 @@ def traffic_menu(event):
match event.message.text:
case '公車查詢':
jump_to(bus_util, event.source.user_id, False)
return "請問你想要查什麼公車呢?"
return "請問您想要回中央、去高鐵站,還是去火車站?"
case '高鐵查詢/訂票':
jump_to(hsr_util, event.source.user_id, False)
from backenddb.appModel import find_hsr_data
Expand All @@ -99,15 +98,18 @@ def update_eeclass(event):
cb.push_message(event.source.user_id, text(lambda ev: '獲取資料中')(event))
try:
result = check_eeclass_update_pipeline(user)
print("a")
jump_to(eeclass_util, event.source.user_id, True)
return result
except Exception as e:
jump_to(default_message, event.source.user_id, True)
import traceback
traceback.print_exception(e)
return f'獲取失敗, 錯誤訊息:\n{e}'


@chat_status("hsr util")
@text
@text_with_leave
def hsr_util(event):
from . import hsrChatbot
hsr_agent_pool_instance = hsrChatbot.get_agent_pool_instance()
Expand All @@ -129,7 +131,7 @@ def eeclass_util(event):
# agent.run("我要知道eeclass更新了啥")
# return agent.run(event.message.text)
jump_to(default_message, event.source.user_id, True)
return '請實作eeclassChatBot'
return '更新完成!'

@chat_status("bus util")
@text
Expand Down Expand Up @@ -178,4 +180,45 @@ def about_course(event):
if agent is None:
agent = ee_agent_pool_instance.add(event.source.user_id)
agent.run("我要查詢EECLASS資料")
return agent.run(event.message.text)
return agent.run(event.message.text)

@chat_status("debug_about_kind")
@text
def debug_about_course(event):
# from . import eeclassBotTool
# ee_agent_pool_instance = eeclassBotTool.get_agent_pool_instance()
# agent = ee_agent_pool_instance.get(event.source.user_id)
# if agent is None:
# agent = ee_agent_pool_instance.add(event.source.user_id)
# agent.run("我要查詢EECLASS資料")
# return agent.run(event.message.text)
jump_to(default_message, event.source.user_id, True)
return """以下是最近的新公告:

1. 軟體工程實務 Software engineering practices:
- 標題:Week4 lab3 補交相關事項
- 內容:助教已經將各位的學習狀況以及建議看完了,補交期限為10/15 23:59,成績將會乘上75%。
- 發布日期:2023-10-09

2. 軟體工程實務 Software engineering practices:
- 標題:Term project現場demo取消,改為繳交影片
- 內容:Term project實體demo取消,改為繳交demo影片,影片繳交deadline為10/29 23:59。
- 發布日期:2023-10-12

3. 電腦攻擊與防禦 The Attack and Defense of Computers:
- 標題:10/17 重要提醒
- 內容:明天請在家看影片,學校 web server 目前有問題,老師的網頁無法正常更新。
- 發布日期:2023-10-16

4. Linux作業系統 Linux Operating System:
- 標題:Linux Project 1
- 內容:Linux Project 1已發布在課程網頁上。
- 發布日期:2023-10-09

5. 軟體工程實務 Software engineering practices:
- 標題:Week4 lab3 會議連結
- 內容:因為沒有同學反應設備問題,所以採用全線上模式,會議連結在公告中。
- 發布日期:2023-10-02

以上是最近的新公告,詳細內容請參閱課程網頁或公告。
"""
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading