Skip to content

Commit 04d9683

Browse files
Jay Bryantmarkpollack
authored andcommitted
Editing pass for clarity, grammar, spelling, punctuation, and usage.
Also added several anchors and links.
1 parent 78f6c8c commit 04d9683

File tree

7 files changed

+195
-194
lines changed

7 files changed

+195
-194
lines changed

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

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1+
[[AiClient]]
12
= AiClient
23

3-
== Overview
4-
5-
The AiClient interface streamlines interactions with xref:concepts.adoc#_models[AI Models].
6-
It simplifies connecting to various AI Models — each with potentially unique APIs — by offering a uniform interface for interaction.
4+
The `AiClient` interface streamlines interactions with xref:concepts.adoc#_models[AI Models].
5+
It simplifies connecting to various AI Models -— each with potentially unique APIs -— by offering a uniform interface for interaction.
76

87
Currently, the interface supports only text-based input and output.
9-
You should expect some of the classes and interfaces to change as we support for other input and output types is implemented.
8+
You should expect some of the classes and interfaces to change as we add other input and output types.
109

11-
The design of the AiClient interface centers around two primary goals:
10+
The design of the `AiClient` interface centers around two primary goals:
1211

13-
1. *Portability*: It allows easy integration with different AI Models, allowing developers to switch between differing AI models with minimal code changes.
12+
* *Portability*: It allows easy integration with different AI Models, letting developers switch between differing AI models with minimal code changes.
1413
This design aligns with Spring's philosophy of modularity and interchangeability.
1514

16-
17-
2. *Simplicity*: Using companion classes like `Prompt` for input encapsulation and `AiResponse` for output handling, the `AiClient` interface simplifies communication with AI Models. It manages the complexity of request preparation and response parsing, offering a direct and simplified API interaction.
15+
* *Simplicity*: By using companion classes like `Prompt` for input encapsulation and `AiResponse` for output handling, the `AiClient` interface simplifies communication with AI Models. It manages the complexity of request preparation and response parsing, offering a direct and simplified API interaction.
1816

1917
== API Overview
2018

