forked from llmware-ai/llmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document-clustering.py
57 lines (34 loc) · 1.48 KB
/
document-clustering.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""This example demonstrates the use of LLM function calls to perform document clustering and
automated classification of different parts of a document. """
from llmware.parsers import Parser
from llmware.agents import LLMfx
from llmware.setup import Setup
import os
def document_clustering_example ():
samples_fp = Setup().load_sample_files(over_write=True)
agreements_fp = os.path.join(samples_fp, "Agreements")
agreement_files = os.listdir(agreements_fp)
if len(agreement_files) == 0:
print("something went wrong")
return -1
# parsing the first file (could be random) found in the os.listdir in the Agreements sample folder
contract_chunks = Parser().parse_one_pdf(agreements_fp,agreement_files[0])
# create a LLMfx object
agent = LLMfx()
# there are ~65-70 contract_chunks in ~15 page contract - feel free to slice (faster demo), or the whole thing
agent.load_work(contract_chunks[0:5])
agent.load_tool_list(["topics","tags", "ner"])
while True:
agent.exec_multitool_function_call(["topics", "tags","ner"])
if not agent.increment_work_iteration():
break
agent.show_report()
agent.activity_summary()
# uncomment this to see a full view of all of the responses
"""
for i, entries in enumerate(agent.response_list):
print("response_list: ", i, entries)
"""
return agent.response_list
if __name__ == "__main__":
analysis= document_clustering_example()