Spaces:
Running
Running
version bump and minor bugfixes
Browse files- agent.py +44 -16
- requirements.txt +1 -1
agent.py
CHANGED
@@ -21,35 +21,43 @@ citation_description = '''
|
|
21 |
Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
|
22 |
'''
|
23 |
|
24 |
-
def extract_components_from_citation(citation: str) ->
|
25 |
citation_components = citation.split(' ')
|
26 |
volume_num = citation_components[0]
|
27 |
reporter = '-'.join(citation_components[1:-1]).replace('.', '').lower()
|
28 |
first_page = citation_components[-1]
|
29 |
|
30 |
if not volume_num.isdigit():
|
31 |
-
|
32 |
if not first_page.isdigit():
|
33 |
-
|
34 |
|
35 |
-
return int(volume_num), reporter, int(first_page)
|
36 |
|
37 |
def create_assistant_tools(cfg):
|
38 |
|
39 |
def get_opinion_text(
|
40 |
-
case_citation = Field(description = citation_description),
|
41 |
-
summarize:
|
42 |
) -> str:
|
43 |
"""
|
44 |
-
|
45 |
-
if summarize is True, the text is summarized.
|
46 |
If there is more than one opinion for the case, the type of each opinion is returned with the text,
|
47 |
and the opinions (or their summaries) are separated by semicolons (;)
|
|
|
|
|
|
|
|
|
48 |
"""
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
50 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
51 |
if response.status_code != 200:
|
52 |
-
return "Case not found; please check the citation."
|
53 |
res = json.loads(response.text)
|
54 |
|
55 |
if len(res["casebody"]["opinions"]) == 1:
|
@@ -69,10 +77,15 @@ def create_assistant_tools(cfg):
|
|
69 |
"""
|
70 |
Given a case citation, returns a valid web url to a pdf of the case record
|
71 |
"""
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
73 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
74 |
if response.status_code != 200:
|
75 |
-
return "Case not found; please check the citation."
|
76 |
res = json.loads(response.text)
|
77 |
page_number = res["first_page_order"]
|
78 |
return f"https://static.case.law/{reporter}/{volume_num}.pdf#page={page_number}"
|
@@ -83,7 +96,12 @@ def create_assistant_tools(cfg):
|
|
83 |
"""
|
84 |
Given a case citation, returns a valid web url to a page with information about the case.
|
85 |
"""
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
87 |
url = f"https://case.law/caselaw/?reporter={reporter}&volume={volume_num}&case={first_page:04d}-01"
|
88 |
response = requests.get(url)
|
89 |
if response.status_code != 200:
|
@@ -96,7 +114,12 @@ def create_assistant_tools(cfg):
|
|
96 |
"""
|
97 |
Given a case citation, returns its name and name abbreviation.
|
98 |
"""
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
100 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
101 |
if response.status_code != 200:
|
102 |
return "Case not found", "Case not found"
|
@@ -110,7 +133,12 @@ def create_assistant_tools(cfg):
|
|
110 |
Given a case citation, returns a list of cases that are cited by the opinion of this case.
|
111 |
The output is a list of cases, each a dict with the citation, name and name_abbreviation of the case.
|
112 |
"""
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
114 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
115 |
if response.status_code != 200:
|
116 |
return "Case not found; please check the citation."
|
@@ -159,7 +187,7 @@ def create_assistant_tools(cfg):
|
|
159 |
reranker = "multilingual_reranker_v1", rerank_k = 100,
|
160 |
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
161 |
summary_num_results = 10,
|
162 |
-
vectara_summarizer = 'vectara-summary-ext-
|
163 |
include_citations = False,
|
164 |
)
|
165 |
|
|
|
21 |
Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
|
22 |
'''
|
23 |
|
24 |
+
def extract_components_from_citation(citation: str) -> dict:
|
25 |
citation_components = citation.split(' ')
|
26 |
volume_num = citation_components[0]
|
27 |
reporter = '-'.join(citation_components[1:-1]).replace('.', '').lower()
|
28 |
first_page = citation_components[-1]
|
29 |
|
30 |
if not volume_num.isdigit():
|
31 |
+
return {}
|
32 |
if not first_page.isdigit():
|
33 |
+
return {}
|
34 |
|
35 |
+
return {'volume': int(volume_num), 'reporter': reporter, 'first_page': int(first_page)}
|
36 |
|
37 |
def create_assistant_tools(cfg):
|
38 |
|
39 |
def get_opinion_text(
|
40 |
+
case_citation: str = Field(description = citation_description),
|
41 |
+
summarize: bool = Field(default=True, description="if True returns case summary, otherwise the full text of the case")
|
42 |
) -> str:
|
43 |
"""
|
44 |
+
Returns the full opinion/ruling text of the case, or the summary if summarize=True.
|
|
|
45 |
If there is more than one opinion for the case, the type of each opinion is returned with the text,
|
46 |
and the opinions (or their summaries) are separated by semicolons (;)
|
47 |
+
|
48 |
+
Args
|
49 |
+
case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
|
50 |
+
summarize (bool): True to return just a summary of the case, False to return full case text.
|
51 |
"""
|
52 |
+
citation_dict = extract_components_from_citation(case_citation)
|
53 |
+
if not citation_dict:
|
54 |
+
return f"Citation is invalid: {case_citation}."
|
55 |
+
reporter = citation_dict['reporter']
|
56 |
+
volume_num = citation_dict['volume']
|
57 |
+
first_page = citation_dict['first_page']
|
58 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
59 |
if response.status_code != 200:
|
60 |
+
return f"Case not found; please check the citation {case_citation}."
|
61 |
res = json.loads(response.text)
|
62 |
|
63 |
if len(res["casebody"]["opinions"]) == 1:
|
|
|
77 |
"""
|
78 |
Given a case citation, returns a valid web url to a pdf of the case record
|
79 |
"""
|
80 |
+
citation_dict = extract_components_from_citation(case_citation)
|
81 |
+
if not citation_dict:
|
82 |
+
return f"Citation is invalid: {case_citation}."
|
83 |
+
reporter = citation_dict['reporter']
|
84 |
+
volume_num = citation_dict['volume']
|
85 |
+
first_page = citation_dict['first_page']
|
86 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
87 |
if response.status_code != 200:
|
88 |
+
return f"Case not found; please check the citation {case_citation}."
|
89 |
res = json.loads(response.text)
|
90 |
page_number = res["first_page_order"]
|
91 |
return f"https://static.case.law/{reporter}/{volume_num}.pdf#page={page_number}"
|
|
|
96 |
"""
|
97 |
Given a case citation, returns a valid web url to a page with information about the case.
|
98 |
"""
|
99 |
+
citation_dict = extract_components_from_citation(case_citation)
|
100 |
+
if not citation_dict:
|
101 |
+
return f"Citation is invalid: {case_citation}."
|
102 |
+
reporter = citation_dict['reporter']
|
103 |
+
volume_num = citation_dict['volume']
|
104 |
+
first_page = citation_dict['first_page']
|
105 |
url = f"https://case.law/caselaw/?reporter={reporter}&volume={volume_num}&case={first_page:04d}-01"
|
106 |
response = requests.get(url)
|
107 |
if response.status_code != 200:
|
|
|
114 |
"""
|
115 |
Given a case citation, returns its name and name abbreviation.
|
116 |
"""
|
117 |
+
citation_dict = extract_components_from_citation(case_citation)
|
118 |
+
if not citation_dict:
|
119 |
+
return f"Citation is invalid: {case_citation}.", f"Citation is invalid: {case_citation}."
|
120 |
+
reporter = citation_dict['reporter']
|
121 |
+
volume_num = citation_dict['volume']
|
122 |
+
first_page = citation_dict['first_page']
|
123 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
124 |
if response.status_code != 200:
|
125 |
return "Case not found", "Case not found"
|
|
|
133 |
Given a case citation, returns a list of cases that are cited by the opinion of this case.
|
134 |
The output is a list of cases, each a dict with the citation, name and name_abbreviation of the case.
|
135 |
"""
|
136 |
+
citation_dict = extract_components_from_citation(case_citation)
|
137 |
+
if not citation_dict:
|
138 |
+
return [f"Citation is invalid: {case_citation}."]
|
139 |
+
reporter = citation_dict['reporter']
|
140 |
+
volume_num = citation_dict['volume']
|
141 |
+
first_page = citation_dict['first_page']
|
142 |
response = requests.get(f"https://static.case.law/{reporter}/{volume_num}/cases/{first_page:04d}-01.json")
|
143 |
if response.status_code != 200:
|
144 |
return "Case not found; please check the citation."
|
|
|
187 |
reranker = "multilingual_reranker_v1", rerank_k = 100,
|
188 |
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
189 |
summary_num_results = 10,
|
190 |
+
vectara_summarizer = 'vectara-experimental-summary-ext-2023-12-11-med-omni',
|
191 |
include_citations = False,
|
192 |
)
|
193 |
|
requirements.txt
CHANGED
@@ -6,4 +6,4 @@ streamlit-feedback==0.1.3
|
|
6 |
uuid==1.30
|
7 |
langdetect==1.0.9
|
8 |
langcodes==3.4.0
|
9 |
-
vectara-agentic==0.1.
|
|
|
6 |
uuid==1.30
|
7 |
langdetect==1.0.9
|
8 |
langcodes==3.4.0
|
9 |
+
vectara-agentic==0.1.15
|