Rename AiReponse to ChatResponse in Documents (#255)
This commit is contained in:
@@ -7,7 +7,7 @@ Your rate limits are directly determined by your plan when you signed up with yo
|
||||
|
||||
To help garner insight into your AI (model) consumption and general usage, Spring AI provides an API to introspect the metadata that is returned by AI providers in their APIs.
|
||||
|
||||
Spring AI defines 3 primary interfaces to examine these metrics: `GenerationMetadata`, `RateLimit` and `Usage`. All of these interface can be accessed programmatically from the `AiResponse` returned and initiated by an AI request.
|
||||
Spring AI defines 3 primary interfaces to examine these metrics: `GenerationMetadata`, `RateLimit` and `Usage`. All of these interface can be accessed programmatically from the `ChatResponse` returned and initiated by an AI request.
|
||||
|
||||
[[AiMetadata-GenerationMetadata]]
|
||||
== `GenerationMetadata` interface
|
||||
@@ -30,9 +30,9 @@ interface GenerationMetadata {
|
||||
}
|
||||
----
|
||||
|
||||
An instance of `GenerationMetadata` is automatically created by Spring AI when an AI request is made through the AI provider's API and an AI response is returned. You can get access to the AI provider metadata from the `AiResponse` using:
|
||||
An instance of `GenerationMetadata` is automatically created by Spring AI when an AI request is made through the AI provider's API and an AI response is returned. You can get access to the AI provider metadata from the `ChatResponse` using:
|
||||
|
||||
.Get access to `GenerationMetadata` from `AiResponse`
|
||||
.Get access to `GenerationMetadata` from `ChatResponse`
|
||||
[source,java]
|
||||
----
|
||||
@Service
|
||||
@@ -42,13 +42,13 @@ class MyService {
|
||||
|
||||
Prompt prompt = createPrompt(request);
|
||||
|
||||
AiResponse response = aiClient.generate(prompt)
|
||||
ChatResponse response = chatClient.generate(prompt);
|
||||
|
||||
// Process the AI response
|
||||
// Process the chat response
|
||||
|
||||
GenerationMetadata metadata = response.getMetadata();
|
||||
|
||||
// Inspect the AI metadata returned in the AI response of the AI providers API
|
||||
// Inspect the AI metadata returned in the chat response of the AI providers API
|
||||
|
||||
Long totalTokensUsedInAiPromptAndResponse = metadata.getUsage().getTotalTokens();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ The design of the `ChatClient` interface centers around two primary goals:
|
||||
* *Portability*: It allows easy integration with different AI Models, letting developers switch between differing AI models with minimal code changes.
|
||||
This design aligns with Spring's philosophy of modularity and interchangeability.
|
||||
|
||||
* *Simplicity*: By using companion classes like `Prompt` for input encapsulation and `AiResponse` for output handling, the `ChatClient` interface simplifies communication with AI Models. It manages the complexity of request preparation and response parsing, offering a direct and simplified API interaction.
|
||||
* *Simplicity*: By using companion classes like `Prompt` for input encapsulation and `ChatResponse` for output handling, the `ChatClient` interface simplifies communication with AI Models. It manages the complexity of request preparation and response parsing, offering a direct and simplified API interaction.
|
||||
|
||||
== API Overview
|
||||
|
||||
@@ -27,14 +27,14 @@ public interface ChatClient {
|
||||
default String generate(String message) { // implementation omitted
|
||||
}
|
||||
|
||||
AiResponse generate(Prompt prompt);
|
||||
ChatResponse generate(Prompt prompt);
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
The `generate` method with a `String` parameter simplifies initial use, avoiding the complexities of the more sophisticated `Prompt` and `AiResponse` classes.
|
||||
The `generate` method with a `String` parameter simplifies initial use, avoiding the complexities of the more sophisticated `Prompt` and `ChatResponse` classes.
|
||||
|
||||
In real-world applications, it is more common to use the `generate` method that takes a `Prompt` instance and returns an `AiResponse`.
|
||||
In real-world applications, it is more common to use the `generate` method that takes a `Prompt` instance and returns an `ChatResponse`.
|
||||
|
||||
=== Prompt
|
||||
|
||||
@@ -75,12 +75,12 @@ While the term `MessageType` might imply a specific message format, in this cont
|
||||
For AI models that do not use specific roles, the `UserMessage` implementation acts as a standard category, typically representing user-generated inquiries or instructions.
|
||||
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 xref:api/prompt.adoc[Prompts] section.
|
||||
|
||||
=== AiResponse
|
||||
=== ChatResponse
|
||||
|
||||
The structure of the `AiResponse` class is as follows:
|
||||
The structure of the `ChatResponse` class is as follows:
|
||||
|
||||
```java
|
||||
public class AiResponse {
|
||||
public class ChatResponse {
|
||||
|
||||
private final List<Generation> generations;
|
||||
|
||||
@@ -88,9 +88,9 @@ public class AiResponse {
|
||||
}
|
||||
```
|
||||
|
||||
The `AiResponse` class holds the AI Model's output, with each `Generation` instance containing one of potentially multiple outputs resulting from a single prompt.
|
||||
The `ChatResponse` class holds the AI Model's output, with each `Generation` instance containing one of potentially multiple outputs resulting from a single prompt.
|
||||
|
||||
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.
|
||||
The `ChatResponse` 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.
|
||||
|
||||
=== Generation
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ You can find this on the Inference Endpoint's UI link:https://ui.endpoints.huggi
|
||||
----
|
||||
HuggingfaceChatClient client = new HuggingfaceChatClient(apiKey, basePath);
|
||||
Prompt prompt = new Prompt("Your text here...");
|
||||
AiResponse response = client.generate(prompt);
|
||||
ChatResponse response = client.generate(prompt);
|
||||
System.out.println(response.getGeneration().getText());
|
||||
----
|
||||
|
||||
@@ -55,7 +55,7 @@ String mistral7bInstruct = """
|
||||
Just generate the JSON object without explanations:
|
||||
[/INST]""";
|
||||
Prompt prompt = new Prompt(mistral7bInstruct);
|
||||
AiResponse aiResponse = huggingfaceChatClient.generate(prompt);
|
||||
ChatResponse aiResponse = huggingfaceChatClient.generate(prompt);
|
||||
System.out.println(response.getGeneration().getText());
|
||||
----
|
||||
Will produce the output
|
||||
|
||||
@@ -24,7 +24,7 @@ OpenAI have introduced even more structure to prompts by categorizing multiple m
|
||||
|
||||
=== Prompt
|
||||
|
||||
It is common to use the `generate` method of `ChatClient` that takes a `Prompt` instance and returns an `AiResponse`.
|
||||
It is common to use the `generate` method of `ChatClient` that takes a `Prompt` instance and returns an `ChatResponse`.
|
||||
|
||||
The Prompt class functions as a container for an organized series of Message objects, with each one forming a segment of the overall prompt.
|
||||
Every Message embodies a unique role within the prompt, differing in its content and intent.
|
||||
|
||||
Reference in New Issue
Block a user