gkijkul commited on
Commit
6640d96
·
1 Parent(s): 74debcf

expense justification feature added

Browse files
src/chatbot/form_management/acceptance_criteria.py CHANGED
@@ -68,11 +68,12 @@ acceptance_criteria = {
68
  {
69
  "fieldName": "Expense Justification",
70
  "priority": 8,
71
- "description": "The reason for the expense seen in the receipt.",
72
  "validationRules": [
73
- "Must provide a justification for the expense that contributes to the project."
 
74
  ],
75
- "exampleInput": "Purchase seeds to plant trees in the project area."
76
  }
77
  ]
78
  }
 
68
  {
69
  "fieldName": "Expense Justification",
70
  "priority": 8,
71
+ "description": "The expense description pertaining to the project's scope.",
72
  "validationRules": [
73
+ "Cannot be none.",
74
+ "Must provide a description for how the expense contributes towards the project."
75
  ],
76
+ "exampleInput": "ค่าจ้างแรงงาน ทำแนวกันไฟในจุดพื้นที่เสี่ยงต่อครั้งที่ 2-8 ทุก 10 วัน"
77
  }
78
  ]
79
  }
src/chatbot/form_management/project_task_descriptions.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ project_tasks = {
2
+ "tasks:": [
3
+ {
4
+ "Activity": "ทำแนวกันไฟครั้งที่ 1",
5
+ "Items": "ค่าอาหาร 20000 บาท ค่าเช่ารถไม่เกินเครื่องเป่า 1000 บาท รวมเป็นเงิน 21000 บาท",
6
+ "Budget": "6000"
7
+ },
8
+ {
9
+ "Activity": "ทำแนวกันไฟในจุดพื้นที่เสี่ยงต่อครั้งที่ 2-8 ทุก 10 วัน",
10
+ "Items": "ค่าจ้างแรงงาน 300 บาท/คน",
11
+ "Budget": "288000"
12
+ },
13
+ {
14
+ "Activity": "ลาดตระเวน วันละ 18 คน 4 ครั้ง/สัปดาห์",
15
+ "Items": "ค่าจ้างแรงงาน 300 บาท/คน/วัน",
16
+ "Budget": "345600"
17
+ },
18
+ {
19
+ "Activity": "ซ่อมประปาไฟฟ้า ที่พักสำหรับลาดตระเวน",
20
+ "Items": "-ค่าแรงงานในการสร้างซ่อมประปา เป็นลักษณะเฉพาะพื้นที่มีความลาดชัน ฯลฯ จำนวน 2 หลัง 20 คนๆ ละ 300 บาท 10 วัน เป็นเงิน 30000 บาท",
21
+ "Budget": "60000"
22
+ },
23
+ {
24
+ "Activity": "ค่าเบี้ยในการทำฝายชะลอช้า ฝึกซ้อมแถว ฝึกระเบียบ ทำฝาย 4 จุด ทำประเมินเดือนเมษายน พ.ศ. 2567",
25
+ "Items": "-ค่าของ 800 ลูก/ลูกละ 5 บาท รวมเป็นเงินจำนวน 2500 บาท -ปูน 50 ลูก/ลูกละ 170 รวมเป็นเงินจำนวน 8500 บาท -ค่าแรง 9000 บาท",
26
+ "Budget": "80000"
27
+ },
28
+ {
29
+ "Activity": "ปลูกหญ้าแฝก 2000 ต้น เรื่องเล็กๆค่าจ้างจากชาวบ้าน 50 คน",
30
+ "Items": "ค่าแรงงาน 100 คนๆละ 300 บาท รวมเป็นเงินจำนวน 9000 บาท",
31
+ "Budget": "30000"
32
+ },
33
+ {
34
+ "Activity": "ทำทางตรวจเฝ้าระวัง ระยะทาง 10 กม.",
35
+ "Items": "ค่าจ้างแรงงาน 30 คนๆละ 300 บาท ระยะเวลา 10 วัน 90000 บาท",
36
+ "Budget": "90000"
37
+ },
38
+ {
39
+ "Activity": "เฝ้าระวังดูไฟป่า",
40
+ "Items": "ค่าจ้าง 300/คน ใช้ 25 คน",
41
+ "Budget": "15000"
42
+ },
43
+ {
44
+ "Activity": "ทำบัตรขึ้นทะเบียนผู้ใช้ประโยชน์จากชุมชน",
45
+ "Items": "ค่าทำบัตรบันทึก 700 บาท",
46
+ "Budget": "35000"
47
+ },
48
+ {
49
+ "Activity": "กองทุนอาสาสมัครป่าไม้",
50
+ "Items": "ค่าทำบัญชีอาสาฯ/ค่าย",
51
+ "Budget": "50000"
52
+ },
53
+ {
54
+ "Activity": "กิจกรรมประชุมหารือ ประชุมคณะทำงานการดำเนินงานดูแล รักษาทางการขอคืนพื้นที่และการดำเนินงานป่าชุมชน",
55
+ "Items": "-ประชุมคณะกรรมการดำเนินงาน 25 คน จำนวน 12 ครั้ง -ค่าอาหาร 300 คนๆละ 100 บาท 30000 บาท -ค่าตอบแทนผู้เข้าร่วมฯ 30 คนๆละ 300 บาทๆ ละ 12 ครั้ง 144000 บาท -ประชุมร่วมกับชุมชนวางแผนการดำเนินงานค่าอาหารผู้เข้าร่วมจำนวน 288 คนๆละ 3 ครั้งๆ ละ 100 บาท 28800 บาท รวม 4 ครั้ง 115200 บาท - หมึกปริ้นเตอร์ กระดาษ A4 ปากกาไม้บรรทัด พิมพ์เอกสาร 3000 บาท - อุปกรณ์ 3000 บาท - ใช้ในการจัดเตรียมเอกสารด้านเอกสาร จำนวน 1 ชุด 35000 บาท - ค่าเช่าประชุม ค่าขนย้ายเครื่องเสียง พร้อมจ่ายคณะกรรมการที่ปฏิบัติงานเพื่อ��ครงการชุมชน ค่าเช่าลำโพง เครื่องมือในการดับไฟป่า 50000 บาท",
56
+ "Budget": "115200"
57
+ }
58
+ ]
59
+ }
src/chatbot/llm_engine.py CHANGED
@@ -3,7 +3,7 @@
3
  import os
