Power your OpenAI assistant with custom tools!
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
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.
This project is intentionally built with a minimal set of dependencies, but it relies heavily on the following pieces of tech:
To get started with the Go OpenAI Toolkit, you will need to install the go language. You can find the installation instructions here.
This project requires no external prerequisites other than the Go language itself.
-
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
-
Add the toolkit to your project
go get -u github.com/emilkje/go-openai-toolkit
-
Create a new tool in the directory of your choice, here
./tools/weather.go
is used as an examplepackage 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) }
-
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 -
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.
- 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).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
This would have been much harder to create without the following projects: