Skip to main content

openai-api-with-easy-tools-and-web-browsing

An unofficial OpenAI library for Python, featuring an integrated Bing Custom Search API for web browsing (free) and easy-to-use custom tools.

Here is an example of capabilities of this library:

If you ask the program: Can you search the internet for the population of Paris and New York in the year 2015, then add the two values together and tell me the result, and then add 10,000,000 to that result

The response, using a web search and a custom tool to add two numbers, should be something like: The total population of Paris and New York in 2015 was about 31,082,144 inhabitants. If 10,000,000 is added to this number, it becomes 41,082,144.

See code below to reproduce this example.

First, get an API key from OpenAI here and get a Bing Custom Search API key, which you can get here (free for limited use)

Then, get the library with pip: pip install openai-api-with-easy-tools-and-web-browsing

And then, you can use the following code to get started:

import openai_api_with_easy_tools_and_web_browsing as webBrowsingApiGPT

# Enter our API keys
subscriptionKey = ""
openAIAPIKey = ""

### Creation of the Bing search tool ###

# Create a Bing search engine that synthesizes results with GPT-3.5-turbo
bingSearchEngine = webBrowsingApiGPT.BingSearchEngine(openAIAPIKey, subscriptionKey, model="gpt-3.5-turbo")
# Rename the Bing search function (otherwise it does not work as a tool in the OpenAI API)
bingSearch = bingSearchEngine.bingSearch
# Take the already made Bing search function description (the function must be named 'bingSearch')
bingSearchDescription = webBrowsingApiGPT.BING_SEARCH_DESCRIPTION

### Creation of the addition tool ###

def adder(a, b):
    """This function adds two numbers together"""
    return (str(a + b))

adderDescription = {
    "type": "function",
    "function": {
        "name": "adder",
        "description": "Add two numbers together",
        "parameters": {
            "type": "object",
            "properties": {
                "a": {
                    "type": "integer",
                    "description": "The first number to add"
                },
                "b": {
                    "type": "integer",
                    "description": "The second number to add"
                },
            },
            "required": ["a", "b"]
        }
    }
}

# Create an instance of the 'OpenaiApiWithEasyToolsAndWebBrowsing' class
openaiApiWithEasyToolsAndWebBrowsing = webBrowsingApiGPT.OpenaiApiWithEasyToolsAndWebBrowsing(openAIAPIKey)

### Return a response to a prompt in 'ponctual' mode ###
print("PONCTUAL MODE\n")
prompt = "Can you search the internet for the population of Paris and New York in the year 2015, then add the two values together and tell me the result, and then add 10,000,000 to that result"
# Use the 'getLLMAnswerWithWebBrowsingAndTools' function to get a response from a user message
answer = openaiApiWithEasyToolsAndWebBrowsing.getLLMAnswer(prompt, systemMessage="You are a helpful assistant", model="gpt-3.5-turbo", mode="ponctual",
                                                           toolList=[bingSearch, adder], toolDescriptionList=[bingSearchDescription, adderDescription],
                                                           temperature=0.9, top_p=1,
                                                           verbosity=1)
# The response, using a web search and a custom tool to add two numbers, should be something like:
# "The total population of Paris and New York in 2015 was about 31,082,144 inhabitants.
# If 10,000,000 is added to this number, it becomes 41,082,144."
print(answer)

### Discussion in 'continuous' mode ###
print("\n\n\nCONTINUOUS MODE\n")
openaiApiWithEasyToolsAndWebBrowsing.getLLMAnswer(None, systemMessage="You are a helpful assistant", model="gpt-4o", mode="continuous",
                                                  toolList=[bingSearch, adder], toolDescriptionList=[bingSearchDescription, adderDescription],
                                                  max_prompt_tokens=4096, max_completion_tokens=2048,
                                                  verbosity=1)

Metadata

Release files for openai-api-with-easy-tools-and-web-browsing 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-api-with-easy-tools-and-web-browsing 1.0.7
File Size Uploaded
openai_api_with_easy_tools_and_web_browsing-1.0.7.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-api-with-easy-tools-and-web-browsing 1.0.7
File Interpreter ABI Platform
openai_api_with_easy_tools_and_web_browsing-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / openai_api_with_easy_tools_and_web_browsing-1.0.7.tar.gz

Download URL openai_api_with_easy_tools_and_web_browsing-1.0.7.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ee0970567147481f6b56b9949917ec2f33772db264cda473bd86c41e20efe831
BLAKE2b-256 checksum
How to use checksums
15e931aacd6eba2cd152e1826ed22b9890824756eec9132acb4153455c4997f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.13

Release files / openai_api_with_easy_tools_and_web_browsing-1.0.7-py3-none-any.whl

Download URL openai_api_with_easy_tools_and_web_browsing-1.0.7-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
689b9bdec75d959e22e0c9716172c485186ffaf04726e90d23ff769b43230dd0
BLAKE2b-256 checksum
How to use checksums
c22e3f6f6434921c62773ce421b26c02842a77af13f8e6ce41fac729c3fc4175
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.0.7 This release

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page