You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most applications will need to perform some logic that allows you to control the workflow of your Agente with good old if/else statements. For example, given a question in plain English, you want to do something different, like checking if the email sounds urgent or not:
30
+
Most applications will need to perform some logic that allows you to control the workflow of your Agent with good old if/else statements. For example, given a question in plain English, you want to do something different, like checking if the email sounds urgent or not:
31
31
32
32
```python
33
-
34
-
llm.set_context(email=email)
35
-
36
-
if llm.true_or_false('is this email urgent?'):
33
+
if llm.is_true('is this email urgent?', email=email):
37
34
-- do something
38
35
else:
39
36
-- do something else
40
-
41
37
```
42
38
43
39
### Workflow: Routing
@@ -47,26 +43,21 @@ Similar to if/else statements, but for when your LLM needs to be more dramatic w
47
43
48
44
*For example*, let's say we want to classify a message into different categories:
49
45
50
-
```python
51
-
46
+
```python
52
47
options = {
53
48
'meeting': 'this is a meeting request',
54
49
'spam': 'people trying to sell you stuff you dont want',
55
50
'other': 'this is sounds like something else'
56
-
}
57
-
58
-
llm.set_context(email=email)
51
+
}
59
52
60
-
match llm.get_key(options):
53
+
match llm.classify(options, email=email):
61
54
case'meeting':
62
-
# you can add more context whenever you want
63
-
llm.add_context(meeting=True)
55
+
-- do something
64
56
case'spam':
65
-
llm.add_context(spam=True)
57
+
-- do something
66
58
case'other':
67
59
-- do something
68
60
69
-
70
61
```
71
62
72
63
## Agents
@@ -90,10 +81,7 @@ class EmailSummary(BaseModel):
90
81
label: str
91
82
92
83
93
-
llm.set_context(email=email)
94
-
95
-
ret = llm.generate_object(EmailSummary)
96
-
84
+
ret = llm.generate_object(EmailSummary, email=email)
97
85
```
98
86
99
87
@@ -114,33 +102,32 @@ class ActionItem(BaseModel):
114
102
115
103
object_schema = List[ActionItem]
116
104
117
-
llm.set_context(email=email)
118
-
105
+
# lets pass the context to the LLM once, so we don't have to pass it every time
106
+
llm.set_context(email=email, today= date.today())
119
107
if llm.true_or_false('are there action items in this email?'):
120
108
for action_item in llm.generate_object(object_schema):
121
109
-- do something
110
+
111
+
llm.clear_context()
122
112
```
123
113
124
114
### Function Calling
125
115
126
116
And of course, we want to be able to call functions. But you want the llm to figure out the arguments for you.
127
117
128
118
*For example*, let's say we want to call a function that sends a calendar invite to a meeting, we want the llm to figure out the arguments for the function given some information:
129
-
```python
130
-
131
119
120
+
```python
132
121
defsend_calendar_invite(
133
122
subject=str,
134
123
time=str,
135
124
location=str,
136
125
attendees= List[str]):
137
126
-- send a calendar invite to the meeting
138
127
139
-
llm.set_context(email=email)
140
-
141
-
if llm.true_or_false('is this an email requesting for a meeting?'):
142
-
ret = llm.call_function(send_calendar_invite)
143
128
129
+
if llm.true_or_false('is this an email requesting for a meeting?', email=email):
130
+
ret = llm.call_function(send_calendar_invite, email=email, today= date.today())
144
131
```
145
132
146
133
### Function picking
@@ -150,7 +137,6 @@ Sometimes you want to pick a function from a list of functions. You can do that
150
137
*For example*, let's say we want to pick a function from a list of functions:
Sometimes you just want a simple string response from the LLM. You can use the `get_string` method for this, I know! boring AF but it may come in handy:
190
170
191
171
```python
192
-
193
-
llm.set_context(email=email)
194
-
195
-
ret = llm.get_string('what is the subject of the email?')
196
-
172
+
ret = llm.get_string('what is the subject of the email?', email=email)
197
173
```
198
174
199
175
### Streaming Response
200
176
201
177
Sometimes you want to stream the response from the LLM. You can use the `get_stream` method for this:
202
178
203
179
```python
204
-
205
-
llm.set_context(email=email)
206
-
207
-
for chunk in llm.get_stream('what is the subject of the email?'):
180
+
for chunk in llm.get_stream('what is the subject of the email?', email=email):
0 commit comments