bot

package
v0.0.0-...-b9ed496 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package bot contains the core logic for TorontoBot which is shared across host platforms.

Index

Constants

View Source
const (
	// Model is the openai model to query. GPT-4 is expensive, so we use GPT-3.5.
	//Model = openai.GPT4
	Model = openai.GPT3Dot5Turbo
	// RespTemp is the response temperature we want from the model. Default temp is 1.0 and higher
	// is more "creative".
	RespTemp = 0.1
)

Variables

View Source
var ChartSelectFunction = openai.FunctionDefinition{
	Name:        "select_chart",
	Description: "Selects a chart type and foramts data to be used in the chart.",
	Parameters: jsonschema.Definition{
		Type: jsonschema.Object,
		Properties: map[string]*jsonschema.Definition{
			"type": {
				Type:        jsonschema.String,
				Description: "Selected type of chart for this data.",
				Enum:        []string{"bar", "stacked-bar", "line", "pie"},
			},
			"title": {
				Type:        jsonschema.String,
				Description: "Title for the chart.",
			},
			"data": {
				Type: jsonschema.Array,
				Items: &jsonschema.Definition{
					Type: jsonschema.Object,
					Properties: map[string]*jsonschema.Definition{
						"name": {
							Type:        jsonschema.String,
							Description: "Name of the data entry.",
						},
						"date": {
							Type:        jsonschema.Number,
							Description: "Year of the data entry.",
						},
						"value": {
							Type:        jsonschema.Number,
							Description: "Value of the data entry.",
						},
					},
					Required: []string{"value"},
				},
			},
			"is_currency": {
				Type:        jsonschema.Boolean,
				Description: "Whether the data value represents money/currency amount or not.",
			},
		},
		Required: []string{"type", "title", "data", "is_currency"},
	},
}
View Source
var SQLAnalysisFunction = openai.FunctionDefinition{
	Name:        "sql_analysis",
	Description: "Accepts SQL query analysis derived from user queries.",
	Parameters: jsonschema.Definition{
		Type: jsonschema.Object,
		Properties: map[string]*jsonschema.Definition{
			"schema": {
				Type:        jsonschema.String,
				Description: "1 to 2 sentences about which columns from the schema to use.",
			},
			"applicability": {
				Type:        jsonschema.String,
				Description: "1 to 2 sentences about which columns and enums are relevant, or which ones are missing.",
			},
			"sql": {
				Type:        jsonschema.String,
				Description: "A single-line SQL query to run. Remember to escape any special characters",
			},
			"result_is_currency": {
				Type:        jsonschema.Boolean,
				Description: "Whether the result of the query is a currency value.",
			},
		},
		Required: []string{"schema", "applicability", "sql", "result_is_currency"},
	},
}

Functions

This section is empty.

Types

type ChartSelectResponse

type ChartSelectResponse struct {
	Chart           string           `json:"type"`
	Title           string           `json:"title"`
	Data            []*viz.DataEntry `json:"data"`
	ValueIsCurrency bool             `json:"is_currency"`
}

type ChartType

type ChartType int
const (
	ChartTypeUnknown ChartType = iota
	ChartTypeBar
	ChartTypeLine
	ChartTypePie
	ChartTypeScatter
)

type DataTable

type DataTable struct {
	Name         string                       `json:"name"`
	Desc         string                       `json:"description"`
	Schema       string                       `json:"schema"`
	Enums        map[string][]interface{}     `json:"enums"`
	Hints        map[string]map[string]string `json:"hints"`
	Instructions string                       `json:"instructions"`
}

func (*DataTable) EmbeddingText

func (t *DataTable) EmbeddingText() string

type MsgTemplate

type MsgTemplate struct {
	Role         string               `json:"role"`
	Name         string               `json:"name"`
	Content      string               `json:"content"`
	FunctionCall *openai.FunctionCall `json:"function_call"`
	// contains filtered or unexported fields
}

func (*MsgTemplate) Parse

func (t *MsgTemplate) Parse() error

type SQLResponse

type SQLResponse struct {
	Schema        string `json:"schema"`
	Applicability string `json:"applicability"`
	SQL           string `json:"sql"`
	IsCurrency    bool   `json:"result_is_currency"`
	MissingData   string `json:"missing_data"`
}

type TorontoBot

type TorontoBot struct {
	Hostname string
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, db *sql.DB, ai *openai.Client, store *citygraph.Store, host string) (*TorontoBot, error)

func (*TorontoBot) HasGraphStore

func (b *TorontoBot) HasGraphStore() bool

func (*TorontoBot) LoadResults

func (b *TorontoBot) LoadResults(sqlQuery string, isCurrency bool) (string, error)

func (*TorontoBot) SQLAnalysis

func (b *TorontoBot) SQLAnalysis(ctx context.Context, table *DataTable, question string) (*SQLResponse, error)

func (*TorontoBot) SaveToGraph

func (b *TorontoBot) SaveToGraph(ctx context.Context, id, title, body, chartJS, featureImage, user string) (string, error)

func (*TorontoBot) SelectChart

func (b *TorontoBot) SelectChart(ctx context.Context, question, dataTable string) (*ChartSelectResponse, error)

func (*TorontoBot) SelectTable

func (b *TorontoBot) SelectTable(ctx context.Context, question string) (*DataTable, error)

Jump to

Keyboard shortcuts

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