Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix CreateChatHandler()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Sep 14, 2023
1 parent a1929f4 commit 2682383
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions commands/ui/handlers/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (

// ChatRequest represents a chat request data structure
type ChatRequest struct {
Conversation []string `json:"conversation"` // Conversation represents the conversation history of the chat request
Temperature *float64 `json:"temperature"` // Temperature represents the temperature to use for generating the response
Conversation []string `json:"conversation"` // Conversation represents the conversation history of the chat request
SystemPrompt string `json:"systemPrompt,omitempty"` // system prompt
Temperature *float64 `json:"temperature"` // Temperature represents the temperature to use for generating the response
}

// ChatResponse represents a chat response data structure
Expand Down Expand Up @@ -85,26 +86,19 @@ func CreateChatHandler(options CreateChatHandlerOptions) egoTypes.FHRequestHandl
}

var additionalInfo []string
var systemPromptBuff bytes.Buffer

addInfos := func(infos ...string) {
additionalInfo = append(additionalInfo, infos...)
}

customSystemPrompt := strings.TrimSpace(options.CustomSystemPrompt)
if customSystemPrompt != "" {
systemPromptBuff.WriteString(fmt.Sprintln(customSystemPrompt))
} else {
defaultSystemPrompt, _, err := egoUtils.GetSystemPrompt()
if err != nil {
panic(err)
}

systemPromptBuff.WriteString(fmt.Sprintln(defaultSystemPrompt))
}
customSystemPrompt := strings.TrimSpace(chatRequest.SystemPrompt)

var finalSystemPrompt bytes.Buffer
finalSystemPrompt.WriteString(systemPromptTemplate)
if customSystemPrompt == "" {
finalSystemPrompt.WriteString(systemPromptTemplate)
} else {
finalSystemPrompt.WriteString(customSystemPrompt)
}

if !options.NoSystemInfo {
if !options.NoTime {
Expand Down

0 comments on commit 2682383

Please sign in to comment.