Skip to content

Commit

Permalink
Review 1
Browse files Browse the repository at this point in the history
  • Loading branch information
humcqc committed Jun 10, 2024
1 parent c3c4776 commit 95e3d20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ void generateBeans(OllamaRecorder recorder,
var builder = SyntheticBeanBuildItem
.configure(CHAT_MODEL)
.setRuntimeInit()
.setRuntimeInit()
.defaultBean()
.scope(ApplicationScoped.class)
.supplier(recorder.chatModel(config, fixedRuntimeConfig, configName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ public interface MathAssistant {
@Test
@ActivateRequestContext
void test_multiple_tools() {
String msg = "What is the square root of the sum of the numbers of letters in the words " +
String msg = "What is the square root with maximal precision of the sum of the numbers of letters in the words " +
"\"hello\" and \"world\"";
String response = mathAssistant.chat(msg);
assertThat(response).contains("approximately 3.16");
assertThat(response).contains("3.162278");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class OllamaDefaultToolsHandler implements ToolsHandler {
You must always select one of the above tools and respond with a JSON object matching the following schema,
and only this json object:
{{
{
"tool": <name of the selected tool>,
"tool_input": <parameters for the selected tool, matching the tool's JSON schema>
}}
Do not use new tools, just use the ones from the list. Do not forget the parameters in tool_input field.
}
Do not use other tools than the ones from the list above. Always provide the "tool_input" field.
If several tools are necessary, answer them sequentially.
When the user provides sufficient information , answer with the __conversational_response tool.
When the user provides sufficient information, answer with the __conversational_response tool.
""");

static final ToolSpecification DEFAULT_RESPONSE_TOOL = ToolSpecification.builder()
Expand Down Expand Up @@ -93,8 +93,7 @@ public AiMessage getAiMessageFromResponse(ChatResponse response, List<ToolSpecif
// Extract tools
toolResponse = Json.fromJson(response.message().content(), ToolResponse.class);
} catch (Exception e) {
// No tools found
return AiMessage.from(response.message().content());
throw new RuntimeException("Ollama server did not respond with valid JSON. Please try again!");
}
// If the tool is the final result with default response tool
if (toolResponse.tool.equals(DEFAULT_RESPONSE_TOOL.name())) {
Expand All @@ -104,7 +103,7 @@ public AiMessage getAiMessageFromResponse(ChatResponse response, List<ToolSpecif
List<String> availableTools = toolSpecifications.stream().map(ToolSpecification::name).toList();
if (!availableTools.contains(toolResponse.tool)) {
return AiMessage.from(String.format(
"The LLM wants to call a tool %s that is not part of the available tools %s",
"Ollama server wants to call a tool '%s' that is not part of the available tools %s",
toolResponse.tool, availableTools));
}
// Extract tools request from response
Expand Down

0 comments on commit 95e3d20

Please sign in to comment.