Skip to content

Commit

Permalink
rename config
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Jan 2, 2025
1 parent 4fcc13d commit 86b2522
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public AIAssistant createWithPrompt(
AIAssistant.Builder builder = initializeBuilder(platformType);
builder.id(id)
.memoryStore(chatMemoryStoreProvider.createPersistentChatMemoryStore())
.withConfigProvider(generalAssistantConfig)
.withConfig(generalAssistantConfig)
.withToolProvider(toolProvider);

configureSystemPrompt(builder, systemPrompt, generalAssistantConfig.getLanguage());
Expand All @@ -98,7 +98,7 @@ public AIAssistant createForTest(AIAssistantConfig config, ToolProvider toolProv

builder.id(null)
.memoryStore(chatMemoryStoreProvider.createInMemoryChatMemoryStore())
.withConfigProvider(generalAssistantConfig)
.withConfig(generalAssistantConfig)
.withToolProvider(toolProvider);

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private String loadPromptFromFile(String fileName) {
return Objects.requireNonNullElse(text, "You are a helpful assistant.");
}

@Override
public String getLanguagePrompt(String locale) {
final String filePath = SystemPrompt.LANGUAGE_PROMPT.getValue() + '-' + locale + ".st";
String text = loadTextFromFile(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void testCreateAIAssistant() {
AIAssistant.Builder mockBuilder = mock(OpenAIAssistant.Builder.class);
when(mockBuilder.id(any())).thenReturn(mockBuilder);
when(mockBuilder.memoryStore(any())).thenReturn(mockBuilder);
when(mockBuilder.withConfigProvider(any())).thenReturn(mockBuilder);
when(mockBuilder.withConfig(any())).thenReturn(mockBuilder);
when(mockBuilder.withToolProvider(any())).thenReturn(mockBuilder);
when(mockBuilder.withSystemPrompt(any())).thenReturn(mockBuilder);
when(mockBuilder.build()).thenReturn(mock(AIAssistant.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract static class Builder implements AIAssistant.Builder {
protected Object id;

protected ChatMemoryStore chatMemoryStore;
protected AIAssistantConfig configProvider;
protected AIAssistantConfig config;

protected ToolProvider toolProvider;
protected String systemPrompt;
Expand All @@ -78,8 +78,8 @@ public Builder withSystemPrompt(String systemPrompt) {
return this;
}

public Builder withConfigProvider(AIAssistantConfig configProvider) {
this.configProvider = configProvider;
public Builder withConfig(AIAssistantConfig config) {
this.config = config;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface Builder {

Builder memoryStore(ChatMemoryStore memoryStore);

Builder withConfigProvider(AIAssistantConfig configProvider);
Builder withConfig(AIAssistantConfig configProvider);

Builder withToolProvider(ToolProvider toolProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ public interface SystemPromptProvider {
// return default system prompt
String getSystemMessage();

String getLanguagePrompt(String locale);

String getSystemMessages(List<String> systemPrompts);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public AIAssistant build() {

@Override
public ChatLanguageModel getChatLanguageModel() {
String model = ValidationUtils.ensureNotNull(configProvider.getModel(), "model");
String apiKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("apiKey"), "apiKey");
String model = ValidationUtils.ensureNotNull(config.getModel(), "model");
String apiKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey");
return QwenChatModel.builder().apiKey(apiKey).modelName(model).build();
}

@Override
public StreamingChatLanguageModel getStreamingChatLanguageModel() {
String model = ValidationUtils.ensureNotNull(configProvider.getModel(), "model");
String apiKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("apiKey"), "apiKey");
String model = ValidationUtils.ensureNotNull(config.getModel(), "model");
String apiKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey");
return QwenStreamingChatModel.builder()
.apiKey(apiKey)
.modelName(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public static class Builder extends AbstractAIAssistant.Builder {

@Override
public ChatLanguageModel getChatLanguageModel() {
String model = ValidationUtils.ensureNotNull(configProvider.getModel(), "model");
String apiKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("apiKey"), "apiKey");
String model = ValidationUtils.ensureNotNull(config.getModel(), "model");
String apiKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey");
return OpenAiChatModel.builder()
.apiKey(apiKey)
.baseUrl(BASE_URL)
Expand All @@ -63,9 +63,9 @@ public ChatLanguageModel getChatLanguageModel() {

@Override
public StreamingChatLanguageModel getStreamingChatLanguageModel() {
String model = ValidationUtils.ensureNotNull(configProvider.getModel(), "model");
String apiKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("apiKey"), "apiKey");
String model = ValidationUtils.ensureNotNull(config.getModel(), "model");
String apiKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey");
return OpenAiStreamingChatModel.builder()
.apiKey(apiKey)
.baseUrl(BASE_URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public AIAssistant build() {

@Override
public ChatLanguageModel getChatLanguageModel() {
String model = ValidationUtils.ensureNotNull(configProvider.getModel(), "model");
String apiKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("apiKey"), "apiKey");
String secretKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("secretKey"), "secretKey");
String model = ValidationUtils.ensureNotNull(config.getModel(), "model");
String apiKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey");
String secretKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("secretKey"), "secretKey");
return QianfanChatModel.builder()
.apiKey(apiKey)
.secretKey(secretKey)
Expand All @@ -79,11 +79,11 @@ public ChatLanguageModel getChatLanguageModel() {

@Override
public StreamingChatLanguageModel getStreamingChatLanguageModel() {
String model = ValidationUtils.ensureNotNull(configProvider.getModel(), "model");
String apiKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("apiKey"), "apiKey");
String secretKey = ValidationUtils.ensureNotNull(
configProvider.getCredentials().get("secretKey"), "secretKey");
String model = ValidationUtils.ensureNotNull(config.getModel(), "model");
String apiKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey");
String secretKey =
ValidationUtils.ensureNotNull(config.getCredentials().get("secretKey"), "secretKey");
return QianfanStreamingChatModel.builder()
.apiKey(apiKey)
.secretKey(secretKey)
Expand Down

0 comments on commit 86b2522

Please sign in to comment.