MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / BuildChatRequest

Method BuildChatRequest

internal/cli/flags.go:482–547  ·  view source on GitHub ↗
(Meta string)

Source from the content-addressed store, hash-verified

480}
481
482func (o *Flags) BuildChatRequest(Meta string) (ret *domain.ChatRequest, err error) {
483 ret = &domain.ChatRequest{
484 ContextName: o.Context,
485 SessionName: o.Session,
486 PatternName: o.Pattern,
487 StrategyName: o.Strategy,
488 PatternVariables: o.PatternVariables,
489 InputHasVars: o.InputHasVars,
490 NoVariableReplacement: o.NoVariableReplacement,
491 Meta: Meta,
492 }
493
494 var message *chat.ChatCompletionMessage
495 if len(o.Attachments) > 0 {
496 message = &chat.ChatCompletionMessage{
497 Role: chat.ChatMessageRoleUser,
498 }
499
500 if o.Message != "" {
501 message.MultiContent = append(message.MultiContent, chat.ChatMessagePart{
502 Type: chat.ChatMessagePartTypeText,
503 Text: strings.TrimSpace(o.Message),
504 })
505 }
506
507 for _, attachmentValue := range o.Attachments {
508 var attachment *domain.Attachment
509 if attachment, err = domain.NewAttachment(attachmentValue); err != nil {
510 return
511 }
512 url := attachment.URL
513 if url == nil {
514 var base64Image string
515 if base64Image, err = attachment.Base64Content(); err != nil {
516 return
517 }
518 var mimeType string
519 if mimeType, err = attachment.ResolveType(); err != nil {
520 return
521 }
522 dataURL := fmt.Sprintf("data:%s;base64,%s", mimeType, base64Image)
523 url = &dataURL
524 }
525 message.MultiContent = append(message.MultiContent, chat.ChatMessagePart{
526 Type: chat.ChatMessagePartTypeImageURL,
527 ImageURL: &chat.ChatMessageImageURL{
528 URL: *url,
529 },
530 })
531 }
532 } else if o.Message != "" {
533 message = &chat.ChatCompletionMessage{
534 Role: chat.ChatMessageRoleUser,
535 Content: strings.TrimSpace(o.Message),
536 }
537 }
538
539 ret.Message = message

Callers 1

handleChatProcessingFunction · 0.80

Calls 4

Base64ContentMethod · 0.95
ResolveTypeMethod · 0.95
NewAttachmentFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected