Code Monkey home page Code Monkey logo

function-gpt's Introduction

Function-GPT

This is a typescript library that helps handle function calling with OpenAI.

NPM Build Status codecov MIT License

  • Uses typescript decorators to provide metadata for function calling
  • Automatically generate function calling JSON schema from decorated typescript functions
  • Automatically call functions based on name and JSON-formatted arguments
  • Can be used with OpenAI's Chat Completion API as well as the Assistants API

Example

import { gptFunction, gptString, FunctionCallingProvider } from 'function-gpt';

// Define the type of the input parameter for functions above.
class BrowseParams {
  // Decorate each field with @gptObjectField to provide necessary metadata.
  @gptString('url of the web page to browse')
  public url!: string;
}

// Create your own class that extends FunctionCallingProvider.
class BrowseProvider extends FunctionCallingProvider {
  // Define functions that you want to provide to OpenAI for function calling.
  // Decorate each function with @gptFunction to provide necessary metadata.
  // The function should accept a single parameter that is a typed object.
  @gptFunction('make http request to a url and return its html content', BrowseParams)
  async browse(params: BrowseParams) {
    const response = await fetch(params.url);
    return await response.text();
  }
}

const provider = new BrowseProvider();

const schema = await provider.getSchema();
const result = await provider.handleFunctionCall(
  'browse',
  JSON.stringify({ url: 'https://www.google.com' }),
);

API References

See API references for more detailed information on how to use the library.

Installation

npm install function-gpt --save
# or
yarn add function-gpt
# or
pnpm add function-gpt

Contributing

Contributions are welcome! See CONTRIBUTING.md for more info.

function-gpt's People

Contributors

atinylittleshell avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.