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
Copy file name to clipboardExpand all lines: documentation/modules/ROOT/pages/19_agents_tools.adoc
+24-14Lines changed: 24 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,15 @@
4
4
5
5
The real deal to bring AI for your development process is when you can create a real interaction between services you build and/or use with the LLM.
6
6
7
-
This section will use AI to trigger an email service from our local application.
7
+
This section will use AI to trigger an email service from our local application. To do this, we'll use LangChain4j's concept of Agents and Tools.
8
8
9
+
Agents operate by utilizing a language model to decipher a series of actions, unlike chains where actions are pre-programmed. Ie. agents leverage a language model as a cognitive engine to decide on the actions (tools) and their order.
9
10
10
-
IMPORTANT: We keep assuming that you'll be working inside the project folder that was created before. In this case, `{project-ai-name}`.
11
+
You can read more about this concept in the https://docs.quarkiverse.io/quarkus-langchain4j/dev/agent-and-tools.html[Quarkus LangChain4j Documentation]
11
12
12
13
== Add the Mailer and Mailpit extensions
13
14
14
-
Just open a new terminal window, and make sure you’re at the root of your `{project-ai-name}` project, then run:
15
+
Open a new terminal window, and make sure you’re at the root of your `{project-ai-name}` project, then run:
15
16
16
17
[tabs]
17
18
====
@@ -64,7 +65,9 @@ public class EmailService {
64
65
@Tool("send the given content by email")
65
66
public void sendAnEmail(String content) {
66
67
Log.info("Sending an email: " + content);
67
-
mailer.send(Mail.withText("sendMeALetter@quarkus.io", "A poem for you", content).setFrom("origin@quarkus.io"));
68
+
mailer.send(Mail
69
+
.withText("sendMeALetter@quarkus.io", "A poem for you", content)
70
+
.setFrom("origin@quarkus.io"));
68
71
}
69
72
70
73
}
@@ -73,7 +76,11 @@ public class EmailService {
73
76
74
77
== Create the AI service with prompt context
75
78
76
-
Let's create an interface for our AI service, but with `SystemMessage` and `UserMessage` this time.
79
+
Let's create an interface for our AI service, but with `SystemMessage` and `UserMessage` this time.
80
+
`SystemMessage` gives context to the AI Model.
81
+
In this case we tell it that it should craft a message as if it is written by a professional poet.
82
+
The `UserMessage` is the actual instruction/question we're sending to the AI model. As you can see in the example below,
83
+
you can format and parametrize the UserMessage, translating structured content to text and vice-versa.
77
84
78
85
Create a new `AssistantWithContext` Java interface in `src/main/java` in the `com.redhat.developers` package with the following contents:
79
86
@@ -107,7 +114,7 @@ Note that this assistant references the email service as a tool.
107
114
108
115
== Create a email sending resource
109
116
110
-
Now we create a resource that builds the whole interaction.
117
+
Now we create a resource that builds the interaction and calls the service with the required parameters (topic & lines).
111
118
112
119
Create a new `EmailMeAPoemResource` Java class in `src/main/java` in the `com.redhat.developers` package with the following contents:
113
120
@@ -138,24 +145,27 @@ public class EmailMeAPoemResource {
138
145
139
146
== Adding email service properties to your configuration
140
147
141
-
Add the following properties to your `application.properties` so that it looks like:
148
+
Update the following properties in your `application.properties`
149
+
150
+
IMPORTANT: The LangChain4j `demo` key currently does not support tools, so you will need to use a real OpenAI key for the email service to be called by the OpenAI model.
151
+
You can create an account over at https://platform.openai.com/[OpenAI] if you'd like to see this in action.
152
+
153
+
NOTE: If you do not want to create an OpenAI key, you can still test the below scenario, it just won't send an email.
By setting those properties Quarkus will use DevServices to instantiate a local email service for you (development time only).
168
+
Because we haven't configured the local email service, Quarkus will use DevServices to instantiate and configure a local email service for you (in Dev Mode only!).
159
169
160
170
You can check it running:
161
171
@@ -197,12 +207,12 @@ An example of output (it can vary on each prompt execution):
197
207
I have composed a poem about Quarkus. I have sent it to you via email. Let me know if you need anything else
198
208
----
199
209
200
-
More than see this on your terminal, you can check the "real" email.
210
+
If you have a valid OpenAI key configured, you can check the "real" email:
201
211
202
-
First, open the DevUI and click on the Mailpit arrow.
212
+
First, open the http://localhost:8080/q/dev-ui[DevUI, window=_blank] and click on the Mailpit arrow.
0 commit comments