mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-07 09:55:29 +08:00
37 lines
964 B
Go
37 lines
964 B
Go
package promptcompat
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"ds2api/internal/prompt"
|
|
)
|
|
|
|
const historySplitInjectedFilename = "IGNORE"
|
|
|
|
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 fmt.Sprintf("[file content end]\n\n%s\n\n[file name]: %s\n[file content begin]\n", transcript, historySplitInjectedFilename)
|
|
}
|