Documentation ¶
Overview ¶
Package repairdata provides utilities for transforming JSON data from an old format to a new format.
It specifically ensures that each session's modelConfig contains a 'systemprompt' field.
Copyright (c) 2023 H0llyW00dzZ
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RepairSessionData ¶
RepairSessionData transforms JSON data from the old format to the new format.
It adds a 'systemprompt' field to the 'modelConfig' within each session if it is missing.
Types ¶
type Mask ¶
type Mask struct { ID StringOrInt `json:"id"` Avatar string `json:"avatar"` Name string `json:"name"` Context []Message `json:"context"` SyncGlobalConfig bool `json:"syncGlobalConfig"` ModelConfig *ModelConfig `json:"modelConfig"` Lang string `json:"lang"` Builtin bool `json:"builtin"` CreatedAt int64 `json:"createdAt"` }
Mask represents the structure of the mask field within a session.
type Message ¶
type Message struct { ID string `json:"id"` Date string `json:"date"` Role string `json:"role"` Content string `json:"content"` }
Message represents the structure of a message within a session.
type ModelConfig ¶
type ModelConfig struct { Model string `json:"model"` // The model name. Temperature float64 `json:"temperature"` // The temperature for generating responses. TopP float64 `json:"top_p"` // The top-p value for generating responses. MaxTokens int `json:"max_tokens"` // The maximum number of tokens in a generated response. PresencePenalty float64 `json:"presence_penalty"` // The presence penalty for generating responses. FrequencyPenalty float64 `json:"frequency_penalty"` // The frequency penalty for generating responses. N int `json:"n"` // The number of responses to generate. Quality string `json:"quality"` // The quality of the generated responses. Size string `json:"size"` // The size of the model. Style string `json:"style"` // The style of the generated responses. SystemFingerprint string `json:"system_fingerprint"` // The fingerprint of the system. SendMemory bool `json:"sendMemory"` // Whether to send memory to the model. HistoryMessageCount int `json:"historyMessageCount"` // The number of history messages to include. CompressMessageLengthThreshold int `json:"compressMessageLengthThreshold"` // The threshold for compressing message length. EnableInjectSystemPrompts bool `json:"enableInjectSystemPrompts"` // Whether to enable injecting system prompts. Template string `json:"template"` // The template for generating responses. SystemPrompt *SystemPrompt `json:"systemprompt,omitempty"` // The system prompt for generating responses (optional). }
ModelConfig represents the structure of the modelConfig field within a mask.
type NewData ¶
type NewData struct { ChatNextWebStore struct { Sessions []Session `json:"sessions"` CurrentSessionIndex int `json:"currentSessionIndex"` LastUpdateTime int64 `json:"lastUpdateTime"` } `json:"chat-next-web-store"` }
NewData represents the structure of the new JSON data format.
Additional fields can be added to match the complete new JSON structure as needed.
type OldData ¶
type OldData struct { ChatNextWebStore struct { Sessions []Session `json:"sessions"` CurrentSessionIndex int `json:"currentSessionIndex"` LastUpdateTime int64 `json:"lastUpdateTime"` } `json:"chat-next-web-store"` }
OldData represents the structure of the old JSON data format.
Additional fields can be added to match the complete old JSON structure as needed.
type Session ¶
type Session struct { ID string `json:"id"` Topic string `json:"topic"` MemoryPrompt string `json:"memoryPrompt"` Messages []Message `json:"messages"` Stat Stat `json:"stat"` LastUpdate int64 `json:"lastUpdate"` LastSummarizeIndex int `json:"lastSummarizeIndex"` Mask *Mask `json:"mask"` }
RepairSessionData takes a byte slice of the old JSON format and returns a byte slice of the new JSON format.
type Stat ¶
type Stat struct { TokenCount int `json:"tokenCount"` WordCount int `json:"wordCount"` CharCount int `json:"charCount"` }
Stat represents the structure of the stat field within a session.
type StringOrInt ¶
type StringOrInt string
StringOrInt is a custom type to handle JSON values that can be either strings or integers (Magic Golang 🎩 🪄).
It implements the Unmarshaler interface to handle this mixed type when unmarshaling JSON data.
func (*StringOrInt) UnmarshalJSON ¶
func (soi *StringOrInt) UnmarshalJSON(data []byte) error
UnmarshalJSON is a custom unmarshaler for StringOrInt that tries to unmarshal JSON data
as a string, and if that fails, as an integer, which is then converted to a string.
type SystemPrompt ¶
type SystemPrompt struct {
Default string `json:"default"`
}
SystemPrompt represents the structure of the systemprompt field within a modelConfig.