Coder Social home page Coder Social logo

rasputin2 / rag_plus_function_tools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bianbianzhu/openai-function-calling

0.0 0.0 0.0 1.12 MB

This repo does a deep dive specifically on passing function tools together with the RAG.

License: MIT License

JavaScript 2.19% TypeScript 97.81%

rag_plus_function_tools's Introduction

Farm trip agent with Openai Function calling

Introduction

This project utilizes OpenAI's function calling feature to build a farm trip agent. The agent can help users to find the farms near a location, get the detailed information of the available activities in the farm, and book the activity.

Documentation

There is an detailed Medium article about this project. You can find it here.

If you want to know more about the function calling feature, you can refer to the following links:

openai doc

step by step guide

Quick Start

  1. Clone the repository
  2. Run yarn to install the dependencies
  3. Create a .env file in the root directory and add the following environment variable(s): OPENAI_API_KEY
  4. Run yarn dev to start the application
  5. Run yarn test to run the tests

Please use node version 18 or above.

There is also a script to generate function files from the function description. You can run yarn function:generate to generate the function files. Make sure you run yarn dev before running this script.

Add a new function

To introduce a new function, proceed as follows:

  1. Extend DescribedFunctionName with a new enum, such as DoNewThings.
export enum DescribedFunctionName {
  GetFarm = 'get_farm',
  ...
  DoNewThings = 'do_new_things'
}
  1. Define a Props type for the parameters, e.g., DoNewThingsProps.
export type DoNewThingsProps = {
  param_1: PropBase<"number">;
  param_2: PropBase<"boolean">;
};
  1. Insert a new entry in the functionDescriptionsMap object, and use the FunctionParametersNarrowed type to narrow down the type of the parameters.
export const functionDescriptionsMap: Record<DescribedFunctionName, FunctionDefinition> = {
  ...
  [DescribedFunctionName.DoNewThings]: {
    name: DescribedFunctionName.DoNewThings,
    description: 'Do new things with the parameters.',
    parameters: {
      type: 'object',
      properties: {
        param_1: {
          type: 'number',
          description: 'The first parameter.',
        },
        param_2: {
          type: 'boolean',
          description: 'The third parameter.',
        },
      },
      required: ['param_1', 'param_2'],
    },
  } satisfies FunctionParametersNarrowed<DoNewThingsProps>,
};
  1. Implement the new function in the function directory, naming it after the enum value.
export async function do_new_things(
  args: ConvertedFunctionParamProps<DoNewThingsProps>
): Promise<string> {
  const { param_1, param_2 } = args;
  return JSON.stringify({
    param_1,
    param_2,
  });
}

The required keys for FunctionDefinition:

  • name: The name of the function.
  • description: A description of the function.
  • parameters: An object which represents the parameters of the function. It contains type, description, and required keys.
    • type: The type of the parameter(s). It is normally object.
    • properties: An object that shows all the parameters as its keys. Each key is paired with an object that contains type and description keys, to describe the parameter.
    • required: An array of required parameters.

License

This project is licensed under the MIT License

rag_plus_function_tools's People

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.