Skip to content

emilkje/go-openai-toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Go OpenAI Toolkit

Power your OpenAI assistant with custom tools!
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

The sashabaranov/go-openai library is a great starting point for creating your first OpenAI project. However, it lacks a lot of the tools and features that are necessary to get started with a proper agent.

This project aims to provide a toolkit for developers to get started with creating their own OpenAI assistants powered by their own custom tools. The toolkit includes a variety of features such as:

  • Code Generator: Create dead simple tool structs and let the code generator generate the OpenAI function specs
  • Runtime: A runtime that will handle the conversation loop and call the appropriate tools
  • go-openai integration: Compatible with messages from go-openai library

Of course, this is just the beginning. I hope to add more features and built-in tools to the toolkit as time goes on. See the roadmap for more information.

(back to top)

Built With

This project is intentionally built with a minimal set of dependencies, but it relies heavily on the following pieces of tech:

(back to top)

Getting Started

To get started with the Go OpenAI Toolkit, you will need to install the go language. You can find the installation instructions here.

Prerequisites

This project requires no external prerequisites other than the Go language itself.

Installation

  1. The code generator is strictly optional, but it is recommended to use it to generate the tool definitions. You can install it by running the following command:

    go install github.com/emilkje/go-openai-toolkit/cmd/toolkit-tools-gen@latest
  2. Add the toolkit to your project

    go get -u github.com/emilkje/go-openai-toolkit

(back to top)

Usage

  1. Create a new tool in the directory of your choice, here ./tools/weather.go is used as an example

    package tools
    
    import (
        "fmt"
        "github.com/emilkje/go-openai-toolkit/toolkit"
    )
    
    type WeatherToolArgs struct {
        Location string `json:"location" desc:"The location to get the weather for."`
    }
    
    // WeatherTool is a tool that greets a person
    // +tool:name=weather_tool
    // +tool:description=WeatherTool reports the current weather for a location
    type WeatherTool struct {
        toolkit.Tool[WeatherToolArgs]
    }
    
    func (g *WeatherTool) Execute() string {
        location := g.GetArguments().Location
        return fmt.Sprintf("It's sunny with a temperature of 21C in %s", location)
    }
  2. Generate the tool specs

    toolkit-tools-gen -path ./tools

    or use the go generate directive in your main file

    //go:generate toolkit-tools-gen -path ./tools

    and run go generate ./... in the root of your project

  3. Register the tool in a toolkit and kick off the runtime

    package main
    
    import (
        toolkit_runtime "github.com/emilkje/go-openai-toolkit/runtime"
        "github.com/emilkje/go-openai-toolkit/toolkit"
        "github.com/emilkje/go-openai-toolkit/tools"
        "github.com/sashabaranov/go-openai"
    )
    
    func main() {
        // The toolkit holds a collection of tools
        tk := toolkit.NewToolkit()
        // Register your tool with the toolkit
        tk.RegisterTool(tools.NewWeatherTool())
    
        // client setup is omitted for brevity
        client := openai.NewClientWithConfig(newConfigFromEnv())
    
        // Initialize the runtime with the client and toolkit
        runtime := toolkit_runtime.NewRuntime(client, tk)
    
        messages := []openai.ChatCompletionMessage{
            {
                Role:    openai.ChatMessageRoleSystem,
                Content: "You are a helpful assistant",
            },
            {
                Role:    openai.ChatMessageRoleUser,
                Content: "What is the weather in Oslo?",
            },
        }
    
        // The runtime handles the conversation and tool-calling loop
        chatLog, err := runtime.ProcessChat(messages)
    }

    Note: To see a full example, check out the example directory.

(back to top)

Roadmap

  • Create a basic toolkit
  • Code generator for tools
  • Runtime for handling the conversation loop
  • Provide a streaming interface for the runtime
  • Add Changelog

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Acknowledgments

This would have been much harder to create without the following projects:

(back to top)

About

Power your OpenAI assistant with custom tools

Resources

License

Stars

Watchers

Forks

Packages

No packages published