datacircle

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Datacircle tools for go-openai

Find the best GTM APIs. We benchmark all the GTM APIs and we put the results on our website: https://datacircle.dev

This Go module gives go-openai four function tools on Datacircle's open API, https://api.datacircle.dev/v1. You need no key and no account.

Tool What the tool gives Call
datacircle_list_apis Every GTM API on Datacircle, with the API's slug, number of plans, number of providers and best plan GET /apis
datacircle_best_plans One API's plans, sorted by score out of 100, best first. Each plan comes with a rank and a price per 1,000 calls GET /apis/{slug}/best
datacircle_search_plans Plans that match a provider or plan name, on all APIs or on one API. Sort by score, provider or price GET /plans
datacircle_provider The APIs a provider sells, and the provider's rank on each API GET /providers/{slug}

Install

go get github.com/waynehamadi/go-openai-datacircle

It needs go-openai v1.20.0 or later, and v1.42.0 or later for the Responses API.

Chat completions

Tools gives the four tools for a request's Tools. Call runs a tool call of the model's message into the tool message that answers it.

import datacircle "github.com/waynehamadi/go-openai-datacircle"

client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
tools := datacircle.New(nil)
messages := []openai.ChatCompletionMessage{
	{Role: openai.ChatMessageRoleUser, Content: "Find the 3 best providers for the email-finder API."},
}
for {
	resp, err := client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
		Model:    "gpt-5",
		Messages: messages,
		Tools:    tools.Tools(),
	})
	if err != nil {
		log.Fatal(err)
	}
	msg := resp.Choices[0].Message
	messages = append(messages, msg)
	if len(msg.ToolCalls) == 0 {
		fmt.Println(msg.Content)
		break
	}
	for _, call := range msg.ToolCalls {
		answer, _ := tools.Call(ctx, call)
		messages = append(messages, answer)
	}
}

Your own tools can go in the same request: append(tools.Tools(), yours...). Call gives false for a call of a tool that isn't one of the four, so you run it yourself. Handles(name) says the same before a call. A streamed reply works the same way: put each tool call together from its pieces, then give it to Call.

Responses API

Functions gives the four tools' function definitions, and openai.NewResponseFunctionTool makes each one a tool. Outputs runs the function calls of a response and gives a function_call_output item for each one.

var defs []openai.ResponseTool
for _, f := range tools.Functions() {
	defs = append(defs, openai.NewResponseFunctionTool(f))
}
input := []any{openai.ResponseInputMessage{Role: "user", Content: "Find the 3 best providers for the email-finder API."}}
for {
	resp, err := client.CreateResponse(ctx, openai.CreateResponseRequest{Model: "gpt-5", Input: input, Tools: defs})
	if err != nil {
		log.Fatal(err)
	}
	outputs := tools.Outputs(ctx, resp.Output)
	if len(outputs) == 0 {
		fmt.Println(resp.GetOutputText())
		break
	}
	input = append(append(input, resp.Output...), outputs...)
}

OpenAI also takes only the outputs with PreviousResponseID: resp.ID. Outputs gives nothing for a call of another function, so you run those yourself.

Call a tool yourself

out, err := datacircle.New(nil).Run(ctx, datacircle.BestPlansName, `{"slug":"email-finder","limit":3}`)

Each tool gives back a JSON object. Each plan comes with its rank, provider, plan, score, price per 1,000 (perThousand, in dollars) and its page on datacircle.dev. That page lists every field. A tool also takes an API's or a provider's name where it asks for a slug.

When the API gives no data, like for a slug it doesn't know, Call and Outputs give the model {"error": "..."} with the API's own words and what to send instead, so the model can call again. A network failure is given the same way. Run gives both as its error.

datacircle.Config sets the HTTPClient the tools use (a timeout, a proxy). nil uses http.DefaultClient.

Network

Each tool call makes one HTTPS GET request to https://api.datacircle.dev/v1 and nothing else. The request holds only the tool's own arguments: no key, no config, nothing from your chats. The API takes up to 60 calls a minute from one IP address. The tool waits once, for a minute at most, when the API asks the tool to wait. The module depends only on go-openai and golang.org/x/text, and stores nothing.

