-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context): conversation context struct
- Loading branch information
Showing
3 changed files
with
108 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package chatgpt | ||
|
||
import "strings" | ||
|
||
var ( | ||
DefaultHead = "\nHuman: 你好,让我们开始愉快的谈话!\nAI: 我是 AI assistant ,请问你有什么问题?" | ||
DefaultCharacter = []string{"helpful", "creative", "clever", "friendly", "lovely", "talkative"} | ||
DefaultRole = "The following is a conversation with Ai assistant. The assistant is" + strings.Join(DefaultCharacter, ",") + "." | ||
) | ||
|
||
type ChatContext struct { | ||
Head string | ||
Character []string | ||
Role string | ||
Old []conversation | ||
New []conversation | ||
MaxSequence int | ||
RestartSequence string | ||
StartSequence string | ||
} | ||
|
||
type conversation struct { | ||
role string | ||
prompt string | ||
} | ||
|
||
func NewContext() *ChatContext { | ||
return &ChatContext{ | ||
Role: DefaultRole, | ||
Head: DefaultHead, | ||
Character: DefaultCharacter, | ||
Old: []conversation{}, | ||
New: []conversation{}, | ||
MaxSequence: 10, | ||
RestartSequence: "\nHuman: ", | ||
StartSequence: "\nAI: ", | ||
} | ||
} | ||
|
||
func (c *ChatGPT) ChatWithContext(question string) { | ||
//promptTable := strings.Builder{} | ||
//promptTable.WriteString(c.ChatContext.Role) | ||
//promptTable.WriteString("\n") | ||
//promptTable.WriteString(c.ChatContext.Head) | ||
//promptTable.WriteString("\n") | ||
// 性能去他妈 | ||
var promptTable []string | ||
promptTable = append(promptTable, c.ChatContext.Role) | ||
promptTable = append(promptTable, c.ChatContext.Head) | ||
for _, v := range c.ChatContext.Old { | ||
promptTable = append(promptTable, v.role+" "+v.prompt) | ||
} | ||
promptTable = append(promptTable, c.ChatContext.RestartSequence+question+".") | ||
|
||
} | ||
|
||
//func (c *ChatGPT) cutPrompt(prompt []string) []string { | ||
// //extra := len(prompt) + c.ChatContext.MaxSequence + "" | ||
//} |