4
  from langchain_openai import ChatOpenAI
5
  import openai
6
- from prompts.chat_completion_prompts import feedback_generation_prompt
7
  from dotenv import load_dotenv
8
  from datetime import datetime
9
 
@@ -32,4 +32,16 @@ def generate_expense_info_feedback(acceptance_criteria: dict, form_info: dict) -
32
  input=feedback_generation_prompt.format(acceptance_criteria, form_info, formatted_date)
33
  )
34
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  return response.output_text
 
3
  import os
4
  from langchain_openai import ChatOpenAI
5
  import openai
6
+ from prompts.chat_completion_prompts import feedback_generation_prompt, expense_description_feedback_prompt
7
  from dotenv import load_dotenv
8
  from datetime import datetime
9
 
 
32
  input=feedback_generation_prompt.format(acceptance_criteria, form_info, formatted_date)
33
  )
34
 
35
+ return response.output_text
36
+
37
+ def generate_expense_description_feedback(project_tasks: dict, expense_description: str) -> str:
38
+ """
39
+ Generate feedback using OpenAI Chat Completion based on project_tasks and expense_description.
40
+ """
41
+ response = client.responses.create(
42
+ model="gpt-4.1-mini",
43
+ temperature=0,
44
+ input=expense_description_feedback_prompt.format(project_tasks, expense_description)
45
+ )
46
+
47
  return response.output_text
src/chatbot/nodes.py CHANGED
@@ -8,8 +8,9 @@ from langgraph.prebuilt import create_react_agent, ToolNode
8
  from langgraph.checkpoint.memory import MemorySaver
9
 
10
  # from chatbot.llm_engine import llm_overall_agent, generate_expense_info_feedback
11
- from llm_engine import llm_overall_agent, generate_expense_info_feedback
12
  from form_management.acceptance_criteria import acceptance_criteria
 