@@ -36,13 +34,11 @@ public interface AiClient {
3634

3735
The `generate` method with a `String` parameter simplifies initial use, avoiding the complexities of the more sophisticated `Prompt` and `AiResponse` classes.
3836

39-
4037
=== Prompt
41-
In a real-world application, it will be most common to use the generate method, taking a `Prompt` instance and returning an `AiResponse`.
38+
In a real-world application, it is most common to use the `generate` method, taking a `Prompt` instance and returning an `AiResponse`.
4239

4340
The `Prompt` class encapsulates a list of `Message` objects.
44-
Below is a truncated version of the Prompt class, excluding constructors and other utility methods:
45-
41+
The following listing shows a truncated version of the Prompt class, excluding constructors and other utility methods:
4642

4743
```java
4844
public class Prompt {
@@ -57,7 +53,6 @@ public class Prompt {
5753

5854
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:
5955

60-
6156
```java
6257
public interface Message {
6358

@@ -70,15 +65,14 @@ public interface Message {
7065
}
7166
```
7267

73-
The Message interface has various implementations corresponding to the categories of messages that an AI model can process.
68+
The `Message` interface has various implementations that correspond to the categories of messages that an AI model can process.
7469
Some models, like OpenAI's chat completion endpoint, distinguish between message categories based on conversational roles, effectively mapped by the `MessageType`.
7570

76-
77-
For instance, OpenAI recognizes message categories for distinct conversational roles such as "system", "user", or "assistant".
78-
While the term MessageType might imply a specific message format, in this context, it effectively designates the role a message plays in the dialogue.
71+
For instance, OpenAI recognizes message categories for distinct conversational roles such as "`system,`" "`user,`" or "`assistant.`"
72+
While the term, `MessageType`, might imply a specific message format, in this context, it effectively designates the role a message plays in the dialogue.
7973

8074
For AI models that do not use specific roles, the `UserMessage` implementation acts as a standard category, typically representing user-generated inquiries or instructions.
81-
To understand the practical application and the relationship between Prompt and Message, especially in the context of these roles or message categories, please refer to the detailed explanations in the Prompts section.
75+
To understand the practical application and the relationship between `Prompt` and `Message`, especially in the context of these roles or message categories, see the detailed explanations in the <<Prompts>> section.
8276

8377
=== AiResponse
8478

@@ -95,11 +89,11 @@ public class AiResponse {
9589

9690
The `AiResponse` class holds the AI Model's output, with each `Generation` instance containing one of potentially multiple outputs from a single prompt.
9791

98-
The `AiResponse` class additionally carries a map of key-value pairs providing metadata about the AI Model's response. This feature is still in progress and is not elaborated on in this document.
92+
The `AiResponse` class also carries a map of key-value pairs providing metadata about the AI Model's response. This feature is still in progress and is not elaborated on in this document.
9993

10094
=== Generation
10195

102-
Finally, the `Generation` class contains a String representing the output text and a map that provides metadata about this response.
96+
Finally, the `Generation` class contains a `String` that represents the output text and a map that provides metadata about this response:
10397

10498

10599
```java
@@ -114,30 +108,38 @@ public class Generation {
114108

115109
== Available Implementations
116110

117-
These are the available implementations of the `AiClient` interface
111+
The `AiClient` interface has the following available implementations:
118112

119-
* OpenAI - Using the https://github.com/TheoKanning/openai-java[Theo Kanning client library].
120-
* Azure OpenAI - Using https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Microsoft's OpenAI client library].
121-
* Hugging Face - Using the https://huggingface.co/inference-endpoints[Hugging Face Hosted Inference Service]. This gives you access to hundreds of models.
122-
* https://ollama.ai/[Ollama] - Run large language models, locally.
113+
* OpenAI: Using the https://github.com/TheoKanning/openai-java[Theo Kanning client library].
114+
* Azure OpenAI: Using https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Microsoft's OpenAI client library].
115+
* Hugging Face: Using the https://huggingface.co/inference-endpoints[Hugging Face Hosted Inference Service]. This gives you access to hundreds of models.
116+
* https://ollama.ai/[Ollama]: Run large language models locally.
123117

124118
Planned implementations
125-
* Amazon Bedrock - This can provide access to many AI models.
126-
* Google Vertex - Providing access to 'Bard', aka Palm2
119+
* Amazon Bedrock: This can provide access to many AI models.
120+
* Google Vertex: Providing access to 'Bard' (AKA Palm2).
127121

128-
Others are welcome, the list is not at all closed.
122+
Others are welcome. The list is not at all closed.
129123

130124
== OpenAI-Compatible Models
131125

132126
A variety of models compatible with the OpenAI API are available, including those that can be operated locally, such as [LocalAI](https://github.com/mudler/LocalAI). The standard configuration for connecting to the OpenAI API is through the `spring.ai.openai.baseUrl` property, which defaults to `https://api.openai.com`.
133127

134-
To link the OpenAI client to a compatible model that utilizes the OpenAI API, you should adjust the `spring.ai.openai.baseUrl` property to the corresponding URL of the model you wish to connect to.
128+
To link the OpenAI client to a compatible model that uses the OpenAI API, you should adjust the `spring.ai.openai.baseUrl` property to the corresponding URL of the model you wish to connect to.
135129

136130
== Configuration
137131

132+
This section describes how to configure models, including:
133+
134+
* <<openai-api,OpenAI>>
135+
* <<azure-openai-api,Azure OpenAI>>
136+
* <<hugging-face-api,Hugging Face>>
137+
* <<ollama-api,Ollama>>
138+
139+
[[openan-api]]
138140
=== OpenAI
139141

140-
Add the Spring Boot starter to you project's dependencies
142+
Add the Spring Boot starter to you project's dependencies:
141143

142144
[source, xml]
143145
----
@@ -148,7 +150,7 @@ Add the Spring Boot starter to you project's dependencies
148150
</dependency>
149151
----
150152

151-
This will make an instance of the `AiClient` that is backed by the https://github.com/TheoKanning/openai-java[Theo Kanning client library] available for injection in your application classes.
153+
This makes an instance of the `AiClient` that is backed by the https://github.com/TheoKanning/openai-java[Theo Kanning client library] available for injection in your application classes.
152154

153155
The Spring AI project defines a configuration property named `spring.ai.openai.api-key` that you should set to the value of the `API Key` obtained from `openai.com`.
154156

@@ -159,12 +161,13 @@ Exporting an environment variable is one way to set that configuration property.
159161
export SPRING_AI_OPENAI_API_KEY=<INSERT KEY HERE>
160162
----
161163

164+
[[azure-openai-api]]
162165
=== Azure OpenAI
163166

164-
This will make an instance of the `AiClient` that is backed by the https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Microsoft's OpenAI client library] available for injection in your application classes.
167+
This makes an instance of the `AiClient` that is backed by https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Microsoft's OpenAI client library] available for injection in your application classes.
165168

166169
The Spring AI project defines a configuration property named `spring.ai.azure.openai.api-key` that you should set to the value of the `API Key` obtained from Azure.
167-
There is also a configuraiton property named `spring.ai.azure.openai.endpoint` that you should set to the endpoint URL obtained when provisioning your model in Azure.
170+
There is also a configuration property named `spring.ai.azure.openai.endpoint` that you should set to the endpoint URL obtained when provisioning your model in Azure.
168171

169172
Exporting environment variables is one way to set these configuration properties.
170173

@@ -174,9 +177,10 @@ export SPRING_AI_AZURE_OPENAI_API_KEY=<INSERT KEY HERE>
174177
export SPRING_AI_AZURE_OPENAI_ENDPOINT=<INSERT ENDPOINT URL HERE>
175178
----
176179

180+
[[hugging-face-api]]
177181
=== Hugging Face
178182

179-
There is not yet a Spring Boot Starter for this client implementation, so you should add the dependency to the HuggingFace client implementation to your project's dependencies.
183+
There is not yet a Spring Boot Starter for this client implementation, so you should add the dependency to the HuggingFace client implementation to your project's dependencies and export an environment variable:
180184

181185
[source, xml]
182186
----
@@ -192,11 +196,12 @@ There is not yet a Spring Boot Starter for this client implementation, so you sh
192196
export HUGGINGFACE_API_KEY=your_api_key_here
193197
----
194198

195-
Obtain the endpoint URL of the Inference Endpoint. You can find this on the Inference Endpoint's UI https://ui.endpoints.huggingface.co/[here].
199+
Obtain the endpoint URL of the inference endpoint. You can find this on the Inference Endpoint's UI https://ui.endpoints.huggingface.co/[here].
196200

201+
[[ollama-api]]
197202
=== Ollama
198203

199-
There is not yet a Spring Boot Starter for this client implementation, so you should add the dependency to the Ollama client implementation to your project's dependencies.
204+
There is not yet a Spring Boot Starter for this client implementation, so you should add the dependency to the Ollama client implementation to your project's dependencies:
200205

201206
[source, xml]
202207
----
@@ -209,7 +214,7 @@ There is not yet a Spring Boot Starter for this client implementation, so you sh
209214

210215
== Example Usage
211216

212-
A simple hello world example is shown below that uses the `AiClient's generate method that takes a `String` as input and returns a `String` as output.
217+
The following listing shows a simple "Hello, world" example. It uses the `AiClient.generate` method that takes a `String` as input and returns a `String` as output:
213218

214219
[source,java]
215220
----

0 commit comments

Comments
 (0)