Minor documentation updates

This commit is contained in:
Christian Tzolov
2024-02-09 19:06:38 +01:00
parent 6d13da1ba6
commit c5f80f4930
7 changed files with 20 additions and 135 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.ai.azure.openai;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.models.ChatChoice;
@@ -225,20 +226,13 @@ public class AzureOpenAiChatClient implements ChatClient, StreamingChatClient {
ChatCompletionsOptions mergedAzureOptions = new ChatCompletionsOptions(azureOptions.getMessages());
mergedAzureOptions.setStream(azureOptions.isStream());
mergedAzureOptions.setMaxTokens(azureOptions.getMaxTokens());
if (mergedAzureOptions.getMaxTokens() == null) {
mergedAzureOptions.setMaxTokens(springAiOptions.getMaxTokens());
}
mergedAzureOptions.setMaxTokens(
(azureOptions.getMaxTokens() != null) ? azureOptions.getMaxTokens() : springAiOptions.getMaxTokens());
mergedAzureOptions.setLogitBias(azureOptions.getLogitBias());
if (mergedAzureOptions.getLogitBias() == null) {
mergedAzureOptions.setLogitBias(springAiOptions.getLogitBias());
}
mergedAzureOptions.setLogitBias(
azureOptions.getLogitBias() != null ? azureOptions.getLogitBias() : springAiOptions.getLogitBias());
mergedAzureOptions.setStop(azureOptions.getStop());
if (mergedAzureOptions.getStop() == null) {
mergedAzureOptions.setStop(springAiOptions.getStop());
}
mergedAzureOptions.setStop(azureOptions.getStop() != null ? azureOptions.getStop() : springAiOptions.getStop());
mergedAzureOptions.setTemperature(azureOptions.getTemperature());
if (mergedAzureOptions.getTemperature() == null && springAiOptions.getTemperature() != null) {
@@ -260,20 +254,12 @@ public class AzureOpenAiChatClient implements ChatClient, StreamingChatClient {
mergedAzureOptions.setPresencePenalty(springAiOptions.getPresencePenalty().doubleValue());
}
mergedAzureOptions.setN(azureOptions.getN());
if (mergedAzureOptions.getN() == null) {
mergedAzureOptions.setN(springAiOptions.getN());
}
mergedAzureOptions.setN(azureOptions.getN() != null ? azureOptions.getN() : springAiOptions.getN());
mergedAzureOptions.setUser(azureOptions.getUser());
if (mergedAzureOptions.getUser() == null) {
mergedAzureOptions.setUser(springAiOptions.getUser());
}
mergedAzureOptions.setUser(azureOptions.getUser() != null ? azureOptions.getUser() : springAiOptions.getUser());
mergedAzureOptions.setModel(azureOptions.getModel());
if (mergedAzureOptions.getModel() == null) {
mergedAzureOptions.setModel(springAiOptions.getModel());
}
mergedAzureOptions
.setModel(azureOptions.getModel() != null ? azureOptions.getModel() : springAiOptions.getModel());
return mergedAzureOptions;
}

View File

@@ -4,7 +4,7 @@ Azure's OpenAI offering, powered by ChatGPT, extends beyond traditional OpenAI c
Azure offers Java developers the opportunity to leverage AI's full potential by integrating it with an array of Azure services, which includes AI-related resources such as Vector Stores on Azure.
== Pre-requisites
== Prerequisites
Obtain your Azure OpenAI `endpoint` and `api-key` from the Azure OpenAI Service section on the link:https://portal.azure.com[Azure Portal].

View File

@@ -1,103 +0,0 @@
= Azure OpenAI
Azure's OpenAI offering, powered by ChatGPT, extends beyond traditional OpenAI capabilities, delivering AI-driven text generation with enhanced functionality. Azure offers additional AI safety and responsible AI features, as highlighted in their recent update https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/announcing-new-ai-safety-amp-responsible-ai-features-in-azure/ba-p/3983686[here].
Azure offers Java developers the opportunity to leverage AI's full potential by integrating it with an array of Azure services, which includes AI-related resources such as Vector Stores on Azure.
== Getting Started
Obtain your Azure OpenAI `endpoint` and `api-key` from the Azure OpenAI Service section on the link:https://portal.azure.com[Azure Portal].
Spring AI 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.
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.
Exporting environment variables is one way to set these configuration properties:
[source,shell]
----
export SPRING_AI_AZURE_OPENAI_API_KEY=<INSERT KEY HERE>
export SPRING_AI_AZURE_OPENAI_ENDPOINT=<INSERT ENDPOINT URL HERE>
----
== Project Dependencies
Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
Then add the Spring Boot Starter dependency to your project's Maven `pom.xml` build file:
[source, xml]
----
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
<version>0.8.0-SNAPSHOT</version>
</dependency>
----
or to your Gradle `build.gradle` build file.
[source,groovy]
----
dependencies {
implementation 'org.springframework.ai:spring-ai-azure-openai-spring-boot-starter:0.8.0-SNAPSHOT'
}
----
== Sample Code
This will create a `ChatClient` implementation that you can inject into your class.
Here is an example of a simple `@Controller` class that uses the `ChatClient` implementation.
[source,java]
----
@RestController
public class ChatController {
private final ChatClient chatClient;
@Autowired
public ChatController(ChatClient chatClient) {
this.chatClient = chatClient;
}
@GetMapping("/ai/generate")
public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
return Map.of("generation", chatClient.call(message));
}
}
----
== Azure OpenAI Properties
The prefix `spring.ai.azure.openai` is the property prefix to configure the connection to Azure OpenAI.
[cols="3,5,3"]
|====
| Property | Description | Default
| spring.ai.azure.openai.api-key | The Key from Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | -
| spring.ai.azure.openai.endpoint | The endpoint from the Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | -
|====
The prefix `spring.ai.azure.openai.chat` is the property prefix that configures the `ChatClient` implementation for Azure OpenAI.
[cols="3,5,3"]
|====
| Property | Description | Default
| spring.ai.azure.openai.chat.model | This is the value of the 'Deployment Name' as presented in the Azure AI Portal | gpt-35-turbo
| spring.ai.azure.openai.chat.temperature | The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | 0.7
| spring.ai.azure.openai.chat.top-p | An alternative to sampling with temperature called nucleus sampling. This value causes the model to consider the results of tokens with the provided probability mass. As an example, a value of 0.15 will cause only the tokens comprising the top 15% of probability mass to be considered. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | -
| spring.ai.azure.openai.chat.max-tokens | The maximum number of tokens to generate | -
|====
The prefix `spring.ai.azure.openai.embeddings` is the property prefix that configures the `EmbeddingClient` implementation for Azure OoenAI
[cols="3,5,3"]
|====
| Property | Description | Default
| spring.ai.azure.openai.embedding.model | This is the value of the 'Deployment Name' as presented in the Azure AI Portal | text-embedding-ada-002
|====

