postapi

package
v0.0.0-...-ecddef1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const EmbeddingModel = "text-embedding-ada-002"
View Source
const MAX_FILE_SIZE int64 = 3 << 20 // 3 MB
View Source
const MAX_TOTAL_UPLOAD_SIZE int64 = 3 << 20 // 3 MB
View Source
const MaxTokensPerChunk = 1500

MaxTokensPerChunk is the maximum number of tokens allowed in a single chunk for OpenAI embeddings MaxTokensPerChunk is the maximum number of tokens allowed in a single chunk for OpenAI embeddings

Variables

View Source
var (
	CONFIG                = serverutil.GetConfig()
	C                     *cache.Cache
	DEFAULT_OPENAI_CLIENT *openai.Client
	PINECONE_API_KEY      = ""
	PINECONE_API_ENDPOINT = ""
)

Functions

func FormParseVerify

func FormParseVerify(form form.Form, name string, w http.ResponseWriter, r *http.Request) errorlist.Errors

Util: does grunt work of decoding + verifying form + writing errors back

func QuestionHandler

func QuestionHandler(w http.ResponseWriter, r *http.Request)

Handle Requests For Question

func Run

func Run(openaiClient *openai.Client, pineconeApiKey string, pineconeApiEndpoint string)

Must be called to set up this module before use

func UploadHandler

func UploadHandler(w http.ResponseWriter, r *http.Request)

Types

type Answer

type Answer struct {
	Answer  string    `json:"answer"`
	Context []Context `json:"context"`
	Tokens  int       `json:"tokens"`
}

type Chunk

type Chunk struct {
	Start int
	End   int
	Title string
	Text  string
}

func CreateChunks

func CreateChunks(fileContent string, title string) ([]Chunk, error)

type Config

type Config struct {
	Debug bool
}

type Context

type Context struct {
	Text  string `json:"text"`
	Title string `json:"title"`
}

type OpenAIResponse

type OpenAIResponse struct {
	Response string `json:"response"`
	Tokens   int    `json:"tokens"`
}

type PineconeQueryItem

type PineconeQueryItem struct {
	Values []float32 `json:"values"`
}

type PineconeQueryMatch

type PineconeQueryMatch struct {
	ID       string            `json:"id"`
	Score    float32           `json:"score"` // Use "score" instead of "distance"
	Metadata map[string]string `json:"metadata"`
}

type PineconeQueryRequest

type PineconeQueryRequest struct {
	TopK            int                 `json:"topK"`
	IncludeMetadata bool                `json:"includeMetadata"`
	Namespace       string              `json:"namespace"`
	Queries         []PineconeQueryItem `json:"queries"`
}

type PineconeQueryResponse

type PineconeQueryResponse struct {
	Results []PineconeQueryResponseResult `json:"results"`
}

type PineconeQueryResponseResult

type PineconeQueryResponseResult struct {
	Matches []PineconeQueryMatch `json:"matches"`
}

type PineconeVector

type PineconeVector struct {
	ID       string            `json:"id"`
	Values   []float32         `json:"values"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type UploadResponse

type UploadResponse struct {
	Message             string            `json:"message"`
	NumFilesSucceeded   int               `json:"num_files_succeeded"`
	NumFilesFailed      int               `json:"num_files_failed"`
	SuccessfulFileNames []string          `json:"successful_file_names"`
	FailedFileNames     map[string]string `json:"failed_file_names"`
}

Jump to

Keyboard shortcuts

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