13
  from prompts.agent_prompts import speaker_system_message
14
  from form_management.form_management import Form
15
  from kie import receipt_kie
@@ -30,7 +31,7 @@ form_info = {
30
  # "Row Entries": [],
31
  # },
32
  # "Incompleteness Description": 'None',
33
- # "Expense Justification": 'None',
34
  }
35
 
36
  def get_form_info():
@@ -96,7 +97,10 @@ def edit_form(key: str, value: str) -> dict:
96
  form_info[key] = value
97
  print(form_info)
98
  print(f"Updated {key} to {value}")
99
- feedback = auditor_feedback(form_info)
 
 
 
100
  return {
101
  "review_feedback": feedback # feedback
102
  }
@@ -142,6 +146,10 @@ def auditor_feedback(form_info):
142
  response = generate_expense_info_feedback(acceptance_criteria, form_info)
143
  return response
144
 
 
 
 
 
145
  # # example usage
146
  # if __name__ == "__main__":
147
  # # example_form_info = {
 
8
  from langgraph.checkpoint.memory import MemorySaver
9
 
10
  # from chatbot.llm_engine import llm_overall_agent, generate_expense_info_feedback
11
+ from llm_engine import llm_overall_agent, generate_expense_info_feedback, generate_expense_description_feedback
12
  from form_management.acceptance_criteria import acceptance_criteria
13
+ from form_management.project_task_descriptions import project_tasks
14
  from prompts.agent_prompts import speaker_system_message
15
  from form_management.form_management import Form
16
  from kie import receipt_kie
 
31
  # "Row Entries": [],
32
  # },
33
  # "Incompleteness Description": 'None',
34
+ "Expense Justification": 'None',
35
  }
36
 
37
  def get_form_info():
 
97
  form_info[key] = value
98
  print(form_info)
99
  print(f"Updated {key} to {value}")
100
+ if key == "Expense Justification":
101
+ feedback = exp_desc_feedback(value)
102
+ else:
103
+ feedback = auditor_feedback(form_info)
104
  return {
105
  "review_feedback": feedback # feedback
106
  }
 
146
  response = generate_expense_info_feedback(acceptance_criteria, form_info)
147
  return response
148
 
149
+ def exp_desc_feedback(expense_description):
150
+ response = generate_expense_description_feedback(project_tasks, expense_description)
151
+ return response
152
+
153
  # # example usage
154
  # if __name__ == "__main__":
155
  # # example_form_info = {
src/chatbot/prompts/agent_prompts.py CHANGED
@@ -10,6 +10,7 @@ Buyer Name: The name of the person or entity making the payment.
10
  Buyer Address: The address of the buyer.
11
  Transaction Date: The date of the transaction.
12
  Total Payment Amount: The total amount paid.
 
13
 
14
  Users cannot add new fields to the form, but they can edit the existing fields.
15
  Each time the form is revised, feedback will be provided, and your job to convey the feedback to the user.
 
10
  Buyer Address: The address of the buyer.
11
  Transaction Date: The date of the transaction.
12
  Total Payment Amount: The total amount paid.
13
+ Expense Justification: The justification for the expense as it pertains to the project.
14
 
15
  Users cannot add new fields to the form, but they can edit the existing fields.
16
  Each time the form is revised, feedback will be provided, and your job to convey the feedback to the user.
src/chatbot/prompts/chat_completion_prompts.py CHANGED
@@ -23,4 +23,14 @@ Acceptance Criteria: {}
23
  Form Information: {}
24
 
25
  The current date is: {}
 
 
 
 
 
 
 
 
 
 
26
  """
 
23
  Form Information: {}
24
 
25
  The current date is: {}
26
+ """
27
+
28
+ expense_description_feedback_prompt = """Determine whether the expense description is valid based on the project tasks described.
29
+ Validity is determined by whether the expense description is relevant to the project tasks.
30
+
31
+ If the expense description is relevant, output "Form is complete and valid".
32
+ If the expense description is not relevant, provide your rationale on why it is not relevant.
33
+
34
+ Project Tasks: {}
35
+ Expense Description: {}
36
  """