Refactor Azure model options builder methods
- Deprecate builder methods with the prefix `with` and add them without the prefix - Update references and docs
This commit is contained in:
committed by
Mark Pollack
parent
93a7ba4c84
commit
da45244d99
@@ -63,10 +63,10 @@ For example:
|
||||
AzureOpenAiAudioTranscriptionOptions.TranscriptResponseFormat responseFormat = AzureOpenAiAudioTranscriptionOptions.TranscriptResponseFormat.VTT;
|
||||
|
||||
AzureOpenAiAudioTranscriptionOptions transcriptionOptions = AzureOpenAiAudioTranscriptionOptions.builder()
|
||||
.withLanguage("en")
|
||||
.withPrompt("Ask not this, but ask that")
|
||||
.withTemperature(0f)
|
||||
.withResponseFormat(this.responseFormat)
|
||||
.language("en")
|
||||
.prompt("Ask not this, but ask that")
|
||||
.temperature(0f)
|
||||
.responseFormat(this.responseFormat)
|
||||
.build();
|
||||
AudioTranscriptionPrompt transcriptionRequest = new AudioTranscriptionPrompt(audioFile, this.transcriptionOptions);
|
||||
AudioTranscriptionResponse response = azureOpenAiTranscriptionModel.call(this.transcriptionRequest);
|
||||
@@ -107,8 +107,8 @@ var openAIClient = new OpenAIClientBuilder()
|
||||
var azureOpenAiAudioTranscriptionModel = new AzureOpenAiAudioTranscriptionModel(this.openAIClient, null);
|
||||
|
||||
var transcriptionOptions = AzureOpenAiAudioTranscriptionOptions.builder()
|
||||
.withResponseFormat(TranscriptResponseFormat.TEXT)
|
||||
.withTemperature(0f)
|
||||
.responseFormat(TranscriptResponseFormat.TEXT)
|
||||
.temperature(0f)
|
||||
.build();
|
||||
|
||||
var audioFile = new FileSystemResource("/path/to/your/resource/speech/jfk.flac");
|
||||
|
||||
@@ -168,8 +168,8 @@ ChatResponse response = chatModel.call(
|
||||
new Prompt(
|
||||
"Generate the names of 5 famous pirates.",
|
||||
AzureOpenAiChatOptions.builder()
|
||||
.withDeploymentName("gpt-4o")
|
||||
.withTemperature(0.4)
|
||||
.deploymentName("gpt-4o")
|
||||
.temperature(0.4)
|
||||
.build()
|
||||
));
|
||||
----
|
||||
@@ -198,7 +198,7 @@ Below is a code example excerpted from link:https://github.com/spring-projects/s
|
||||
----
|
||||
URL url = new URL("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png");
|
||||
String response = ChatClient.create(chatModel).prompt()
|
||||
.options(AzureOpenAiChatOptions.builder().withDeploymentName("gpt-4o").build())
|
||||
.options(AzureOpenAiChatOptions.builder().deploymentName("gpt-4o").build())
|
||||
.user(u -> u.text("Explain what do you see on this picture?").media(MimeTypeUtils.IMAGE_PNG, this.url))
|
||||
.call()
|
||||
.content();
|
||||
@@ -229,7 +229,7 @@ Resource resource = new ClassPathResource("multimodality/multimodal.test.png");
|
||||
|
||||
String response = ChatClient.create(chatModel).prompt()
|
||||
.options(AzureOpenAiChatOptions.builder()
|
||||
.withDeploymentName("gpt-4o").build())
|
||||
.deploymentName("gpt-4o").build())
|
||||
.user(u -> u.text("Explain what do you see on this picture?")
|
||||
.media(MimeTypeUtils.IMAGE_PNG, this.resource))
|
||||
.call()
|
||||
@@ -317,9 +317,9 @@ var openAIClient = new OpenAIClientBuilder()
|
||||
.buildClient();
|
||||
|
||||
var openAIChatOptions = AzureOpenAiChatOptions.builder()
|
||||
.withDeploymentName("gpt-4o")
|
||||
.withTemperature(0.4)
|
||||
.withMaxTokens(200)
|
||||
.deploymentName("gpt-4o")
|
||||
.temperature(0.4)
|
||||
.maxTokens(200)
|
||||
.build();
|
||||
|
||||
var chatModel = new AzureOpenAiChatModel(this.openAIClient, this.openAIChatOptions);
|
||||
|
||||
@@ -150,7 +150,7 @@ AzureOpenAiChatModel chatModel = ...
|
||||
UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
|
||||
|
||||
ChatResponse response = this.chatModel.call(new Prompt(List.of(this.userMessage),
|
||||
AzureOpenAiChatOptions.builder().withFunction("CurrentWeather").build())); // (1) Enable the function
|
||||
AzureOpenAiChatOptions.builder().function("CurrentWeather").build())); // (1) Enable the function
|
||||
|
||||
logger.info("Response: {}", response);
|
||||
----
|
||||
@@ -180,7 +180,7 @@ AzureOpenAiChatModel chatModel = ...
|
||||
UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris? Use Multi-turn function calling.");
|
||||
|
||||
var promptOptions = AzureOpenAiChatOptions.builder()
|
||||
.withFunctionCallbacks(List.of(FunctionCallback.builder()
|
||||
.functionCallbacks(List.of(FunctionCallback.builder()
|
||||
.function("CurrentWeather", new MockWeatherService()) // (1) function name and instance
|
||||
.description("Get the current weather in a given location") // (2) function description
|
||||
.inputType(MockWeatherService.Request.class) // (3) function input type
|
||||
|
||||
@@ -126,7 +126,7 @@ For example to override the default model name for a specific request:
|
||||
EmbeddingResponse embeddingResponse = embeddingModel.call(
|
||||
new EmbeddingRequest(List.of("Hello World", "World is big and salvation is near"),
|
||||
AzureOpenAiEmbeddingOptions.builder()
|
||||
.withModel("Different-Embedding-Model-Deployment-Name")
|
||||
.model("Different-Embedding-Model-Deployment-Name")
|
||||
.build()));
|
||||
----
|
||||
|
||||
@@ -199,8 +199,8 @@ var openAIClient = OpenAIClientBuilder()
|
||||
|
||||
var embeddingModel = new AzureOpenAiEmbeddingModel(this.openAIClient)
|
||||
.withDefaultOptions(AzureOpenAiEmbeddingOptions.builder()
|
||||
.withModel("text-embedding-ada-002")
|
||||
.withUser("user-6")
|
||||
.model("text-embedding-ada-002")
|
||||
.user("user-6")
|
||||
.build());
|
||||
|
||||
EmbeddingResponse embeddingResponse = this.embeddingModel
|
||||
|
||||
@@ -118,10 +118,10 @@ For example to override the OpenAI specific options such as quality and the numb
|
||||
ImageResponse response = azureOpenaiImageModel.call(
|
||||
new ImagePrompt("A light cream colored mini golden doodle",
|
||||
OpenAiImageOptions.builder()
|
||||
.withQuality("hd")
|
||||
.withN(4)
|
||||
.withHeight(1024)
|
||||
.withWidth(1024).build())
|
||||
.quality("hd")
|
||||
.N(4)
|
||||
.height(1024)
|
||||
.width(1024).build())
|
||||
|
||||
);
|
||||
----
|
||||
|
||||
Reference in New Issue
Block a user