forked from spring-projects/spring-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b3d6a5
commit 4159758
Showing
11 changed files
with
228 additions
and
146 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
spring-ai-core/src/main/java/org/springframework/ai/core/prompts/AiPromptTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package org.springframework.ai.core.prompts; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.ai.core.prompts.messages.AiMessage; | ||
|
||
public class AiPromptTemplate extends PromptTemplate { | ||
|
||
private boolean example = false; | ||
|
||
public AiPromptTemplate(String template) { | ||
super(template); | ||
} | ||
|
||
public AiPromptTemplate(String template, boolean example) { | ||
super(template); | ||
this.example = example; | ||
} | ||
|
||
@Override | ||
public Prompt create() { | ||
return new Prompt(new AiMessage(render())); | ||
} | ||
|
||
@Override | ||
public Prompt create(Map<String, Object> model) { | ||
return new Prompt(new AiMessage(render(model), this.example)); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
spring-ai-core/src/main/java/org/springframework/ai/core/prompts/ChatPromptTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package org.springframework.ai.core.prompts; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.ai.core.prompts.messages.ChatMessage; | ||
|
||
public class ChatPromptTemplate extends PromptTemplate { | ||
|
||
private String role; | ||
|
||
public ChatPromptTemplate(String template) { | ||
super(template); | ||
} | ||
|
||
public ChatPromptTemplate(String template, String role) { | ||
super(template); | ||
this.role = role; | ||
} | ||
|
||
@Override | ||
public Prompt create() { | ||
return new Prompt(new ChatMessage(render(), this.role)); | ||
} | ||
|
||
@Override | ||
public Prompt create(Map<String, Object> model) { | ||
return new Prompt(new ChatMessage(render(model), this.role)); | ||
} | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
spring-ai-core/src/main/java/org/springframework/ai/core/prompts/FunctionPromptTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package org.springframework.ai.core.prompts; | ||
|
||
public class FunctionPromptTemplate extends PromptTemplate { | ||
|
||
private String name; | ||
|
||
public FunctionPromptTemplate(String template) { | ||
super(template); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
spring-ai-core/src/main/java/org/springframework/ai/core/prompts/PromptBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
spring-ai-core/src/main/java/org/springframework/ai/core/prompts/SystemPromptTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package org.springframework.ai.core.prompts; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.ai.core.prompts.messages.SystemMessage; | ||
|
||
public class SystemPromptTemplate extends PromptTemplate { | ||
|
||
public SystemPromptTemplate(String template) { | ||
super(template); | ||
} | ||
|
||
@Override | ||
public Prompt create() { | ||
return new Prompt(new SystemMessage(render())); | ||
} | ||
|
||
@Override | ||
public Prompt create(Map<String, Object> model) { | ||
return new Prompt(new SystemMessage(render(model))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
spring-ai-core/src/test/java/org/springframework/ai/core/prompts/ChatTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package org.springframework.ai.core.prompts; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ChatTests { | ||
|
||
// @Test | ||
// void testChat() { | ||
// | ||
// String customerStyle = "American English in a calm and respectful tone"; | ||
// String customerEmail = "Arrr, I be fuming that me blender lid " | ||
// + "flew off and splattered me kitchen walls " | ||
// + "with smoothie! And to make matters worse, " | ||
// + "the warranty don't cover the cost of " | ||
// + "cleaning up me kitchen. I need yer help " | ||
// + "right now, matey!"; | ||
// ChatOpenAi chatOpenAi = new ChatOpenAi(); | ||
// chatOpenAi | ||
// | ||
// } | ||
} |
Oops, something went wrong.