This example shows how to use Custom Tools using the Azure OpenAI service.
- Node.js >=18
- Npm or Yarn
- An active subscription with Azure OpenAI
git clone <this-repo>
.- Install dependencies by running
yarn
ornpm install
in the project root directory.
Rename or copy .env.sample
to .env
AZURE_OAI_RESOURCE_NAME="xxx-xxx-xxx-xxx"
AZURE_OAI_API_KEY="xxxxxxxxxxxx"
AZURE_OAI_API_VERSION="xxxx-xx-xx"
AZURE_OAI_DEPLOYMENT_NAME="the-deployment-name"
In this example we are asking the model to check the weather and reply strictly in JSON format with some clothing tips. The System prompt can be found in ./prompts/system.mjs
. Edit the prompt as per your requirements.
To add a new tool:
- Add the tool definitions in
./tools/definitions.mjs
. - Add the tool function in
./tools/functions
.
The getCurrentWeather
function fetches weather data for a specified location. It's invoked through the tool system during a conversation.
The function:
const theQuestion =
"What's the weather like in San Francisco, Tokyo, and Paris?";
askAI(theQuestion)
.then((response) => {
//response.choices[0].message.content
console.log(response);
})
.catch(console.error);
Run the script:
node index.mjs
This project is licensed under the MIT License.
For support, open an issue in the GitHub repository or contact the project maintainers.