api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 17 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIHandlers

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

APIHandlers contains the handlers for API endpoints

func NewAPIHandlers

func NewAPIHandlers(appConfig *config.AppConfig, queue *RequestQueue, pages map[string]playwright.Page, debug bool) *APIHandlers

NewAPIHandlers creates a new API handlers instance

func (*APIHandlers) ChatCompletions

func (h *APIHandlers) ChatCompletions(c *gin.Context)

ChatCompletions handles the /v1/chat/completions endpoint

type ChatProcessor

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

ChatProcessor implements TaskProcessor interface

func NewChatProcessor

func NewChatProcessor(appConfig *config.AppConfig, pages map[string]playwright.Page, proxies map[string]*proxy.Proxy, debug bool) *ChatProcessor

NewChatProcessor creates a new chat processor

func (*ChatProcessor) ProcessTask

func (cp *ChatProcessor) ProcessTask(ctx context.Context, task *RequestTask) *TaskResponse

ProcessTask processes a chat completion task

type ErrorDetail

type ErrorDetail struct {
	Message string `json:"message"`
	Type    string `json:"type"`
	Code    string `json:"code,omitempty"`
}

ErrorDetail represents error details

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents an error response

type Prompt

type Prompt struct {
	Role        string
	ContentType string
	Content     string
}

type RequestQueue

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

RequestQueue manages the sequential processing of chat completion requests

func NewRequestQueue

func NewRequestQueue(processor TaskProcessor) *RequestQueue

NewRequestQueue creates a new request queue

func (*RequestQueue) AddTask

func (q *RequestQueue) AddTask(task *RequestTask) error

AddTask adds a new task to the queue

func (*RequestQueue) GetQueueLength

func (q *RequestQueue) GetQueueLength() int

GetQueueLength returns the current number of tasks in the queue

func (*RequestQueue) IsRunning

func (q *RequestQueue) IsRunning() bool

IsRunning returns whether the queue is currently running

func (*RequestQueue) Start

func (q *RequestQueue) Start() error

Start begins processing requests from the queue

func (*RequestQueue) Stop

func (q *RequestQueue) Stop() error

Stop stops the request queue and waits for current task to complete

type RequestTask

type RequestTask struct {
	ID           string             `json:"id"`
	Request      string             `json:"request"`
	Response     chan *TaskResponse `json:"-"`
	CreatedAt    time.Time          `json:"created_at"`
	Context      *gin.Context       `json:"context"`
	InstanceName string             `json:"instance_name"`
}

RequestTask represents a queued request task

type Server

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

Server represents the API server

func NewServer

func NewServer(config *ServerConfig, appConfig *config.AppConfig) *Server

NewServer creates a new API server instance

func (*Server) Start

func (s *Server) Start() error

Start starts the API server

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully stops the API server

type ServerConfig

type ServerConfig struct {
	Port   string
	Debug  bool
	Pages  map[string]playwright.Page
	Proxys map[string]*proxy.Proxy
}

ServerConfig contains configuration for the API server

type TaskProcessor

type TaskProcessor interface {
	ProcessTask(ctx context.Context, task *RequestTask) *TaskResponse
}

TaskProcessor defines the interface for processing tasks

type TaskResponse

type TaskResponse struct {
	Success  bool        `json:"success"`
	Response string      `json:"response,omitempty"`
	Stream   chan string `json:"-"`
	Error    error       `json:"error,omitempty"`
	Runner   *runner.RunnerManager
}

TaskResponse represents the response from processing a task

Jump to

Keyboard shortcuts

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