Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

# OpenAI Tool Example: Square Root Calculator

This project demonstrates how to use the OpenAI API to create a simple tool for calculating the square root of a number. The tool interacts with the model to perform mathematical operations by utilizing defined functions.

## Features

- **Functionality**: The tool calculates the square root of a given number.
- **Environment Variables**: Uses `dotenv` to load environment variables, ensuring sensitive information such as API keys are kept secure.
- **Error Handling**: Includes error handling to manage situations where the function fails.
- **Modular Design**: Easily extendable to include more mathematical operations or other operations by adding new functions to the tool list.

## Requirements

- Python 3.x
- OpenAI Python client
- `dotenv` for environment variable management

## Setup

1. **Clone the Repository**:
   ```bash
   git clone https://github.com/bdeva1975/OpenAI-MathAPI
   cd OpenAI-MathAPI
  1. Install Dependencies:

    pip install openai python-dotenv
  2. Create a .env File: In the project directory, create a .env file and add your OpenAI API key:

    OPENAI_API_KEY=your_openai_api_key
  3. Run the Script:

    python tool_use.py

Usage

The script defines a tool that calculates the square root of a number. The user can modify the input number by changing the message in the message_list section.

Example

  • Input: "What is the square root of 49?"
  • Output: 7.0

License

This project is licensed under the MIT License.


Feel free to customize the README further based on your preferences or any additional features you might want to highlight!

About

This repository showcases integration with OpenAI's API using a custom mathematical tool to calculate the square root of a number. It highlights modular design for easy extension and includes error handling for robust performance, demonstrating effective interaction through tool calls.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages