Documentation ¶
Index ¶
- func JSONExtract[TData []byte | map[string]any](data TData, paths []JSONPath) (map[string]any, error)
- func JSONMerge(into map[string]any, from map[string]any)
- func Version() string
- type Formality
- type ImproveParams
- type Improver
- type JSONPath
- type Model
- type ModelFunc
- type TranslateParams
- type Translator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONExtract ¶ added in v0.7.0
func JSONExtract[TData []byte | map[string]any](data TData, paths []JSONPath) (map[string]any, error)
JSONExtract extracts values from a JSON document according to specified paths and returns them as a map. It supports both raw JSON bytes and already-parsed maps as input. If any path does not exist or leads to an unexpected type, an error is returned alongside the partial output.
func JSONMerge ¶ added in v0.7.0
JSONMerge combines the contents of two JSON object maps, where 'from' is merged into 'into'. If there are matching keys, the values from 'from' will overwrite those in 'into'. For nested maps, merging is performed recursively. This function modifies the 'into' map directly and does not return a new map.
Types ¶
type Formality ¶ added in v0.9.0
type Formality string
Formality represents the level of formality in language, ranging from formal to informal, providing contextual cues for language translation or usage. It supports checking if a specific formality has been set and converts to its string representation. Formality also guides language adjustments based on the desired tone and social context.
const ( // FormalityUnspecified indicates the absence of a specified formality level in // translation or language settings. FormalityUnspecified Formality = "" // FormalityFormal represents the use of formal language and address forms, // applicable across all languages where such distinctions exist. FormalityFormal Formality = "formal" // FormalityInformal specifies the use of informal language and address forms, // applicable across various languages where distinctions between formality // levels exist. FormalityInformal Formality = "informal" )
func (Formality) IsSpecified ¶ added in v0.9.0
IsSpecified reports whether a Formality instance has a specified value other than the default unspecified state.
type ImproveParams ¶ added in v0.9.0
type ImproveParams struct { Document string // SplitChunks is a list of strings that should be used to split the document // into chunks. If the document is split into chunks, each chunk will be // improved separately, allowing to fit large documents into the model's // context window. SplitChunks []string // Formality specifies the formality (formal address) to use in the improved document. Formality Formality // Keywords are SEO keywords that should be used in the improved document. Keywords []string // Instructions are raw instructions that should be included in the prompt. Instructions []string // Language is the language the improved document should be written in. Language string }
ImproveParams configures the enhancement of a document by specifying its content, how to split it for processing, the desired formality tone, SEO keywords to incorporate, specific instructions for adjustment, and the language in which improvements should be made. It is used by an Improver to adjust a document's appeal, readability, and search engine optimization.
type Improver ¶ added in v0.9.0
type Improver struct {
// contains filtered or unexported fields
}
Improver enhances the content of a document by making it more engaging, informative, and optimized for search engine visibility while preserving its structural integrity. It takes into account various parameters such as formality, language, and specific keywords to ensure the output is tailored to specific needs. The enhanced content is achieved by processing each segment of the document separately when necessary, allowing for large documents to be handled effectively.
func NewImprover ¶ added in v0.9.0
NewImprover creates a new instance of Improver using the provided Model.
func (*Improver) Improve ¶ added in v0.9.0
Improve enhances the content of a document based on specified parameters to increase engagement, clarity, and search engine optimization. It splits the document into manageable chunks if necessary, processes each chunk independently according to the improvement criteria including language, formality, keywords, and additional instructions, and then reassembles the improved chunks into a cohesive output.
type JSONPath ¶ added in v0.7.0
type JSONPath []string
JSONPath represents a sequence of keys that specify a unique path through a JSON object hierarchy, similar to an address for locating a specific value within a nested JSON structure. It is used to traverse and extract data from complex JSON documents.
func JSONDiff ¶ added in v0.7.0
JSONDiff identifies the differences between two JSON objects or two raw JSON byte representations. It returns a slice of JSONPaths that represent the hierarchical structure of keys where differences exist, and an error if any occur during the process. The function is generic and can accept either raw bytes or maps as inputs for comparison.
type Model ¶
type Model interface { // Chat function takes a context and a prompt as input and returns a string and // an error. It uses the provided context and prompt to initiate a chat session // and retrieve a response. Chat(context.Context, string) (string, error) }
Model is an interface that represents a chat-based translation model. It provides a method called Chat, which takes a context and a prompt string as input and returns the translated text and any error that occurred during translation.
type ModelFunc ¶
ModelFunc is a type that represents a function that can be used as a model for chat translation. It implements the Model interface and allows for chat translation by calling the function with a context and prompt string.
type TranslateParams ¶ added in v0.9.0
type TranslateParams struct { Document string // Source is the language of the document to translate. Source string // Target is the language to translate the document to. Target string // Preserve is a list of terms that should not be translated. Useful for // preserving brand names. Preserve []string // Instructions are raw instructions that should be included in the prompt. Instructions []string SplitChunks []string }
TranslateParams specifies the parameters for translating text from one language to another, including instructions on how text should be handled during translation and any terms that should be preserved unchanged. It also defines how to segment the text for translation if necessary.
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator provides facilities for converting text from one language to another while optionally preserving specific terms and adhering to additional translation instructions. It supports translating large documents by splitting them into manageable chunks based on specified delimiters. The process respects the contextual nuances of the source and target languages, ensuring that the structural integrity and formatting of the original document are maintained. Errors during the translation process are handled gracefully, providing detailed error messages that facilitate troubleshooting.
func NewTranslator ¶ added in v0.9.0
func NewTranslator(svc Model) *Translator
NewTranslator creates a new instance of a translator, initializing it with a provided model for language translation tasks. It returns a *Translator.
func (*Translator) Translate ¶
func (t *Translator) Translate(ctx context.Context, params TranslateParams) (string, error)
Translate converts the content of a document from one language to another according to specified parameters. It processes the document in potentially multiple segments, preserving specified terms and formatting instructions. The function returns the translated text or an error if the translation fails. Input parameters and context are provided by a TranslateParams and context.Context, respectively.