Documentation
¶
Index ¶
- Constants
- func BuildContractPrompt(req GenerateContractRequest, context string) string
- func BuildRAGContext(contracts []SimilarContract) string
- func BuildReviewPrompt(contractText string) string
- func DecryptAPIKey(encrypted string) (string, error)
- func EncryptAPIKey(apiKey string) (string, error)
- func ExtractTextFromPDF(r io.Reader) (string, error)
- func SetEncryptionKey(key []byte)
- func ValidateStartupConfig(db *sql.DB, encryptionKey string) error
- type ContractRetriever
- type GenerateContractRequest
- type GenerateResponse
- type LLMClient
- type LLMProvider
- type RateLimiter
- type ReviewContractRequest
- type ReviewResponse
- type RiskItem
- type SimilarContract
Constants ¶
const ( // SystemPromptLegal is the system prompt for legal AI assistant SystemPromptLegal = `` /* 258-byte string literal not displayed */ // GenerateContractPromptTemplate is the template for generating contracts GenerateContractPromptTemplate = `` /* 398-byte string literal not displayed */ // ReviewContractPromptTemplate is the template for reviewing contracts ReviewContractPromptTemplate = `` /* 516-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func BuildContractPrompt ¶
func BuildContractPrompt(req GenerateContractRequest, context string) string
BuildContractPrompt builds the full prompt for contract generation
func BuildRAGContext ¶
func BuildRAGContext(contracts []SimilarContract) string
BuildRAGContext builds a context string from similar contracts
func BuildReviewPrompt ¶
BuildReviewPrompt builds the full prompt for contract review
func DecryptAPIKey ¶
DecryptAPIKey decrypts an API key using AES-256-GCM
func EncryptAPIKey ¶
EncryptAPIKey encrypts an API key using AES-256-GCM
func ExtractTextFromPDF ¶
ExtractTextFromPDF extracts plain text from PDF bytes
func SetEncryptionKey ¶
func SetEncryptionKey(key []byte)
SetEncryptionKey sets the key used for AES encryption Key must be 16, 24, or 32 bytes for AES-128, AES-192, or AES-256
Types ¶
type ContractRetriever ¶
ContractRetriever handles retrieving similar contracts from SQLite
func NewContractRetriever ¶
func NewContractRetriever(db *sql.DB) *ContractRetriever
NewContractRetriever creates a new contract retriever
func (*ContractRetriever) GetSimilarContracts ¶
func (r *ContractRetriever) GetSimilarContracts(companyID int, contractType string, clientID, supplierID int, limit int) ([]SimilarContract, error)
GetSimilarContracts retrieves similar contracts based on type and counterpart, scoped to a company
type GenerateContractRequest ¶
type GenerateContractRequest struct {
ContractType string `json:"contract_type"`
Amount float64 `json:"amount"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
ClientID int `json:"client_id"`
SupplierID int `json:"supplier_id"`
Description string `json:"description,omitempty"`
Context string `json:"context,omitempty"`
}
GenerateContractRequest is the request body for generating a contract with AI
type GenerateResponse ¶
GenerateResponse is the response for AI generation requests
type LLMClient ¶
type LLMClient struct {
Provider LLMProvider
APIKey string
Model string
Endpoint string
HTTPClient *http.Client
}
LLMClient handles communication with LLM providers
func NewLLMClient ¶
func NewLLMClient(provider LLMProvider, apiKey, model, endpoint string) *LLMClient
NewLLMClient creates a new LLM client
type LLMProvider ¶
type LLMProvider string
LLM Provider constants
const ( ProviderOpenAI LLMProvider = "openai" ProviderGroq LLMProvider = "groq" ProviderAnthropic LLMProvider = "anthropic" ProviderOpenRouter LLMProvider = "openrouter" ProviderCustom LLMProvider = "custom" )
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter enforces daily rate limits per company using shared DB storage.
func NewRateLimiter ¶
func NewRateLimiter(db *sql.DB) *RateLimiter
NewRateLimiter creates a RateLimiter backed by the provided DB.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(companyID int) (remaining int, ok bool)
Allow checks if companyID has remaining quota for today. It increments the counter if allowed. Returns (remaining, ok).
func (*RateLimiter) SetLimit ¶
func (rl *RateLimiter) SetLimit(limit int)
SetLimit allows overriding the default daily limit (not persisted).
type ReviewContractRequest ¶
type ReviewContractRequest struct {
ContractID int `json:"contract_id"`
Text string `json:"text"`
DocumentURL string `json:"document_url,omitempty"`
}
ReviewContractRequest is the request body for reviewing a contract with AI
type ReviewResponse ¶
type ReviewResponse struct {
Summary string `json:"summary"`
Risks []RiskItem `json:"risks"`
MissingClauses []string `json:"missing_clauses"`
OverallRisk string `json:"overall_risk"`
}
ReviewResponse is the structured response for contract review
func ParseReviewResponse ¶
func ParseReviewResponse(raw string) (ReviewResponse, error)
ParseReviewResponse parses LLM output into structured ReviewResponse. It tolerates markdown code fences and common formatting issues.