View File

@@ -1,4 +1,4 @@
= Bedrock Anthropic Chat
= Anthropic Chat
https://www.anthropic.com/product[Anthropic's Claude] is an AI assistant based on Anthropics research into training helpful, honest, and harmless AI systems.

View File

@@ -1,4 +1,4 @@
= Bedrock Llama2 Chat
= Llama2 Chat
https://ai.meta.com/llama/[Meta's Llama 2 Chat] is part of the Llama 2 collection of large language models.
It excels in dialogue-based applications with a parameter scale ranging from 7 billion to 70 billion.

View File

@@ -8,7 +8,7 @@ Azure's OpenAI extends the OpenAI capabilities, offering safe text generation an
The Azure OpenAI embeddings rely on `cosine similarity` to compute similarity between documents and a query.
== Pre-requisites
== Prerequisites
Obtain your Azure OpenAI `endpoint` and `api-key` from the Azure OpenAI Service section on the link:https://portal.azure.com[Azure Portal].
@@ -146,6 +146,8 @@ EmbeddingResponse embeddingResponse = embeddingClient
NOTE: the `text-embedding-ada-002` is actually the `Deployment Name` as presented in the Azure AI Portal.
=== Embedding Options
The `AzureOpenAiEmbeddingOptions` provides the configuration information for the embedding requests.
The `AzureOpenAiEmbeddingOptions` offers a builder to create the options.

View File

@@ -16,7 +16,7 @@ Refer to the official Ollama project link:https://github.com/jmorganca/ollama[RE
Note, installing `ollama run llama2` will download a 4GB docker image.
=== OllamaEmbeddingClient Auto-configuration
== Auto-configuration
Spring AI provides Spring Boot auto-configuration for the Azure Ollama Embedding Client.
To enable it add the following dependency to your Maven `pom.xml` file:
@@ -44,7 +44,7 @@ NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency M
The `spring.ai.ollama.embedding.options.*` properties are used to configure the default options used for all embedding requests.
(It is used as `OllamaEmbeddingClient#withDefaultOptions()` instance).
== Embedding Properties
=== Embedding Properties
The prefix `spring.ai.ollama` is the property prefix to configure the connection to Ollama
@@ -57,7 +57,7 @@ The prefix `spring.ai.ollama` is the property prefix to configure the connection
The prefix `spring.ai.ollama.embedding.options` is the property prefix that configures the `EmbeddingClient` implementation for Ollama.
[cols="3,6,1"]
[cols="3,5,1"]
|====
| Property | Description | Default
@@ -168,7 +168,7 @@ EmbeddingResponse embeddingResponse = embeddingClient
The `OllamaOptions` provides the configuration information for all embedding requests.
=== Chat Options
=== Embedding Options
The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaOptions.java[OllamaOptions.java] provides the Ollama configurations, such as the model to use, the low level GPU and CPU tunning, etc.