mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-02 07:25:26 +08:00
36 lines
847 B
Go
36 lines
847 B
Go
package promptcompat
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"ds2api/internal/prompt"
|
|
)
|
|
|
|
const CurrentInputContextFilename = "history.txt"
|
|
|
|
func BuildOpenAIHistoryTranscript(messages []any) string {
|
|
return buildOpenAIInjectedFileTranscript(messages)
|
|
}
|
|
|
|
func BuildOpenAICurrentUserInputTranscript(text string) string {
|
|
if strings.TrimSpace(text) == "" {
|
|
return ""
|
|
}
|
|
return BuildOpenAICurrentInputContextTranscript([]any{
|
|
map[string]any{"role": "user", "content": text},
|
|
})
|
|
}
|
|
|
|
func BuildOpenAICurrentInputContextTranscript(messages []any) string {
|
|
return buildOpenAIInjectedFileTranscript(messages)
|
|
}
|
|
|
|
func buildOpenAIInjectedFileTranscript(messages []any) string {
|
|
normalized := NormalizeOpenAIMessagesForPrompt(messages, "")
|
|
transcript := strings.TrimSpace(prompt.MessagesPrepare(normalized))
|
|
if transcript == "" {
|
|
return ""
|
|
}
|
|
return transcript
|
|
}
|