server

package
v0.0.0-...-f8036e4 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Unlicense Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flatten

func Flatten(data any) string

Flatten data with each sentence on a new line

func Split

func Split(prefix, text string, ctxNum int) (list []string)

Types

type ChatRequest

type ChatRequest struct {
	Prefix      string   `json:"prefix,omitempty"`
	History     []string `json:"history,omitempty"`
	Text        string   `json:"text"`
	DocumentIDs []uint64 `json:"document_ids,omitempty"`
	Documents   []any    `json:"documents,omitempty"`
}

type DocumentSearch

type DocumentSearch struct {
	DocumentUpload
	DocumentID         uint64  `json:"document_id"`
	DocumentSimilarity float32 `json:"document_similarity"`
}

type DocumentUpload

type DocumentUpload struct {
	Name       string `json:"name,omitempty"`
	ExternalID string `json:"external_id,omitempty"`
	Document   any    `json:"document"`
}

type FetchCategoryNamesRequest

type FetchCategoryNamesRequest struct {
	Owner string `json:"owner"`
}

type FetchCategoryNamesResponse

type FetchCategoryNamesResponse struct {
	CategoryNames []string `json:"category_names"`
}

type SearchRequest

type SearchRequest struct {
	Owner     string `json:"owner"`
	Category  string `json:"category"`
	Text      string `json:"text"`
	Count     uint   `json:"count"`
	Offset    uint   `json:"offset,omitempty"`
	Centroids int    `json:"centroids,omitempty"`
}

type SearchResponse

type SearchResponse struct {
	Documents []DocumentSearch `json:"documents"`
}

type Server

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

func New

func New(appCtx context.Context, cfg config.Config, db *database.Database, ai ai.AI) *Server

func (*Server) Chat

func (s *Server) Chat(ctx context.Context, req ChatRequest) (resStream io.ReadCloser, err error)

Chat handles a chat request and returns a stream of bytes for the response.

func (*Server) ChatHttp

func (s *Server) ChatHttp(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteCategory

func (s *Server) DeleteCategory(ctx context.Context, ownerName, categoryName string) (err error)

func (*Server) DeleteCategoryHttp

func (s *Server) DeleteCategoryHttp(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteDocument

func (s *Server) DeleteDocument(ctx context.Context, ownerName, categoryName string, documentID uint64) (err error)

func (*Server) DeleteDocumentHttp

func (s *Server) DeleteDocumentHttp(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteOwner

func (s *Server) DeleteOwner(ctx context.Context, owner string) (err error)

func (*Server) DeleteOwnerHttp

func (s *Server) DeleteOwnerHttp(w http.ResponseWriter, r *http.Request)

func (*Server) FetchCategoryNames

func (s *Server) FetchCategoryNames(ctx context.Context, owner string) (categoryNames []string, err error)

func (*Server) FetchCategoryNamesHttp

func (s *Server) FetchCategoryNamesHttp(w http.ResponseWriter, r *http.Request)

func (*Server) RefreshCentroids

func (d *Server) RefreshCentroids(appCtx context.Context)

func (*Server) Search

func (s *Server) Search(ctx context.Context, req SearchRequest) (res SearchResponse, err error)

Search for a previously uploaded embedding vector in the database and return similar documents.

func (*Server) SearchHttp

func (s *Server) SearchHttp(w http.ResponseWriter, r *http.Request)

func (*Server) Upload

func (s *Server) Upload(ctx context.Context, req UploadRequest) (res UploadResponse, err error)

Upload calculates the embedding for the uploaded document then saves the document and embedding in the database.

func (*Server) UploadHttp

func (s *Server) UploadHttp(w http.ResponseWriter, r *http.Request)

type UploadRequest

type UploadRequest struct {
	Owner     string           `json:"owner"`
	Category  string           `json:"category"`
	Documents []DocumentUpload `json:"documents"`
}

type UploadResponse

type UploadResponse struct {
	DocumentIDs []uint64 `json:"document_ids"`
}

Jump to

Keyboard shortcuts

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