feat: support channel ai.ls now (close #99)

This commit is contained in:
JustSong
2023-05-19 11:07:17 +08:00
parent 7c6bf3e97b
commit 3711f4a741
5 changed files with 15 additions and 7 deletions

View File

@@ -45,9 +45,9 @@ func countTokenMessages(messages []Message, model string) int {
tokenNum += tokensPerMessage
tokenNum += len(tokenEncoder.Encode(message.Content, nil, nil))
tokenNum += len(tokenEncoder.Encode(message.Role, nil, nil))
if message.Name != "" {
if message.Name != nil {
tokenNum += tokensPerName
tokenNum += len(tokenEncoder.Encode(message.Name, nil, nil))
tokenNum += len(tokenEncoder.Encode(*message.Name, nil, nil))
}
}
tokenNum += 3 // Every reply is primed with <|start|>assistant<|message|>

View File

@@ -14,9 +14,9 @@ import (
)
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Name string `json:"name"`
Role string `json:"role"`
Content string `json:"content"`
Name *string `json:"name,omitempty"`
}
type ChatRequest struct {
@@ -232,6 +232,10 @@ func relayHelper(c *gin.Context) *OpenAIErrorWithStatusCode {
go func() {
for scanner.Scan() {
data := scanner.Text()
if len(data) < 6 { // must be something wrong!
common.SysError("Invalid stream response: " + data)
continue
}
dataChan <- data
data = data[6:]
if !strings.HasPrefix(data, "[DONE]") {