MIT license.

Documentation

Overview

Package datacircle gives go-openai four function tools on Datacircle's open API: find the best GTM APIs.

The API needs no key: https://api.datacircle.dev/v1 (its spec: https://api.datacircle.dev/v1/openapi.json). More at https://datacircle.dev

Index

Constants

View Source
const (
	ListAPIsName    = "datacircle_list_apis"
	BestPlansName   = "datacircle_best_plans"
	SearchPlansName = "datacircle_search_plans"
	ProviderName    = "datacircle_provider"
)
View Source
const BaseURL = "https://api.datacircle.dev/v1"

BaseURL is the API's address.

View Source
const Version = "0.1.1"

Version is this module's version, sent in each call's User-Agent.

Variables

Names are the four tools' names, in the order Tools and Functions give them.

Functions

This section is empty.

Types

type BestPlansInput

type BestPlansInput struct {
	Slug  string `json:"slug"`
	Limit Count  `json:"limit,omitempty"`
}

BestPlansInput is datacircle_best_plans' input.

type Config

type Config struct {
	BaseURL    string
	HTTPClient *http.Client
}

Config sets where the tools call. Its zero value, or nil, calls BaseURL with http.DefaultClient.

type Count

type Count int

Count is a whole number a model may send as a number, as text ("3") or as null, which is 0: left out.

func (*Count) UnmarshalJSON

func (n *Count) UnmarshalJSON(b []byte) error

type ListAPIsInput

type ListAPIsInput struct {
	Query string `json:"query,omitempty"`
	Limit Count  `json:"limit,omitempty"`
}

ListAPIsInput is datacircle_list_apis' input.

type ProviderInput

type ProviderInput struct {
	Slug  string `json:"slug"`
	Limit Count  `json:"limit,omitempty"`
}

ProviderInput is datacircle_provider's input.

type SearchPlansInput

type SearchPlansInput struct {
	API    string `json:"api,omitempty"`
	Query  string `json:"query,omitempty"`
	Sort   string `json:"sort,omitempty"`
	Limit  Count  `json:"limit,omitempty"`
	Offset Count  `json:"offset,omitempty"`
}

SearchPlansInput is datacircle_search_plans' input.

type Toolset

type Toolset struct {
	// contains filtered or unexported fields
}

Toolset runs the four tools: datacircle_list_apis, datacircle_best_plans, datacircle_search_plans and datacircle_provider. Its methods are safe to call from many goroutines.

func New

func New(cfg *Config) *Toolset

New gives the four tools, calling where cfg says: nil calls BaseURL with http.DefaultClient.

func (*Toolset) Call

Call runs a tool call of an assistant message, one of its ToolCalls, into the tool message that answers it: its result as JSON, or {"error": ...} with the API's words or the failure's, which the model reads and can call again on. Its false is a call of none of the four tools, for the app to run.

func (*Toolset) Functions

func (t *Toolset) Functions() []openai.FunctionDefinition

Functions gives the four tools' function definitions: each one's name, description and parameters (a JSON schema). For the Responses API (go-openai v1.42.0 and later), openai.NewResponseFunctionTool makes each one a tool.

func (*Toolset) Handles

func (t *Toolset) Handles(name string) bool

Handles says whether name is one of the four tools'.

func (*Toolset) Outputs

func (t *Toolset) Outputs(ctx context.Context, output []any) []any

Outputs runs the function calls of a Responses API response, its Output, that call the four tools, and gives the function_call_output item of each, for the next request's Input. An item of another kind, or a call of another function, gives none: the app runs it.

func (*Toolset) Run

func (t *Toolset) Run(ctx context.Context, name, arguments string) (string, error)

Run calls one tool by its name on the model's arguments, a JSON object, and gives its result as JSON. A call the API answers with no data, like for a slug it doesn't know, or one the tool can't make, gives an error whose words tell the model what to send instead.

func (*Toolset) Tools

func (t *Toolset) Tools() []openai.Tool

Tools gives the four tools for a chat completion request's Tools, each a function tool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL