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
This commit introduces a new overloaded method prompt(String content)
to the ChatClient API. It provides a convenient way to create prompts
using only a string of user content, simplifying the process for basic
chat interactions.
Fixesgh-1286
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
The `ChatClient` fluent API allows you to create a prompt in three distinct ways using an overloaded `prompt` method to initiate the fluent API.
70
+
71
+
* `prompt()`: This method with no arguments is the most flexible, allowing you to build up user, system, and other parts of the prompt using the fluent API.
72
+
73
+
* `prompt(Prompt prompt)`: This method accepts a `Prompt` argument, letting you pass in a `Prompt` instance that you have created using the Prompt's non-fluent APIs. The prompt passed to the model is 'sealed', meaning you can't modify it using fluent API methods.
74
+
75
+
* `prompt(String content)`: This is a convenience method similar to the previous overload. It takes the user's text content and creates a `Prompt` instance internally via `new Prompt(content)`.
76
+
77
+
67
78
== ChatClient Responses
68
79
69
-
The `ChatClient` API offers several ways to format the response from the AI Model.
80
+
The `ChatClient` API offers several ways to format the response from the AI Model using the fluent API.
You often want to return an entity class that is mapped from the returned `String`.
@@ -318,6 +330,39 @@ This contextual data can be of different types. Common types include:
318
330
319
331
* **Conversational history**: The chat model's API is stateless. If you tell the AI model your name, it won't remember it in subsequent interactions. Conversational history must be sent with each request to ensure previous interactions are considered when generating a response.
320
332
333
+
334
+
=== Advisor Configuration in ChatClient
335
+
336
+
The ChatClient fluent API provides an `AdvisorSpec` interface for configuring advisors. This interface offers methods to add parameters, set multiple parameters at once, and add one or more advisors to the chain.
337
+
338
+
[source,java]
339
+
----
340
+
interface AdvisorSpec {
341
+
AdvisorSpec param(String k, Object v);
342
+
AdvisorSpec params(Map<String, Object> p);
343
+
AdvisorSpec advisors(Advisor... advisors);
344
+
AdvisorSpec advisors(List<Advisor> advisors);
345
+
}
346
+
----
347
+
348
+
IMPORTANT: The order in which advisors are added to the chain is crucial, as it determines the sequence of their execution. Each advisor modifies the prompt or the context in some way, and the changes made by one advisor are passed on to the next in the chain.
349
+
350
+
[source,java]
351
+
----
352
+
ChatClient.builder(chatModel)
353
+
.build()
354
+
.prompt()
355
+
.advisors(
356
+
new ChatMemoryAdvisor(chatMemory),
357
+
new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults())
358
+
)
359
+
.user(userText)
360
+
.call();
361
+
----
362
+
363
+
In this configuration, the `ChatMemoryAdvisor` will be executed first, adding the conversation history to the prompt. Then, the `QuestionAnswerAdvisor` will perform its search based on the user's question and the added conversation history, potentially providing more relevant results.
364
+
365
+
321
366
=== Retrieval Augmented Generation
322
367
323
368
A vector database stores data that the AI model is unaware of.
@@ -427,6 +472,8 @@ public class CustomerSupportAssistant {
427
472
}
428
473
----
429
474
475
+
476
+
430
477
=== Logging
431
478
432
479
The `SimpleLoggerAdvisor` is an advisor that logs the `request` and `response` data of the `ChatClient`.
0 commit comments