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

Fix #38

Merged
merged 2 commits into from
Jun 28, 2024
Merged

Fix #38

Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified Ai_work.db
Binary file not shown.
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Flask_Cors==4.0.1
Flask==2.3.2
openai
arrow
qianfan
qianfan
pytesseract
35 changes: 31 additions & 4 deletions backend/run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,40 @@ def deleteReservation():
for member_id in member_ids:
if int(member_id[0]) != int(user_id):
result2 = Team.insertMeetingRoomReservation(room_id, member_id[0], user_id, start_time, end_time, date, subject, team_id, 1)
print(result2)
# print(result2)
activity_name = "会议 - " + room_name + " - " + subject
result3 = DBUtil.deleteActivityByActivityName(activity_name, date)
print(result3)

if result == False:
return jsonify({'code': 1, 'message': '删除会议室预约失败', 'status': 500 })
return jsonify({'code': 0, 'message': '删除会议室预约成功', 'status': 200 }), 200


# getReservationInfo
@app.route(apiPrefix + 'getReservationInfo', methods=['POST'])
def getReservationInfo():
data = request.get_json()
user_id = data.get('userID')
reservations = Team.getMeetingRoomReservation(user_id)
if reservations is None:
return jsonify({'code': 1, 'message': '获取会议室预约列表失败', 'status': 500 })
# room_id, room_name, user_id, reserve_user_id, reserve_user_name, start_time, end_time, date, subject, team_id, team_name, type
keys = ['id', 'room_id', 'room_name', 'user_id', 'reserve_user_id', 'reserve_user_name', 'start_time', 'end_time', 'date', 'subject', 'team_id', 'team_name', 'type']
reservations_list = [dict(zip(keys, reservation)) for reservation in reservations]
return jsonify({'code': 0, 'message': '获取会议室预约列表成功', 'status': 200, 'data': reservations_list}), 200

# acceptReservation
@app.route(apiPrefix + 'acceptReservation', methods=['POST'])
def acceptReservation():
data = request.get_json()
user_id = data.get('userID')
reservation_id = data.get('reservation_id')
type = data.get('type')
result = Team.deleteMeetingRoomReservation(reservation_id, user_id, type)
if result == False:
return jsonify({'code': 1, 'message': '已读失败', 'status': 500 })
return jsonify({'code': 0, 'message': '已读成功', 'status': 200 }), 200


@app.route(apiPrefix + 'getUserReservations', methods=['POST'])
def getUserReservations():
Expand Down Expand Up @@ -475,7 +500,7 @@ def getAIResult():
keys = ['id', 'name', 'floor', 'capacity', 'equipment']
meeting_rooms = [dict(zip(keys, room)) for room in meeting_rooms]

prompt_head = '''你是会议室预约小助手,会议室预约的必选项是会议主题、会议预约日期、会议预约时间(可以是时间段也可以是时间长度,若是后者,你要为用户选择一个时间,格式例如9:00-12:00),可选项是会议人数(default=5),会议室名称(default根据数据选择)。你要根据用户输入判断是否覆盖了必选项的所有。如果缺了,请你必须告知用户需要补充什么信息,此时**不需要**返回json;如果没缺:你**仅**需返回一个json格式,key必须为:subject, date, time, room_name, room_id, number_of_people。\n\n'''
prompt_head = '''你是会议室预约小助手,会议室预约的必选项是会议主题、会议预约日期、会议预约时间(可以是时间段也可以是时间长度,若是后者,你要为用户选择一个时间,格式例如9:00-12:00),可选项是会议人数(default=5),会议室名称(default根据数据选择)。你要根据用户输入判断是否覆盖了必选项的所有。如果缺了,请你必须分点告知用户需要补充什么信息,此时**不需要**返回json;如果没缺:你**仅**需返回一个json格式,key必须为:subject, date, time, room_name, room_id, number_of_people。\n\n'''

history = chat_history.get(userID)
# 列表合并为字符串
Expand All @@ -485,6 +510,7 @@ def getAIResult():
content = content.split('\n')[-1]

content2 = prompt_head + '可用会议室:' + str(meeting_rooms) + '\n\n' + '现在的时间是:' + day_and_time + '\n\n' + '请按照我的指令执行:' + '\n\n' + history + '\n\n' + content
print("==============", content2)

response = llm_minimax.query(content2)
print(response)
Expand Down Expand Up @@ -561,10 +587,11 @@ def getAIResult():
number_of_people = 0

meeting_rooms = RBooking.getroombycapacity(number_of_people)
print(meeting_rooms)
keys = ['id', 'name', 'floor', 'capacity', 'equipment']
rooms_list = [dict(zip(keys, room)) for room in meeting_rooms]

prompt_head = '''你是会议室预约小助手,会议室预约的必选项是会议主题、会议预约日期、会议预约时间(可以是时间段也可以是时间长度,若是后者,你要为用户选择一个时间, 格式例如9:00-12:00),可选项是会议人数(default=5),会议室名称(default根据数据选择)。你要根据用户输入判断是否覆盖了必选项的所有。如果有缺漏,请你告知用户需要补充什么信息,此时**不需要**返回json;如果没缺:你**仅**需返回一个json格式,key必须为:subject, date, time, room_name, room_id, number_of_people。\n\n'''
prompt_head = '''你是会议室预约小助手,会议室预约的必选项是会议主题、会议预约日期、会议预约时间(可以是时间段也可以是时间长度,若是后者,你要为用户选择一个时间, 格式例如9:00-12:00),可选项是会议人数(default=5),会议室名称(default根据数据选择)。你要根据用户输入判断是否覆盖了必选项的所有。如果有缺漏,请你必须分点告知用户需要补充什么信息,此时**不需要**返回json;如果没缺:你**仅**需返回一个json格式,key必须为:subject, date, time, room_name, room_id, number_of_people。\n\n'''

