Skip to content

Allow String prompt in ChatClient #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static Builder builder(ChatModel chatModel, ObservationRegistry observationRegis

ChatClientRequestSpec prompt();

ChatClientPromptRequestSpec prompt(String content);

ChatClientPromptRequestSpec prompt(Prompt prompt);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public ChatClientRequestSpec prompt() {
return new DefaultChatClientRequestSpec(this.defaultChatClientRequest);
}

@Override
public ChatClientPromptRequestSpec prompt(String content) {
return new DefaultChatClientPromptRequestSpec(this.chatModel, new Prompt(content));
}

@Override
public ChatClientPromptRequestSpec prompt(Prompt prompt) {
return new DefaultChatClientPromptRequestSpec(this.chatModel, prompt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,19 @@ public void defaultUserText() {
assertThat(userMessage.getMessageType()).isEqualTo(MessageType.USER);
}

@Test
public void simpleUserPromptAsString() {
when(chatModel.call(promptCaptor.capture()))
.thenReturn(new ChatResponse(List.of(new Generation(new AssistantMessage("response")))));

assertThat(ChatClient.builder(chatModel).build().prompt("User prompt").call().content())
.isEqualTo("response");

Message userMessage = promptCaptor.getValue().getInstructions().get(0);
assertThat(userMessage.getContent()).isEqualTo("User prompt");
assertThat(userMessage.getMessageType()).isEqualTo(MessageType.USER);
}

@Test
public void simpleUserPrompt() {
when(chatModel.call(promptCaptor.capture()))
Expand Down