botastic

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: MIT Imports: 11 Imported by: 7

README

botastic-go

A Go SDK package for botastic service. https://developers.pando.im/references/botastic/api.html

Example

package main

import (
	"context"

	"github.com/pandodao/botastic-go"
)

func main() {
	client := botastic.New("YOUR_APP_ID", "YOUR_APP_SECRET", botastic.WithHost("host..."), botastic.WithDebug(true))
	resp, err := client.SearchIndexes(context.Background(), botastic.SearchIndexesRequest{
		Keywords: "hello",
		N:        10,
	})
	if err != nil {
		panic(err)
	}

	for _, index := range resp.Items {
		println(index.ObjectID, index.Data)
	}
}

Options

  • WithHost - Set the custom host, the default host is our production environment service address.
  • WithDebug - The relevant request and response logs will be printed out.
  • WithLogger - Custom logger for debug log.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ID        uint64     `json:"id"`
	AppID     string     `json:"app_id"`
	CreatedAt *time.Time `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`
}

type Bot

type Bot struct {
	ID   uint64 `json:"id"`
	Name string `json:"name"`
}

type Client

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

func New

func New(appID, appSecret string, opts ...Option) *Client

func (*Client) CreateConversation

func (c *Client) CreateConversation(ctx context.Context, req CreateConversationRequest) (*Conversation, error)

func (*Client) CreateIndexes

func (c *Client) CreateIndexes(ctx context.Context, req CreateIndexesRequest) error

func (*Client) DeleteConversation

func (c *Client) DeleteConversation(ctx context.Context, conversationID string) error

func (*Client) DeleteIndex

func (c *Client) DeleteIndex(ctx context.Context, objectId string) error

func (*Client) GetConvTurn

func (c *Client) GetConvTurn(ctx context.Context, conversationID string, turnID uint64, blockUntilResponse bool) (*ConvTurn, error)

func (*Client) GetConversation

func (c *Client) GetConversation(ctx context.Context, conversationID string) (*Conversation, error)

func (*Client) PostToConversation

func (c *Client) PostToConversation(ctx context.Context, req PostToConversationPayloadRequest) (*ConvTurn, error)

func (*Client) SearchIndexes

func (c *Client) SearchIndexes(ctx context.Context, req SearchIndexesRequest) (*SearchIndexesResponse, error)

func (*Client) UpdateConversation

func (c *Client) UpdateConversation(ctx context.Context, req UpdateConversationRequest) error

type ConvTurn

type ConvTurn struct {
	ID               uint64     `json:"id"`
	ConversationID   string     `json:"conversation_id"`
	BotID            uint64     `json:"bot_id"`
	AppID            uint64     `json:"app_id"`
	UserIdentity     string     `json:"user_identity"`
	Request          string     `json:"request"`
	Response         string     `json:"response"`
	RequestToken     int        `json:"request_token"`
	ResponseToken    int        `json:"response_token"`
	PromptTokens     int        `json:"prompt_tokens"`
	CompletionTokens int        `json:"completion_tokens"`
	TotalTokens      int        `json:"total_tokens"`
	Status           int        `json:"status"`
	CreatedAt        *time.Time `json:"created_at"`
	UpdatedAt        *time.Time `json:"updated_at"`
}

type Conversation

type Conversation struct {
	ID           string      `json:"id"`
	Bot          *Bot        `json:"bot"`
	App          *App        `json:"app"`
	UserIdentity string      `json:"user_identity"`
	Lang         string      `json:"lang"`
	History      []*ConvTurn `json:"history"`
	ExpiredAt    time.Time   `json:"expired_at"`
}

type CreateConversationRequest

type CreateConversationRequest struct {
	BotID        uint64 `json:"bot_id"`
	UserIdentity string `json:"user_identity"`
	Lang         string `json:"lang"`
}

type CreateIndexesItem

type CreateIndexesItem struct {
	ObjectID   string `json:"object_id"`
	Category   string `json:"category"`
	Data       string `json:"data"`
	Properties string `json:"properties"`
}

type CreateIndexesRequest

type CreateIndexesRequest struct {
	Items []*CreateIndexesItem `json:"items"`
}

type Error

type Error struct {
	StatusCode int    `json:"-"`
	Code       int    `json:"code"`
	Msg        string `json:"msg"`
}

func (Error) Error

func (e Error) Error() string

type Index

type Index struct {
	Data       string  `json:"data"`
	ObjectID   string  `json:"object_id"`
	Category   string  `json:"category"`
	Properties string  `json:"properties"`
	CreatedAt  int64   `json:"created_at"`
	Score      float32 `json:"score"`
}

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
}

type Middleware

type Middleware struct {
	ID      uint64                 `json:"id"`
	Name    string                 `json:"name"`
	Options map[string]interface{} `json:"options"`
}

type Option

type Option func(*Client)

func WithDebug

func WithDebug(debug bool) Option

func WithHost

func WithHost(host string) Option

func WithLogger

func WithLogger(logger Logger) Option

type PostToConversationPayloadRequest

type PostToConversationPayloadRequest struct {
	ConversationID string `json:"-"`
	Content        string `json:"content"`
	Category       string `json:"category"`
}

type SearchIndexesRequest

type SearchIndexesRequest struct {
	Keywords string
	N        int
}

type SearchIndexesResponse

type SearchIndexesResponse struct {
	Items []*Index `json:"items"`
}

type UpdateConversationRequest

type UpdateConversationRequest struct {
	ConversationID string `json:"-"`
	Lang           string `json:"lang"`
}

Jump to

Keyboard shortcuts

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