content2 = prompt_head + '可用会议室:' + str(rooms_list) + '\n\n' + '现在的时间是:' + day_and_time + '\n\n' + '请按照我的指令执行:' + '\n\n' + content
print(content2)
Expand Down
1 change: 1 addition & 0 deletions backend/sqlite_roombooking.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def getroombycapacity(capacity):
lock_threading.acquire()
# 返回3个会议室,id小的优先,同时返回
cursor.execute("SELECT * FROM meeting_room WHERE capacity>=? ORDER BY capacity ASC LIMIT 3", (capacity,))
return cursor.fetchall()
except sqlite3.Error as e:
print(e)
return None
Expand Down
24 changes: 24 additions & 0 deletions backend/sqlite_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ def insertMeetingRoomReservation(room_id, user_id, reserve_user_id, start_time,
finally:
lock_threading.release()

def getMeetingRoomReservation(user_id):
try:
lock_threading.acquire()
cursor.execute('''SELECT * FROM meeting_room_reservation WHERE user_id = ?''', (user_id,))
return cursor.fetchall()
except sqlite3.Error as e:
print(e)
return False
finally:
lock_threading.release()

def deleteMeetingRoomReservation(reservation_id, user_id, type):
try:
lock_threading.acquire()
print(reservation_id, user_id, type)
cursor.execute('''DELETE FROM meeting_room_reservation WHERE id = ? AND user_id = ? AND type = ?''', (reservation_id, user_id, type))
conn.commit()
return True
except sqlite3.Error as e:
print(e)
return False
finally:
lock_threading.release()


def insertTeam(team_name, captain_id):
try:
Expand Down
85 changes: 55 additions & 30 deletions frontend/src/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styled from 'styled-components';
import RightTopSection from './RightTopSection';
import LeftTopSection from './LeftTopSection';
import RightTopSection2 from './RightTopsection2';
import { Button, Card, Form, Input, InputNumber, Modal, Select, message } from 'antd';
import { Button, Card, Flex, Form, Input, InputNumber, Modal, Select, message } from 'antd';
import moment from 'moment';

const Container = styled.div`
Expand Down Expand Up @@ -190,35 +190,57 @@ const Homepage: React.FC = () => {
};

// 实例化迅飞语音听写
// const xfVoice = new XfVoiceDictation({
// APPID: '27ce1c02',
// APISecret: 'NWRhNDM1NTJlMmJiYmU0YWI5OGY1YmNm',
// APIKey: 'c55054b06c4f1753117debf4b31168dd',
// onWillStatusChange: function (oldStatus: any, newStatus: any) {
// console.log('开始识别:', oldStatus, newStatus);
// },
// onTextChange: function (text: any) {
// console.log('识别内容:', text);
// if (text) {
// if (times.current) {
// clearTimeout(times.current);
// }
// times.current = setTimeout(() => xfVoice.stop(), 3000);
// // 将识别内容填充到ProChat的输入框中
// if (chatRef.current) {
// chatRef.current.setValue(text);
// }
// }
// }
// });

// const handleVoiceButtonClick = () => {
// xfVoice.start();
// };

// const handleVoiceStopButtonClick = () => {
// xfVoice.stop();
// };
const Control = () => {
const [isRecording, setIsRecording] = useState(false);
const proChat = useProChat();
const chatRef = useRef('');

const xfVoice = new XfVoiceDictation({
APPID: '27ce1c02',
APISecret: 'NWRhNDM1NTJlMmJiYmU0YWI5OGY1YmNm',
APIKey: 'c55054b06c4f1753117debf4b31168dd',
onWillStatusChange: function (oldStatus: any, newStatus: any) {
console.log('语音识别状态变化:', oldStatus, newStatus);
if (newStatus === 'end') {
// 获取识别的文本并发送消息
const recognizedText = chatRef.current;
if (recognizedText) {
proChat.sendMessage(recognizedText);
chatRef.current = ''

}
}
},
onTextChange: function (text: any) {
console.log('识别内容:', text);
if (text) {
chatRef.current = text; // 保存识别到的内容
}
}
});

const handleVoiceButtonClick = () => {
if (isRecording) {
xfVoice.stop();
setIsRecording(false);
} else {
chatRef.current = ''
xfVoice.start();
setIsRecording(true);
}
};

return (
<div style={{ paddingBottom: 8, paddingLeft: 24, textAlign: 'right' }}>
<Button
type={'primary'}
onClick={handleVoiceButtonClick}
>
{isRecording ? '停止录音' : '开始录音'}
</Button>
</div>
);
};


return (
Expand All @@ -237,6 +259,8 @@ const Homepage: React.FC = () => {
}}
>
<div style={{ height: '350px' }}>
<ProChatProvider>
<Control />
<ProChat
helloMessage={'欢迎使用协时通,我是你的智能AI助手!\n我可以帮助你查询日程、安排会议。\n你可以试着问我:\n1. 我今天有哪些安排 \n2. 今天我有哪些会议 \n3. 请帮我预约一个明天下午6人的会议室'}
request={handleRequest}
Expand All @@ -261,6 +285,7 @@ const Homepage: React.FC = () => {
},
}}
/>
</ProChatProvider>
</div>
</div>
</Container>
Expand Down
Loading
Loading