Spaces:
Build error
Build error
incorporate themes and places
Browse files
planning_ai/chains/map_chain.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from typing import Literal, Optional
|
2 |
|
3 |
from langchain_core.prompts import ChatPromptTemplate
|
@@ -9,6 +10,19 @@ with open("./planning_ai/chains/prompts/map.txt", "r") as f:
|
|
9 |
map_template = f.read()
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
class BriefSummary(BaseModel):
|
13 |
"""A summary of the response with generated metadata"""
|
14 |
|
@@ -16,9 +30,12 @@ class BriefSummary(BaseModel):
|
|
16 |
stance: Literal["SUPPORT", "OPPOSE", "NEUTRAL"] = Field(
|
17 |
..., description="Overall stance of the response."
|
18 |
)
|
19 |
-
themes: list[
|
20 |
..., description="A list of themes associated with the response."
|
21 |
)
|
|
|
|
|
|
|
22 |
rating: int = Field(
|
23 |
...,
|
24 |
description="How constructive the response is, from a rating of 1 to 10.",
|
@@ -30,6 +47,9 @@ class BriefSummary(BaseModel):
|
|
30 |
raise ValueError("Summary cannot be empty.")
|
31 |
return v
|
32 |
|
|
|
|
|
|
|
33 |
|
34 |
SLLM = LLM.with_structured_output(BriefSummary)
|
35 |
|
@@ -45,8 +65,4 @@ if __name__ == "__main__":
|
|
45 |
Papworth Everard has grown beyond recognition. This in itself is a matter of concern.
|
46 |
"""
|
47 |
|
48 |
-
result = map_chain.invoke({"context": test_document})
|
49 |
-
|
50 |
-
print("Generated Summary:")
|
51 |
-
print(result)
|
52 |
-
result
|
|
|
1 |
+
from enum import Enum
|
2 |
from typing import Literal, Optional
|
3 |
|
4 |
from langchain_core.prompts import ChatPromptTemplate
|
|
|
10 |
map_template = f.read()
|
11 |
|
12 |
|
13 |
+
class Theme(str, Enum):
|
14 |
+
climate = "Climate change"
|
15 |
+
biodiversity = "Biodiversity and green spaces"
|
16 |
+
wellbeing = "Wellbeing and social inclusion"
|
17 |
+
great_places = "Great places"
|
18 |
+
jobs = "Jobs"
|
19 |
+
homes = "Homes"
|
20 |
+
infrastructure = "Infrastructure"
|
21 |
+
|
22 |
+
def __repr__(self) -> str:
|
23 |
+
return self.value
|
24 |
+
|
25 |
+
|
26 |
class BriefSummary(BaseModel):
|
27 |
"""A summary of the response with generated metadata"""
|
28 |
|
|
|
30 |
stance: Literal["SUPPORT", "OPPOSE", "NEUTRAL"] = Field(
|
31 |
..., description="Overall stance of the response."
|
32 |
)
|
33 |
+
themes: list[Theme] = Field(
|
34 |
..., description="A list of themes associated with the response."
|
35 |
)
|
36 |
+
places: Optional[list[str]] = Field(
|
37 |
+
..., description="A list of places mentioned in the response."
|
38 |
+
)
|
39 |
rating: int = Field(
|
40 |
...,
|
41 |
description="How constructive the response is, from a rating of 1 to 10.",
|
|
|
47 |
raise ValueError("Summary cannot be empty.")
|
48 |
return v
|
49 |
|
50 |
+
def __str__(self) -> str:
|
51 |
+
return f"{self.summary}\n" f"Related Aims: {self.themes}"
|
52 |
+
|
53 |
|
54 |
SLLM = LLM.with_structured_output(BriefSummary)
|
55 |
|
|
|
65 |
Papworth Everard has grown beyond recognition. This in itself is a matter of concern.
|
66 |
"""
|
67 |
|
68 |
+
result = map_chain.invoke({"context": test_document, "filename": "test"})
|
|
|
|
|
|
|
|
planning_ai/chains/prompts/map.txt
CHANGED
@@ -1,9 +1,19 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
4. **Constructiveness Rating:** Rate how constructive the response is on a scale from 1 to 10, with 1 being unconstructive and 10 being highly constructive.
|
8 |
|
9 |
**Few-shot examples for reference:**
|
@@ -12,12 +22,13 @@ Summarise the following response to a planning application concisely and accurat
|
|
12 |
|
13 |
**Example 1:**
|
14 |
|
15 |
-
Response:
|
16 |
"I am in favour of this new park development as it will provide much-needed green space for families. However, the parking situation needs to be reconsidered."
|
17 |
|
18 |
- **Summary:** The author supports the park development for its benefit to families but expresses concern about parking.
|
19 |
- **Stance:** SUPPORT
|
20 |
-
- **Themes:**
|
|
|
21 |
- **Constructiveness Rating:** 8
|
22 |
|
23 |
---
|
@@ -25,17 +36,18 @@ Response:
|
|
25 |
**Example 2:**
|
26 |
|
27 |
Response:
|
28 |
-
"This development will destroy local wildlife and create traffic chaos. It should not go ahead."
|
29 |
|
30 |
-
- **Summary:** The author opposes the development due to concerns about wildlife and traffic.
|
31 |
- **Stance:** OPPOSE
|
32 |
-
- **Themes:**
|
|
|
33 |
- **Constructiveness Rating:** 3
|
34 |
|
35 |
---
|
36 |
|
37 |
**Now summarise the following response:**
|
38 |
|
39 |
-
Response:
|
40 |
{context}
|
41 |
|
|
|
1 |
+
This is a list of aims proposed the South Cambridgeshire Council:
|
2 |
+
|
3 |
+
- Climate change: Help Greater Cambridge transition to net zero carbon by 2050, by ensuring that development is sited in places that help to limit carbon emissions, is designed to the highest achievable standards for energy and water use, and is resilient to current and future climate risks.
|
4 |
+
- Biodiversity and green spaces: Increase and improve our network of habitats for wildlife, and green spaces for people, ensuring that development leaves the natural environment better than it was before.
|
5 |
+
- Wellbeing and social inclusion: Help people in Greater Cambridge to lead healthier and happier lives, ensuring that everyone benefits from the development of new homes and jobs.
|
6 |
+
- Great places: Sustain the unique character of Cambridge and South Cambridgeshire, and complement it with beautiful and distinctive development, creating a place where people want to live, work and play.
|
7 |
+
- Jobs: Encourage a flourishing and mixed economy in Greater Cambridge which includes a wide range of jobs, while maintaining our area's global reputation for innovation.
|
8 |
+
- Homes: Plan for enough housing to meet our needs, including significant quantities of housing that is affordable to rent and buy, and different kinds of homes to suit our diverse communities.
|
9 |
+
- Infrastructure: Plan for transport, water, energy and digital networks; and health, education and cultural facilities; in the right places and built at the right times to serve our growing communities.
|
10 |
+
|
11 |
+
Summarise the following response to a planning application that was proposed with these aims in mind, following these steps:
|
12 |
+
|
13 |
+
1. **Summary:** Provide a brief, neutral summary that captures the key points of the response with respect to the list of aims proposed by the council.
|
14 |
+
2. **Stance:** Indicate the author’s overall stance as one of the following: 'SUPPORT', 'OPPOSE', or 'NEUTRAL'.
|
15 |
+
3. **Aims:** Identify what aims proposed by the council are discussed.
|
16 |
+
4. **Places:** Identify the places the author has considered for discussion.
|
17 |
4. **Constructiveness Rating:** Rate how constructive the response is on a scale from 1 to 10, with 1 being unconstructive and 10 being highly constructive.
|
18 |
|
19 |
**Few-shot examples for reference:**
|
|
|
22 |
|
23 |
**Example 1:**
|
24 |
|
25 |
+
Response:
|
26 |
"I am in favour of this new park development as it will provide much-needed green space for families. However, the parking situation needs to be reconsidered."
|
27 |
|
28 |
- **Summary:** The author supports the park development for its benefit to families but expresses concern about parking.
|
29 |
- **Stance:** SUPPORT
|
30 |
+
- **Themes:** Biodiversity and green spaces, Infrastructure
|
31 |
+
- **Places:** None
|
32 |
- **Constructiveness Rating:** 8
|
33 |
|
34 |
---
|
|
|
36 |
**Example 2:**
|
37 |
|
38 |
Response:
|
39 |
+
"This development in Cambridge will destroy local wildlife and create traffic chaos. It should not go ahead."
|
40 |
|
41 |
+
- **Summary:** The author opposes the development due to concerns about wildlife and traffic congestion.
|
42 |
- **Stance:** OPPOSE
|
43 |
+
- **Themes:** Biodiversity and green spaces, Infrastructure
|
44 |
+
- **Places:** Cambridge
|
45 |
- **Constructiveness Rating:** 3
|
46 |
|
47 |
---
|
48 |
|
49 |
**Now summarise the following response:**
|
50 |
|
51 |
+
Response:
|
52 |
{context}
|
53 |
|