MCPcopy
hub / github.com/danielmiessler/Fabric / handleChatProcessing

Function handleChatProcessing

internal/cli/chat.go:21–147  ·  view source on GitHub ↗

handleChatProcessing handles the main chat processing logic

(currentFlags *Flags, registry *core.PluginRegistry, messageTools string)

Source from the content-addressed store, hash-verified

19
20// handleChatProcessing handles the main chat processing logic
21func handleChatProcessing(currentFlags *Flags, registry *core.PluginRegistry, messageTools string) (err error) {
22 if messageTools != "" {
23 currentFlags.AppendMessage(messageTools)
24 }
25 // Check for pattern-specific model via environment variable
26 if currentFlags.Pattern != "" && currentFlags.Model == "" {
27 envVar := "FABRIC_MODEL_" + strings.ToUpper(strings.ReplaceAll(currentFlags.Pattern, "-", "_"))
28 if modelSpec := os.Getenv(envVar); modelSpec != "" {
29 parts := strings.SplitN(modelSpec, "|", 2)
30 if len(parts) == 2 {
31 currentFlags.Vendor = parts[0]
32 currentFlags.Model = parts[1]
33 } else {
34 currentFlags.Model = modelSpec
35 }
36 }
37 }
38
39 var chatter *core.Chatter
40 if chatter, err = registry.GetChatter(currentFlags.Model, currentFlags.ModelContextLength,
41 currentFlags.Vendor, currentFlags.Stream, currentFlags.DryRun); err != nil {
42 return
43 }
44
45 var session *fsdb.Session
46 var chatReq *domain.ChatRequest
47 if chatReq, err = currentFlags.BuildChatRequest(strings.Join(os.Args[1:], " ")); err != nil {
48 return
49 }
50
51 if chatReq.Language == "" {
52 chatReq.Language = registry.Language.DefaultLanguage.Value
53 }
54 var chatOptions *domain.ChatOptions
55 if chatOptions, err = currentFlags.BuildChatOptions(); err != nil {
56 return
57 }
58
59 // Check if user is requesting audio output or using a TTS model
60 isAudioOutput := currentFlags.Output != "" && IsAudioFormat(currentFlags.Output)
61 isTTSModel := isTTSModel(currentFlags.Model)
62
63 if isTTSModel && !isAudioOutput {
64 err = fmt.Errorf("%s", fmt.Sprintf(i18n.T("tts_model_requires_audio_output"), currentFlags.Model))
65 return
66 }
67
68 if isAudioOutput && !isTTSModel {
69 err = fmt.Errorf("%s", fmt.Sprintf(i18n.T("audio_output_file_specified_but_not_tts_model"), currentFlags.Output, currentFlags.Model))
70 return
71 }
72
73 // For TTS models, check if output file already exists BEFORE processing
74 if isTTSModel && isAudioOutput {
75 outputFile := currentFlags.Output
76 // Add .wav extension if not provided
77 if filepath.Ext(outputFile) == "" {
78 outputFile += ".wav"

Callers 1

CliFunction · 0.85

Calls 14

SendMethod · 0.95
GetLastMessageMethod · 0.95
StringMethod · 0.95
TFunction · 0.92
IsAudioFormatFunction · 0.85
isTTSModelFunction · 0.85
CopyToClipboardFunction · 0.85
CreateOutputFileFunction · 0.85
CreateAudioOutputFileFunction · 0.85
sendNotificationFunction · 0.85
AppendMessageMethod · 0.80
GetChatterMethod · 0.80

Tested by

no test coverage detected