forked from llmware-ai/llmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent-llmfx-getting-started.py
82 lines (52 loc) · 2.85 KB
/
agent-llmfx-getting-started.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
""" Using SLIM tools as part of an agent workflow - introducing LLMfx class - this example shows how to:
1. Create an agent using the LLMfx class.
2. Load multiple specialized tools for the agent.
3. Execute a series of function-calls.
4. Generate a consolidated automatic dictionary report.
"""
from llmware.models import ModelCatalog
from llmware.agents import LLMfx
def create_multistep_report(customer_transcript):
""" Creating a multi-step, multi-model agent workflow """
# create an agent using LLMfx class
agent = LLMfx()
agent.load_work(customer_transcript)
# load tools individually
agent.load_tool("sentiment")
agent.load_tool("ner")
# load multiple tools
agent.load_tool_list(["emotions", "topics", "intent", "tags", "ratings", "answer"])
# start deploying tools and running various analytics
# first conduct three 'soft skills' initial assessment using 3 different models
agent.sentiment()
agent.emotions()
agent.intent()
# alternative way to execute a tool, passing the tool name as a string
agent.exec_function_call("ratings")
# call multiple tools concurrently
agent.exec_multitool_function_call(["ner","topics","tags"])
# the 'answer' tool is a quantized question-answering model - ask an 'inline' question
# the optional 'key' assigns the output to a dictionary key for easy consolidation
agent.answer("What is a short summary?",key="summary")
# prompting tool to ask a quick question as part of the analytics
response = agent.answer("What is the customer's account number and user name?", key="customer_info")
# you can 'unload_tool' to release it from memory
agent.unload_tool("ner")
agent.unload_tool("topics")
# at end of processing, show the report that was automatically aggregated by key
report = agent.show_report()
# displays a summary of the activity in the process
activity_summary = agent.activity_summary()
# list of the responses gathered
for i, entries in enumerate(agent.response_list):
print("update: response analysis: ", i, entries)
output = {"report": report, "activity_summary": activity_summary, "journal": agent.journal}
return output
if __name__ == "__main__":
# sample customer transcript
customer_transcript = "My name is Michael Jones, and I am a long-time customer. " \
"The Mixco product is not working currently, and it is having a negative impact " \
"on my business, as we can not deliver our products while it is down. " \
"This is the fourth time that I have called. My account number is 93203, and " \
"my user name is mjones. Our company is based in Tampa, Florida."
output = create_multistep_report(customer_transcript)