DeepLX/translate/types.go

110 lines
3.3 KiB
Go
Raw Normal View History

2024-04-23 12:50:11 +08:00
/*
2024-09-17 00:08:13 +08:00
* @Author: Vincent Young
* @Date: 2024-09-16 11:59:24
2024-11-01 12:43:57 +08:00
* @LastEditors: Vincent Yang
2024-11-02 11:19:50 +08:00
* @LastEditTime: 2024-11-01 23:18:56
2024-09-17 00:08:13 +08:00
* @FilePath: /DeepLX/translate/types.go
2024-04-23 12:50:11 +08:00
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
*
* Copyright © 2024 by Vincent, All Rights Reserved.
*/
2024-03-21 04:41:44 +08:00
2024-09-17 00:08:13 +08:00
package translate
2024-03-21 04:41:44 +08:00
2024-11-01 12:43:57 +08:00
// Lang represents the language settings for translation
2024-03-21 04:41:44 +08:00
type Lang struct {
2024-11-01 12:43:57 +08:00
SourceLangComputed string `json:"source_lang_computed,omitempty"`
TargetLang string `json:"target_lang"`
LangUserSelected string `json:"lang_user_selected,omitempty"`
2024-03-21 04:41:44 +08:00
}
2024-11-01 12:43:57 +08:00
// CommonJobParams represents common parameters for translation jobs
2024-03-21 04:41:44 +08:00
type CommonJobParams struct {
2024-11-02 00:48:26 +08:00
Mode string `json:"mode"`
2024-11-02 11:19:50 +08:00
RegionalVariant string `json:"regionalVariant,omitempty"`
2024-03-21 04:41:44 +08:00
}
2024-11-01 12:43:57 +08:00
// Sentence represents a sentence in the translation request
type Sentence struct {
Prefix string `json:"prefix"`
Text string `json:"text"`
ID int `json:"id"`
}
// Job represents a translation job
type Job struct {
Kind string `json:"kind"`
PreferredNumBeams int `json:"preferred_num_beams"`
RawEnContextBefore []string `json:"raw_en_context_before"`
RawEnContextAfter []string `json:"raw_en_context_after"`
Sentences []Sentence `json:"sentences"`
}
// Params represents parameters for translation requests
2024-03-21 04:41:44 +08:00
type Params struct {
2024-11-01 12:43:57 +08:00
CommonJobParams CommonJobParams `json:"commonJobParams"`
2024-03-21 04:41:44 +08:00
Lang Lang `json:"lang"`
2024-11-01 12:43:57 +08:00
Texts []string `json:"texts,omitempty"`
TextType string `json:"textType,omitempty"`
Jobs []Job `json:"jobs,omitempty"`
Priority int `json:"priority,omitempty"`
2024-03-21 04:41:44 +08:00
Timestamp int64 `json:"timestamp"`
}
2024-11-01 12:43:57 +08:00
// PostData represents the complete translation request
2024-03-21 04:41:44 +08:00
type PostData struct {
Jsonrpc string `json:"jsonrpc"`
Method string `json:"method"`
ID int64 `json:"id"`
Params Params `json:"params"`
}
2024-11-01 12:43:57 +08:00
// SplitTextResponse represents the response from text splitting
type SplitTextResponse struct {
Jsonrpc string `json:"jsonrpc"`
ID int64 `json:"id"`
Result struct {
Lang struct {
Detected string `json:"detected"`
} `json:"lang"`
Texts []struct {
Chunks []struct {
Sentences []struct {
Prefix string `json:"prefix"`
Text string `json:"text"`
} `json:"sentences"`
} `json:"chunks"`
} `json:"texts"`
} `json:"result"`
2024-03-21 04:41:44 +08:00
}
2024-11-01 12:43:57 +08:00
// TranslationResponse represents the response from translation
2024-03-21 04:41:44 +08:00
type TranslationResponse struct {
2024-11-01 12:43:57 +08:00
Jsonrpc string `json:"jsonrpc"`
ID int64 `json:"id"`
Result struct {
Translations []struct {
Beams []struct {
Sentences []struct {
Text string `json:"text"`
} `json:"sentences"`
} `json:"beams"`
} `json:"translations"`
SourceLang string `json:"source_lang"`
TargetLang string `json:"target_lang"`
} `json:"result"`
2024-03-21 04:41:44 +08:00
}
2024-11-01 12:43:57 +08:00
// DeepLXTranslationResult represents the final translation result
2024-03-21 04:41:44 +08:00
type DeepLXTranslationResult struct {
2024-11-01 12:43:57 +08:00
Code int `json:"code"`
ID int64 `json:"id"`
Message string `json:"message,omitempty"`
Data string `json:"data"`
Alternatives []string `json:"alternatives"`
SourceLang string `json:"source_lang"`
TargetLang string `json:"target_lang"`
Method string `json:"method"`
2024-03-21 04:41:44 +08:00
}