Skip to content

Commit

Permalink
update READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
rderbier committed Nov 21, 2024
1 parent 5eda607 commit ea69aa7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ The following recipes have associated recorded content:
| [modushack-data-models](modushack-data-models/) | [ModusHack: Working With Data & AI Models livestream](https://www.youtube.com/watch?v=gB-v7YWwkCw&list=PLzOEKEHv-5e3zgRGzDysyUm8KQklHQQgi&index=3) |
| [modus-press](modus-press/) | Coming soon |
| [dgraph-101](dgraph-101/) | Coming soon |
| [function-calling](function-calling/) | Coming soon |
50 changes: 33 additions & 17 deletions function-calling/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Function Calling With Modus

LLM apis such as OpenAI, have a feature called **function calling** or **tool use**. With this feature the LLM response to a chat message could be a request to invoke a function, usually in order to collect information necessary to generate a response.

This project demonstrates how to setup function calling within [Modus](https://docs.hypermode.com/modus), the open source framework for building intelligent APIs.

The example implements a function `askQuestionToWarehouse` accepting an query in natural language about prices or stock of goods in the warehouse.

The API uses 2 tools available for the LLM
- get_product_types: provide the list of product types we have in the warehouse
- get_product_info: return an info (qty or price) about one product type



## Get started

1- Set your credentials
Expand All @@ -20,43 +32,47 @@ modus dev
From a GraphQL client (Postman),
Introspect the GraphQL endpoint `http://localhost:8686/graphql`
Invoke the operation `askQuestionToWarehouse`
Experiment with some queries to see the function tools at work.

The operation replies with an array of strings showing the steps used to produce a response along with the final response.
```graphql
# example query using tool calling

query AskQuestion {
askQuestionToWarehouse(
question: "What is the most expensive product?") {
response
logs
}
}

```
The operation returns the final response and an array of strings showing showing the tool calls and messages exchanged with the LLM API.

Experiment with some queries to see the function calling at work.



```text
# example of questions
What can you do for me?
what fo we have in the warehouse?
How many shoes in stock?
How many shoes and hats do we have in stock?
What is the most expensive product in stock?
what is the price of a desks?
What is the most expensive product in stock?
```



## About

LLM apis such as OpenAI, have a feature called **function calling** or **tool use**. With this feature the LLM response to a chat message could be a request to invoke a function, usually in order to collect information necessary to generate a response.

This project demonstrates how to setup function calling within Modus when using openAI chat/completion API or any models supporting the same API.


In our case, we are implementing a function `askQuestionToWarehouse` accepting an query in natural language about prices or stock of goods in the warehouse.

We are declaring 2 tools available for the LLM
- getProductList: provide the list of product types we have in the warehouse
-
## Details

The logic is as follow:

- Instruct the LLM to use function calls (tools) with the correct parameters to get the data necessary to reply to the provided question.

- Execute the identified function calls in Modus to build an additional context.
- Execute the identified function calls in Modus to build an additional context (tool messages)

- Re-invoke the LLM API with the additional context.
- Re-invoke the LLM API with the additional tool messages.

Return the generated responses based on the data retrieved by the function calls.

Expand Down

0 comments on commit ea69aa7

Please sign in to comment.