diff --git a/README.md b/README.md index 92236c3..afb81bd 100644 --- a/README.md +++ b/README.md @@ -125,10 +125,43 @@ if (response.data.choices[0].finish_reason === "function_call") { } ``` -<details><summary>Full example code about import { GoogleCustomSearch } from 'openai-function-calling-tools'; -</summary> -Just 3 steps to use the tools in your OpenAI API project. -<p> +### Example 2: Function Calls with Google Custom Search + +> 📝 Note: You need to apply for a Google Custom Search API key and a Google Custom Search Engine ID to use this tool. + +#### The following is a sequence diagram of the example +```mermaid +sequenceDiagram + participant U as User + participant M as Main Function + participant O as OpenAI API + participant F as Functions Object + participant GC as Google Custom Search + + U->>M: Execute main function + M->>M: Initialize configuration and API + M->>M: Define QUESTION variable + M->>M: Create Google Custom Search tool + M->>F: Add tool to functions object + loop Chat Completion Loop + M->>O: Request chat completion + O-->>M: Return response + alt If finish reason is "stop" + M->>U: Display answer and exit loop + else If finish reason is "function_call" + M->>M: Parse function call name and arguments + M->>F: Invoke corresponding function + F->>GC: Perform Google Custom Search + GC-->>F: Return search results + F->>M: Receive function result + M->>M: Add result to message queue + M->>M: Output function call details + else Other cases + M->>M: Continue loop + end + end +``` +#### Code ```js const { Configuration, OpenAIApi } = require("openai"); @@ -214,10 +247,8 @@ const main = async () => { main(); ``` -</p> -</details> -### Example 2: Schema Extraction +### Example 3: Schema Extraction Example to extract schema from a function call