Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

claude could use context as well #64

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## 规则

- 第一个消息是系统消息(prompt)
- OPENAI 上下文默认附带最新创建的10条消息, (Claude 模型不带上下文)
- 上下文默认附带最新创建的10条消息
- 第一个注册的用户是管理员
- 默认限流 100 chatGPT call /10分钟 (OPENAI_RATELIMIT=100)

Expand All @@ -23,7 +23,7 @@
## How to Use

- The first message is a system message (prompt)
- by default, the latest 10 messages are context for opeanai model. no context for claude v1.
- by default, the latest 10 messages are context
- First user is superuser.
- 100 chatgpt api call / 10 mins (OPENAI_RATELIMIT=100)

Expand Down
17 changes: 14 additions & 3 deletions api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,30 @@ func chatStreamClaude(w http.ResponseWriter, chatSession sqlc_queries.ChatSessio

// set the url
url := "https://api.anthropic.com/v1/complete"
msg := chat_compeletion_messages[len(chat_compeletion_messages)-1].Content

var sb strings.Builder // create a new strings.Builder
// iterate through the messages and format them
for _, message := range chat_compeletion_messages {
// print the user's question
if message.Role != "assistant" {
sb.WriteString(fmt.Sprintf("\n\nHuman: %s\n\nAssistant: ", message.Content))
} else {
// convert assistant's response to json format
sb.WriteString(fmt.Sprintf("%s\n", message.Content))
}
}
// create the json data
jsonData := map[string]interface{}{
"prompt": "\n\nHuman: " + msg + "\n\nAssistant: ",
"prompt": sb.String(),
"model": "claude-v1",
"max_tokens_to_sample": chatSession.MaxTokens,
"temperature": chatSession.Temperature,
"stop_sequences": []string{"\n\nHuman:"},
"stream": true,
}

// convert data to json format
jsonValue, _ := json.Marshal(jsonData)

// create the request
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue))
if err != nil {
Expand Down