@@ -77,7 +77,7 @@ type Message struct {
77
77
// The message role
78
78
Role string `json:"role,omitempty" yaml:"role"`
79
79
// The message content
80
- Content string `json:"content,omitempty " yaml:"content"`
80
+ Content * string `json:"content" yaml:"content"`
81
81
// A result of a function call
82
82
FunctionCall interface {} `json:"function_call,omitempty" yaml:"function_call,omitempty"`
83
83
}
@@ -392,7 +392,7 @@ func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
392
392
ComputeChoices (s , req , config , o , loader , func (s string , c * []Choice ) {}, func (s string ) bool {
393
393
resp := OpenAIResponse {
394
394
Model : req .Model , // we have to return what the user sent here, due to OpenAI spec.
395
- Choices : []Choice {{Delta : & Message {Content : s }, Index : 0 }},
395
+ Choices : []Choice {{Delta : & Message {Content : & s }, Index : 0 }},
396
396
Object : "chat.completion.chunk" ,
397
397
}
398
398
log .Debug ().Msgf ("Sending goroutine: %s" , s )
@@ -460,24 +460,29 @@ func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
460
460
}
461
461
}
462
462
r := config .Roles [role ]
463
+ contentExists := i .Content != nil && * i .Content != ""
463
464
if r != "" {
464
- content = fmt .Sprint (r , " " , i .Content )
465
+ if contentExists {
466
+ content = fmt .Sprint (r , " " , * i .Content )
467
+ }
465
468
if i .FunctionCall != nil {
466
469
j , err := json .Marshal (i .FunctionCall )
467
470
if err == nil {
468
- if i . Content != "" {
471
+ if contentExists {
469
472
content += "\n " + fmt .Sprint (r , " " , string (j ))
470
473
} else {
471
474
content = fmt .Sprint (r , " " , string (j ))
472
475
}
473
476
}
474
477
}
475
478
} else {
476
- content = i .Content
479
+ if contentExists {
480
+ content = fmt .Sprint (* i .Content )
481
+ }
477
482
if i .FunctionCall != nil {
478
483
j , err := json .Marshal (i .FunctionCall )
479
484
if err == nil {
480
- if i . Content != "" {
485
+ if contentExists {
481
486
content += "\n " + string (j )
482
487
} else {
483
488
content = string (j )
@@ -600,7 +605,7 @@ func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
600
605
message = Finetune (* config , predInput , message )
601
606
log .Debug ().Msgf ("Reply received from LLM(finetuned): %s" , message )
602
607
603
- * c = append (* c , Choice {Message : & Message {Role : "assistant" , Content : message }})
608
+ * c = append (* c , Choice {Message : & Message {Role : "assistant" , Content : & message }})
604
609
return
605
610
}
606
611
}
@@ -623,18 +628,18 @@ func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
623
628
}
624
629
625
630
prediction = Finetune (* config , predInput , prediction )
626
- * c = append (* c , Choice {Message : & Message {Role : "assistant" , Content : prediction }})
631
+ * c = append (* c , Choice {Message : & Message {Role : "assistant" , Content : & prediction }})
627
632
} else {
628
633
// otherwise reply with the function call
629
634
* c = append (* c , Choice {
630
635
FinishReason : "function_call" ,
631
- Message : & Message {Role : "function " , FunctionCall : ss },
636
+ Message : & Message {Role : "assistant " , FunctionCall : ss },
632
637
})
633
638
}
634
639
635
640
return
636
641
}
637
- * c = append (* c , Choice {Message : & Message {Role : "assistant" , Content : s }})
642
+ * c = append (* c , Choice {Message : & Message {Role : "assistant" , Content : & s }})
638
643
}, nil )
639
644
if err != nil {
640
645
return err
0 commit comments