Skip to content

Commit be7544c

Browse files
committed
Improve Message docs
1 parent 7dc5f19 commit be7544c

File tree

3 files changed

+44
-58
lines changed

3 files changed

+44
-58
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ You can register custom Java functions with the `AzureOpenAiChatModel` and have
66
This allows you to connect the LLM capabilities with external tools and APIs.
77
The Azure models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature.
88

9-
NOTE: Parallel function calling is only supported with gpt-35-turbo (1106) and gpt-4 (1106-preview) also known as GPT-4 Turbo Preview.
10-
119
The Azure OpenAI API does not call the function directly; instead, the model generates JSON that you can use to call the function in your code and return the result back to the model to complete the conversation.
1210

1311
Spring AI provides flexible and user-friendly ways to register and call custom functions.

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatmodel.adoc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,39 @@ public class Prompt implements ModelRequest<List<Message>> {
7474

7575
==== Message
7676

77-
The `Message` interface encapsulates a textual message, a collection of attributes as a `Map`, and a categorization known as `MessageType`. The interface is defined as follows:
77+
The `Message` interface encapsulates a Prompt textual content and a collection of metadata attributes and a categorization known as `MessageType`.
7878

79-
[source,java]
80-
----
81-
public interface Message extends Node<String> {
79+
The interface is defined as follows:
8280

83-
String getContent();
81+
```java
82+
public interface Content {
8483

85-
List<Media> getMedia();
84+
String getContent();
8685

87-
MessageType getMessageType();
86+
Map<String, Object> getMetadata();
8887
}
89-
----
9088

89+
public interface Message extends Content {
90+
91+
MessageType getMessageType();
92+
}
93+
```
9194

92-
and the Node interface is
95+
The multimodal message types implement also the `MediaContent` interface providing a list of `Media` content objects.
9396

9497
```java
98+
public interface MediaContent extends Content {
9599

96-
public interface Node<T> {
97-
98-
T getContent();
100+
Collection<Media> getMedia();
99101

100-
Map<String, Object> getMetadata();
101102
}
102103
```
103104

104-
The `Message` interface has various implementations that correspond to the categories of messages that an AI model can process.
105-
Some models, like OpenAI's chat completion endpoint, distinguish between message categories based on conversational roles, effectively mapped by the `MessageType`.
105+
The `Message` interface has various implementations that correspond to the categories of messages that an AI model can process:
106+
107+
image::spring-ai-message-api.jpg[Spring AI Message API, width=800, align="center"]
108+
109+
The chat completion endpoint, distinguish between message categories based on conversational roles, effectively mapped by the `MessageType`.
106110

107111
For instance, OpenAI recognizes message categories for distinct conversational roles such as `system`,`user`, `function` or `assistant`.
108112

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,55 +44,57 @@ public class Prompt implements ModelRequest<List<Message>> {
4444

4545
=== Message
4646

47-
The `Message` interface encapsulates a textual message, a collection of attributes as a `Map`, a categorization known as `MessageType`, and a list of media objects for those models that are multimodal.
48-
The interface is defined as follows:
47+
The `Message` interface encapsulates a Prompt textual content and a collection of metadata attributes and a categorization known as `MessageType`.
4948

50-
image::spring-ai-message-api.jpg[Spring AI Message API, width=800, align="center"]
49+
The interface is defined as follows:
5150

5251
```java
52+
public interface Content {
53+
54+
String getContent();
55+
56+
Map<String, Object> getMetadata();
57+
}
58+
5359
public interface Message extends Content {
5460

5561
MessageType getMessageType();
56-
5762
}
5863
```
5964

60-
and the Content interface is
65+
The multimodal message types implement also the `MediaContent` interface providing a list of `Media` content objects.
6166

6267
```java
68+
public interface MediaContent extends Content {
6369

64-
public interface Content {
65-
66-
String getContent();
70+
Collection<Media> getMedia();
6771

68-
Map<String, Object> getMetadata();
6972
}
7073
```
7174

72-
Various implementations of the `Message` interface correspond to different categories of messages that an AI model can process. Some models, like those from OpenAI, distinguish between message categories based on conversational roles. These roles are effectively mapped by the `MessageType`, as discussed below.
73-
75+
Various implementations of the `Message` interface correspond to different categories of messages that an AI model can process.
76+
The Models distinguish between message categories based on conversational roles.
7477

75-
== Roles
78+
image::spring-ai-message-api.jpg[Spring AI Message API, width=800, align="center"]
7679

77-
The evolution of prompts in AI has transitioned from basic, straightforward text to more organized and complex formats with specific roles and structures.
80+
These roles are effectively mapped by the `MessageType`, as discussed below.
7881

79-
Initially, prompts were simple strings – just lines of text.
80-
Over time, this evolved to include specific placeholders within these strings, like “USER:”, which the AI model could recognize and respond to accordingly.
81-
This was a step towards more structured prompts.
82+
==== Roles
8283

83-
OpenAI then introduced an even more organized approach.
84-
In their model, prompts are not merely single strings but a series of messages.
85-
Each message, while still in text form, is assigned a specific role.
84+
Each message is assigned a specific role.
8685
These roles categorize the messages, clarifying the context and purpose of each segment of the prompt for the AI model.
8786
This structured approach enhances the nuance and effectiveness of communication with the AI, as each part of the prompt plays a distinct and defined role in the interaction.
8887

89-
9088
The primary roles are:
9189

9290
* System Role: Guides the AI's behavior and response style, setting parameters or rules for how the AI interprets and replies to the input. It's akin to providing instructions to the AI before initiating a conversation.
9391
* User Role: Represents the user's input – their questions, commands, or statements to the AI. This role is fundamental as it forms the basis of the AI's response.
94-
* Assistant Role: The AI's response to the user's input. More than just an answer or reaction, it's crucial for maintaining the flow of the conversation. By tracking the AI's previous responses (its 'Assistant Role' messages), the system ensures coherent and contextually relevant interactions.
95-
* Function Role: This role deals with specific tasks or operations during the conversation. While the System Role sets the AI's overall behavior, the Function Role focuses on carrying out certain actions or commands the user asks for. It's like a special feature in the AI, used when needed to perform specific functions such as calculations, fetching data, or other tasks beyond just talking. This role allows the AI to offer practical help in addition to conversational responses.
92+
* Assistant Role: The AI's response to the user's input.
93+
More than just an answer or reaction, it's crucial for maintaining the flow of the conversation.
94+
By tracking the AI's previous responses (its 'Assistant Role' messages), the system ensures coherent and contextually relevant interactions.
95+
The Assistant message may contain Function Tool Call request information as well.
96+
It's like a special feature in the AI, used when needed to perform specific functions such as calculations, fetching data, or other tasks beyond just talking.
97+
* Tool/Function Role: The Too/Function Role focuses on returning additional information in response to Tool Call Aisstnat Messages.
9698

9799
Roles are represented as an enumeration in Spring AI as shown below
98100

@@ -107,25 +109,7 @@ public enum MessageType {
107109

108110
TOOL("tool");
109111

110-
private final String value;
111-
112-
MessageType(String value) {
113-
this.value = value;
114-
}
115-
116-
public String getValue() {
117-
return value;
118-
}
119-
120-
public static MessageType fromValue(String value) {
121-
for (MessageType messageType : MessageType.values()) {
122-
if (messageType.getValue().equals(value)) {
123-
return messageType;
124-
}
125-
}
126-
throw new IllegalArgumentException("Invalid MessageType value: " + value);
127-
}
128-
112+
...
129113
}
130114
```
131115

0 commit comments

Comments
 (0)