forked from quarkiverse/quarkus-langchain4j
-
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.
New Prompt, but still some issues with send poem. Need to tune it to …
…avoid unnecessary multiple calls to same tool
- Loading branch information
Showing
14 changed files
with
309 additions
and
155 deletions.
There are no files selected for viewing
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
118 changes: 0 additions & 118 deletions
118
...lama/deployment/src/test/java/io/quarkiverse/langchain4j/ollama/deployment/ToolsTest.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
...ama/deployment/src/test/java/io/quarkiverse/langchain4j/ollama/tools/Llama3ToolsTest.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,88 @@ | ||
package io.quarkiverse.langchain4j.ollama.tools; | ||
|
||
import dev.langchain4j.service.SystemMessage; | ||
import dev.langchain4j.service.UserMessage; | ||
import io.quarkiverse.langchain4j.RegisterAiService; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.enterprise.context.control.ActivateRequestContext; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Disabled("Integration tests that need an ollama server running") | ||
@DisplayName("LLM Tools test - " + Llama3ToolsTest.MODEL_NAME) | ||
@QuarkusTest | ||
public class Llama3ToolsTest { | ||
|
||
public static final String MODEL_NAME = "llama3"; | ||
|
||
@RegisterAiService(tools = Tools.Calculator.class, modelName = MODEL_NAME) | ||
public interface MathAssistantLlama3 { | ||
String chat(String userMessage); | ||
} | ||
|
||
@Inject | ||
MathAssistantLlama3 mathAssistantLlama3; | ||
|
||
@Test | ||
@ActivateRequestContext | ||
void square_of_sum_of_number_of_letters() { | ||
String msg = "What is the square root with maximal precision of the sum " + | ||
"of the numbers of letters in the words hello and llama"; | ||
String response = mathAssistantLlama3.chat(msg); | ||
assertThat(response).contains("3.1622776601683795"); | ||
} | ||
|
||
@RegisterAiService(tools = Tools.ExpenseService.class, modelName = MODEL_NAME) | ||
public interface Assistant { | ||
@SystemMessage(""" | ||
You are a property manager assistant, answering to co-owners requests. | ||
Format the date as YYYY-MM-DD and the time as HH:MM | ||
Today is {{current_date}} use this date as date time reference | ||
The co-owners is living in the following condominium: {condominium} | ||
""") | ||
@UserMessage(""" | ||
{{request}} | ||
""") | ||
String answer(String condominium, String request); | ||
} | ||
@Inject | ||
Assistant assistant; | ||
|
||
@Test | ||
@ActivateRequestContext | ||
void get_expenses() { | ||
String response = assistant.answer("Rives de Marne", | ||
"What are the expenses for this year ?"); | ||
assertThat(response).contains("Expense hp12"); | ||
} | ||
|
||
@Test | ||
@ActivateRequestContext | ||
void should_not_calls_tool() { | ||
String response = assistant.answer("Rives de Marne", "What time is it ?"); | ||
assertThat(response).doesNotContain("Expense hp12"); | ||
} | ||
|
||
@RegisterAiService(tools = Tools.EmailService.class, modelName = MODEL_NAME) | ||
public interface PoemService { | ||
@SystemMessage("You are a professional poet") | ||
@UserMessage(""" | ||
Write a poem about {topic}. The poem should be {lines} lines long. Then send this poem by email. | ||
""") | ||
String writeAPoem(String topic, int lines); | ||
} | ||
|
||
@Inject | ||
PoemService poemService; | ||
|
||
@Test | ||
@ActivateRequestContext | ||
void send_a_poem() { | ||
String response = poemService.writeAPoem("Condominium Rives de marne", 4); | ||
assertThat(response).contains("Success"); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...viders/ollama/deployment/src/test/java/io/quarkiverse/langchain4j/ollama/tools/Tools.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,64 @@ | ||
package io.quarkiverse.langchain4j.ollama.tools; | ||
|
||
import dev.langchain4j.agent.tool.Tool; | ||
import io.quarkus.logging.Log; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Singleton; | ||
|
||
public class Tools { | ||
|
||
@Singleton | ||
@SuppressWarnings("unused") | ||
public static class Calculator { | ||
@Tool("Calculates the length of a string") | ||
int stringLength(String s) { | ||
return s.length(); | ||
} | ||
|
||
String stringLengthStr(String s) { | ||
return String.format("The length of the word %s is %d", s, s.length()); | ||
} | ||
|
||
@Tool("Calculates the sum of two numbers") | ||
int add(int a, int b) { | ||
return a + b; | ||
} | ||
|
||
String addStr(int a, int b) { | ||
return String.format("The sum of %s and %s is %d", a, b, a + b); | ||
} | ||
|
||
@Tool("Calculates the square root of a number") | ||
double sqrt(int x) { | ||
return Math.sqrt(x); | ||
} | ||
|
||
String sqrtStr(int x) { | ||
return String.format("The square root of %s is %f", x, Math.sqrt(x)); | ||
} | ||
} | ||
|
||
@Singleton | ||
@SuppressWarnings("unused") | ||
static class ExpenseService { | ||
@Tool("useful for when you need to lookup condominium expenses for given dates.") | ||
public String getExpenses(String condominium, String fromDate, String toDate) { | ||
String result = String.format(""" | ||
The Expenses for %s from %s to %s are: | ||
- Expense hp12: 2800e | ||
- Expense 2: 15000e | ||
""", condominium, fromDate, toDate); | ||
Log.infof(result); | ||
return result; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
static class EmailService { | ||
@Tool("send the given content by email") | ||
@SuppressWarnings("unused") | ||
public void sendAnEmail(String content) { | ||
Log.info("Tool sendAnEmail has been executed successfully!"); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
model-providers/ollama/deployment/src/test/resources/application.properties
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,31 @@ | ||
quarkus.langchain4j.ollama.log-requests = true | ||
quarkus.langchain4j.ollama.log-responses = true | ||
quarkus.langchain4j.ollama.chat-model.num-predict = 8192 | ||
quarkus.langchain4j.ollama.chat-model.num-ctx = 4096 | ||
|
||
|
||
# Not working llm: calebfahlgren/natural-functions , phi3, aya, mistral, gemma, | ||
# Working llm: llama3, qwen2 | ||
quarkus.langchain4j.ollama.llama3-2048_ctx.chat-model.model-id = llama3-2048_ctx | ||
quarkus.langchain4j.ollama.llama3-2048_ctx.timeout = 60s | ||
quarkus.langchain4j.ollama.llama3-2048_ctx.chat-model.temperature = 0.0 | ||
quarkus.langchain4j.ollama.llama3-2048_ctx.chat-model.num-ctx = 4096 | ||
quarkus.langchain4j.ollama.llama3-2048_ctx.chat-model.num-predict = 8192 | ||
quarkus.langchain4j.ollama.llama3-2048_ctx.experimental-tools = true | ||
|
||
quarkus.langchain4j.ollama.llama3.chat-model.model-id = llama3-2048_ctx | ||
quarkus.langchain4j.ollama.llama3.timeout = 60s | ||
quarkus.langchain4j.ollama.llama3.chat-model.temperature = 0.0 | ||
quarkus.langchain4j.ollama.llama3.chat-model.num-ctx = 4096 | ||
quarkus.langchain4j.ollama.llama3.chat-model.num-predict = 8192 | ||
quarkus.langchain4j.ollama.llama3.experimental-tools = true | ||
|
||
quarkus.langchain4j.ollama.mistral.chat-model.model-id = mistral | ||
quarkus.langchain4j.ollama.mistral.timeout = 60s | ||
quarkus.langchain4j.ollama.mistral.chat-model.temperature = 0.0 | ||
quarkus.langchain4j.ollama.mistral.experimental-tools = true | ||
|
||
quarkus.langchain4j.ollama.qwen2.chat-model.model-id = qwen2 | ||
quarkus.langchain4j.ollama.qwen2.timeout = 60s | ||
quarkus.langchain4j.ollama.qwen2.chat-model.temperature = 0.0 | ||
quarkus.langchain4j.ollama.qwen2.experimental-tools = true |
Oops, something went wrong.