Skip to content

Commit

Permalink
Update tools examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasVitale committed Jan 5, 2025
1 parent e7791af commit 9220693
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions patterns/function-calling/function-calling-ollama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ http :8080/chat/method/single authorName=="C.S. Lewis" -b
```shell
http :8080/chat/method/list bookTitle1=="Narnia" bookTitle2=="The Hobbit" -b
```

```shell
http :8080/chat/method/non-public authorName=="C.S. Lewis" -b
```
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,22 @@ String chatMethodList(String bookTitle1, String bookTitle2) {
.content();
}

@GetMapping("/chat/method/non-public")
String chatMethodNonPublic(String authorName) {
var userPromptTemplate = "What books written by {author} are available in the library?";
return chatClient.prompt()
.user(userSpec -> userSpec
.text(userPromptTemplate)
.param("author", authorName)
)
.functions(FunctionCallback.builder()
.method("findBooksByAuthor", String.class)
.description("Get the list of books written by the given author available in the library")
.targetObject(tools)
.build()
)
.call()
.content();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public List<BookService.Author> authorsByBooks(List<String> books) {
return bookService.getAuthorsByBook(books.stream().map(b -> new BookService.Book(b, "")).toList());
}

List<BookService.Book> findBooksByAuthor(String author) {
logger.info("Getting books by author: {}", author);
return bookService.getBooksByAuthor(new BookService.Author(author));
}

}
4 changes: 4 additions & 0 deletions patterns/function-calling/function-calling-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ http :8080/chat/method/single authorName=="C.S. Lewis" -b
```shell
http :8080/chat/method/list bookTitle1=="Narnia" bookTitle2=="The Hobbit" -b
```

```shell
http :8080/chat/method/non-public authorName=="C.S. Lewis" -b
```
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,22 @@ String chatMethodList(String bookTitle1, String bookTitle2) {
.content();
}

@GetMapping("/chat/method/non-public")
String chatMethodNonPublic(String authorName) {
var userPromptTemplate = "What books written by {author} are available in the library?";
return chatClient.prompt()
.user(userSpec -> userSpec
.text(userPromptTemplate)
.param("author", authorName)
)
.functions(FunctionCallback.builder()
.method("findBooksByAuthor", String.class)
.description("Get the list of books written by the given author available in the library")
.targetObject(tools)
.build()
)
.call()
.content();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public List<BookService.Author> authorsByBooks(List<String> books) {
return bookService.getAuthorsByBook(books.stream().map(b -> new BookService.Book(b, "")).toList());
}

List<BookService.Book> findBooksByAuthor(String author) {
logger.info("Getting books by author: {}", author);
return bookService.getBooksByAuthor(new BookService.Author(author));
}

}

0 comments on commit 9220693

Please sign in to comment.