-
Notifications
You must be signed in to change notification settings - Fork 47
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
1cf87b8
commit c6c183b
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...t/java/dev/langchain4j/service/spring/mode/explicit/tools/AiServiceWithExplicitTools.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,11 @@ | ||
package dev.langchain4j.service.spring.mode.explicit.tools; | ||
|
||
import dev.langchain4j.service.spring.AiService; | ||
|
||
import static dev.langchain4j.service.spring.AiServiceWiringMode.EXPLICIT; | ||
|
||
@AiService(wiringMode = EXPLICIT, chatModel = "openAiChatModel", tools = {"tools1"}) | ||
public interface AiServiceWithExplicitTools { | ||
|
||
String chat(String userMessage); | ||
} |
12 changes: 12 additions & 0 deletions
12
...langchain4j/service/spring/mode/explicit/tools/AiServiceWithExplicitToolsApplication.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,12 @@ | ||
package dev.langchain4j.service.spring.mode.explicit.tools; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
class AiServiceWithExplicitToolsApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AiServiceWithExplicitToolsApplication.class, args); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...java/dev/langchain4j/service/spring/mode/explicit/tools/AiServiceWithExplicitToolsIT.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,36 @@ | ||
package dev.langchain4j.service.spring.mode.explicit.tools; | ||
|
||
import dev.langchain4j.service.spring.AiServicesAutoConfig; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
import static dev.langchain4j.service.spring.mode.explicit.tools.Tools1.TOOL_1_TEMPERATURE; | ||
import static dev.langchain4j.service.spring.mode.explicit.tools.Tools2.TOOL_2_TEMPERATURE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class AiServiceWithExplicitToolsIT { | ||
|
||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(AiServicesAutoConfig.class)); | ||
|
||
@Test | ||
void should_create_AI_service_with_explicit_tools() { | ||
contextRunner | ||
.withPropertyValues( | ||
"langchain4j.open-ai.chat-model.api-key=" + System.getenv("OPENAI_API_KEY"), | ||
"langchain4j.open-ai.chat-model.max-tokens=100", | ||
"langchain4j.open-ai.chat-model.temperature=0.0") | ||
.withUserConfiguration(AiServiceWithExplicitToolsApplication.class) | ||
.run(context -> { | ||
|
||
// given | ||
AiServiceWithExplicitTools aiService = context.getBean(AiServiceWithExplicitTools.class); | ||
|
||
// when | ||
String answer = aiService.chat("What is the temperature?"); | ||
|
||
// then | ||
assertThat(answer).contains(TOOL_1_TEMPERATURE).doesNotContain(TOOL_2_TEMPERATURE); | ||
}); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...boot-starter/src/test/java/dev/langchain4j/service/spring/mode/explicit/tools/Tools1.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,15 @@ | ||
package dev.langchain4j.service.spring.mode.explicit.tools; | ||
|
||
import dev.langchain4j.agent.tool.Tool; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class Tools1 { | ||
|
||
public static final String TOOL_1_TEMPERATURE = "6"; | ||
|
||
@Tool | ||
String getCurrentTemperature() { | ||
return TOOL_1_TEMPERATURE; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...boot-starter/src/test/java/dev/langchain4j/service/spring/mode/explicit/tools/Tools2.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,15 @@ | ||
package dev.langchain4j.service.spring.mode.explicit.tools; | ||
|
||
import dev.langchain4j.agent.tool.Tool; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class Tools2 { | ||
|
||
public static final String TOOL_2_TEMPERATURE = "9"; | ||
|
||
@Tool | ||
String getCurrentTemperature() { | ||
return TOOL_2_TEMPERATURE; | ||
} | ||
} |