Update available OpenAI GPT 4 family of models in enum

* Use GPT 4 Turbo in OpenAiPromptTransformingChatServiceIT
* Accept multiple bike names as acceptable answers in assertion
* Update docs
This commit is contained in:
Mark Pollack
2024-05-26 18:28:59 -04:00
parent a60035eeb6
commit dc656ce3bc
3 changed files with 37 additions and 24 deletions

View File

@@ -121,6 +121,20 @@ public class OpenAiApi {
*/
GPT_4_O("gpt-4o"),
/**
* GPT-4 Turbo with Vision
* The latest GPT-4 Turbo model with vision capabilities.
* Vision requests can now use JSON mode and function calling.
* Currently points to gpt-4-turbo-2024-04-09.
*/
GPT_4_0_TURBO("gpt-4-turbo"),
/**
* GPT-4 Turbo with Vision model. Vision requests can now use JSON mode and function calling
*/
GPT_4_0_TURBO_2204_04_09("gpt-4-turbo-2024-04-09"),
/**
* (New) GPT-4 Turbo - latest GPT-4 model intended to reduce cases
* of “laziness” where the model doesnt complete a task.

View File

@@ -16,32 +16,25 @@
package org.springframework.ai.openai.chat.service;
import java.util.List;
import java.util.function.Supplier;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.service.ChatService;
import org.springframework.ai.chat.prompt.transformer.TransformerContentType;
import org.springframework.ai.document.Document;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.qdrant.QdrantContainer;
import org.springframework.ai.chat.service.PromptTransformingChatService;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.transformer.ChatServiceContext;
import org.springframework.ai.chat.prompt.transformer.QuestionContextAugmentor;
import org.springframework.ai.chat.prompt.transformer.TransformerContentType;
import org.springframework.ai.chat.prompt.transformer.VectorStoreRetriever;
import org.springframework.ai.chat.service.ChatService;
import org.springframework.ai.chat.service.PromptTransformingChatService;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.evaluation.EvaluationResponse;
import org.springframework.ai.evaluation.RelevancyEvaluator;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.ai.reader.JsonReader;
@@ -55,9 +48,15 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.qdrant.QdrantContainer;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.ai.openai.api.OpenAiApi.ChatModel.GPT_4_TURBO_PREVIEW;
import java.util.List;
import java.util.function.Supplier;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.ai.openai.api.OpenAiApi.ChatModel.GPT_4_0_TURBO;
@Testcontainers
@SpringBootTest(classes = OpenAiPromptTransformingChatServiceIT.Config.class)
@@ -92,20 +91,20 @@ public class OpenAiPromptTransformingChatServiceIT {
void simpleChat() {
loadData();
var prompt = new Prompt(new UserMessage("What reliable road bike?"));
String question = "What reliable road bike?";
var prompt = new Prompt(new UserMessage(question));
var chatServiceResponse = this.chatService.call(new ChatServiceContext(prompt));
String answer = chatServiceResponse.getChatResponse().getResult().getOutput().getContent();
assertTrue(answer.contains("Celerity"), "Response does not include 'Celerity'");
assertThat(answer).containsAnyOf("Celerity", "Velocity")
.as("Answer does not include 'Celerity' or 'Velocity'. Answer = %s", answer);
// Use GPT 4 as a better model for determining relevancy. gpt 3.5 makes basic
// mistakes
OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()
.withModel(GPT_4_TURBO_PREVIEW.getValue())
.build();
// Use GPT 4 Turbo as a better model for determining relevancy.
OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder().withModel(GPT_4_0_TURBO.getValue()).build();
var relevancyEvaluator = new RelevancyEvaluator(this.chatModel, openAiChatOptions);
EvaluationResponse evaluationResponse = relevancyEvaluator.evaluate(chatServiceResponse.toEvaluationRequest());
assertTrue(evaluationResponse.isPass(), "Response is not relevant to the question");
assertThat(evaluationResponse.isPass())
.as("Response is not relevant to the question. Question = %s; Answer = %s", question, answer);
}

View File

@@ -90,7 +90,7 @@ The prefix `spring.ai.openai.chat` is the property prefix that lets you configur
| spring.ai.openai.chat.enabled | Enable OpenAI chat model. | true
| spring.ai.openai.chat.base-url | Optional overrides the spring.ai.openai.base-url to provide chat specific url | -
| spring.ai.openai.chat.api-key | Optional overrides the spring.ai.openai.api-key to provide chat specific api-key | -
| spring.ai.openai.chat.options.model | This is the OpenAI Chat model to use | `gpt-3.5-turbo` (the `gpt-3.5-turbo`, `gpt-4`, and `gpt-4-32k` point to the latest model versions)
| spring.ai.openai.chat.options.model | This is the OpenAI Chat model to use. `gpt-4o`, `gpt-4-turbo`, `gpt-4-turbo-2024-04-09`, `gpt-4-0125-preview`, `gpt-4-turbo-preview`, `gpt-4-vision-preview`, `gpt-4-32k`, `gpt-3.5-turbo`, `gpt-3.5-turbo-0125`, `gpt-3.5-turbo-1106`. See the https://platform.openai.com/docs/models[models] page for more information. | `gpt-3.5-turbo`
| spring.ai.openai.chat.options.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.8
| spring.ai.openai.chat.options.frequencyPenalty | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. | 0.0f
| spring.ai.openai.chat.options.logitBias | Modify the likelihood of specified tokens appearing in the completion. | -