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: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,6 @@ You can register custom Java functions with the `AzureOpenAiChatModel` and have
6
6
This allows you to connect the LLM capabilities with external tools and APIs.
7
7
The Azure models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature.
8
8
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
-
11
9
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.
12
10
13
11
Spring AI provides flexible and user-friendly ways to register and call custom functions.
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatmodel.adoc
+19-15Lines changed: 19 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,35 +74,39 @@ public class Prompt implements ModelRequest<List<Message>> {
74
74
75
75
==== Message
76
76
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`.
78
78
79
-
[source,java]
80
-
----
81
-
public interface Message extends Node<String> {
79
+
The interface is defined as follows:
82
80
83
-
String getContent();
81
+
```java
82
+
public interface Content {
84
83
85
-
List<Media> getMedia();
84
+
String getContent();
86
85
87
-
MessageType getMessageType();
86
+
Map<String, Object> getMetadata();
88
87
}
89
-
----
90
88
89
+
public interface Message extends Content {
90
+
91
+
MessageType getMessageType();
92
+
}
93
+
```
91
94
92
-
and the Node interface is
95
+
The multimodal message types implement also the `MediaContent` interface providing a list of `Media` content objects.
93
96
94
97
```java
98
+
public interface MediaContent extends Content {
95
99
96
-
public interface Node<T> {
97
-
98
-
T getContent();
100
+
Collection<Media> getMedia();
99
101
100
-
Map<String, Object> getMetadata();
101
102
}
102
103
```
103
104
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`.
106
110
107
111
For instance, OpenAI recognizes message categories for distinct conversational roles such as `system`,`user`, `function` or `assistant`.
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc
+25-41Lines changed: 25 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,55 +44,57 @@ public class Prompt implements ModelRequest<List<Message>> {
44
44
45
45
=== Message
46
46
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`.
49
48
50
-
image::spring-ai-message-api.jpg[Spring AI Message API, width=800, align="center"]
49
+
The interface is defined as follows:
51
50
52
51
```java
52
+
public interface Content {
53
+
54
+
String getContent();
55
+
56
+
Map<String, Object> getMetadata();
57
+
}
58
+
53
59
public interface Message extends Content {
54
60
55
61
MessageType getMessageType();
56
-
57
62
}
58
63
```
59
64
60
-
and the Content interface is
65
+
The multimodal message types implement also the `MediaContent` interface providing a list of `Media` content objects.
61
66
62
67
```java
68
+
public interface MediaContent extends Content {
63
69
64
-
public interface Content {
65
-
66
-
String getContent();
70
+
Collection<Media> getMedia();
67
71
68
-
Map<String, Object> getMetadata();
69
72
}
70
73
```
71
74
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.
74
77
75
-
== Roles
78
+
image::spring-ai-message-api.jpg[Spring AI Message API, width=800, align="center"]
76
79
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.
78
81
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
82
83
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.
86
85
These roles categorize the messages, clarifying the context and purpose of each segment of the prompt for the AI model.
87
86
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.
88
87
89
-
90
88
The primary roles are:
91
89
92
90
* 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.
93
91
* 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.
96
98
97
99
Roles are represented as an enumeration in Spring AI as shown below
98
100
@@ -107,25 +109,7 @@ public enum MessageType {
107
109
108
110
TOOL("tool");
109
111
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);
0 commit comments