Git Product home page Git Product logo

openaifunctionsplayground's Introduction

GPT Function Playground

This repository contains a simple Python playground for testing the custom function functionality of OpenAI's GPT models, such as gpt-3.5-turbo and gpt-4. The code demonstrates how to use the Chat Completions API to define and call custom functions using the model's generated responses.

The sample code includes a basic chatbot that can perform addition and subtraction using user-defined functions. It showcases how to define functions, send them to the Chat Completions API, check if the model wants to call a function, execute the function, and send the function response back to the model.

Requirements

  • Python 3.6 or later
  • OpenAI Python package: pip install openai

Setup

  1. Clone this repository.
  2. Obtain an API key from OpenAI by signing up at https://platform.openai.com/signup.
  3. Set the OPENAI_API_KEY environment variable with your API key.
  4. Run python main.py and start chatting with the assistant.

Usage

  • Type your messages as input to interact with the chatbot.
  • Ask the assistant to perform addition or subtraction, for example:
    • "What's the sum of 5 and 3?"
    • "Subtract 7 from 10."
  • Type 'exit' to end the conversation.

Extending the Code

Feel free to modify the code and add your own custom functions. To do so, follow these steps:

  1. Define your new function in the code.
  2. Add the function definition to the functions list, including the name, description, and parameters.
  3. Update the function call handling section of the code to execute your new function when it's called by the model.

Remember to follow the guidelines and limits of the Chat Completions API when defining and using custom functions. Enjoy experimenting with the GPT Function Playground! It's super fun!

openaifunctionsplayground's People

Contributors

doriandarko avatar

Stargazers

 avatar Kala avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.