Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3af6192633 | ||
|
|
5b75b51059 | ||
|
|
49b89d5aad | ||
|
|
87386c5061 |
10
README.md
10
README.md
@@ -1,4 +1,4 @@
|
||||
# Real-time ChatGPT service, support GPT3/GPT4
|
||||
# Real-time ChatGPT service, support GPT3/GPT4, support conversation and generate pictures from sentences
|
||||
|
||||
- [English README](README.md)
|
||||
- [中文 README](README_CN.md)
|
||||
@@ -17,8 +17,13 @@
|
||||
|
||||
## Demo
|
||||
|
||||
- Real-time conversation mode
|
||||
|
||||

|
||||
|
||||
- Generate picture patterns from sentences
|
||||
|
||||

|
||||
|
||||
## Quick start
|
||||
|
||||
@@ -36,6 +41,9 @@ vi config.yaml
|
||||
# your openai.com API key
|
||||
apiKey: "xxxxxx"
|
||||
|
||||
# create pictures directory
|
||||
mkdir -p assets
|
||||
chown -R 1000:1000 assets
|
||||
|
||||
# Start the service with docker-compose
|
||||
docker-compose up -d
|
||||
|
||||
10
README_CN.md
10
README_CN.md
@@ -1,4 +1,4 @@
|
||||
# 实时ChatGPT服务,支持GPT3/GPT4
|
||||
# 实时ChatGPT服务,支持GPT3/GPT4,支持对话和通过句子生成图片
|
||||
|
||||
- [English README](README.md)
|
||||
- [中文 README](README_CN.md)
|
||||
@@ -17,8 +17,13 @@
|
||||
|
||||
## 效果图
|
||||
|
||||
- 实时对话模式
|
||||
|
||||

|
||||
|
||||
- 通过句子生成图片模式
|
||||
|
||||

|
||||
|
||||
## 快速开始
|
||||
|
||||
@@ -36,6 +41,9 @@ vi config.yaml
|
||||
# openai的apiKey,改为你的apiKey
|
||||
apiKey: "xxxxxx"
|
||||
|
||||
# 创建生成的图片目录
|
||||
mkdir -p assets
|
||||
chown -R 1000:1000 assets
|
||||
|
||||
# 使用docker-compose启动服务
|
||||
docker-compose up -d
|
||||
|
||||
@@ -76,7 +76,7 @@ func (api *Api) wsPingMsg(conn *websocket.Conn, chClose, chIsCloseSet chan int)
|
||||
}
|
||||
}
|
||||
|
||||
func (api *Api) GetChatMessage(conn *websocket.Conn, cli *openai.Client, mutex *sync.Mutex, requestMsg string) {
|
||||
func (api *Api) GetChatMessage(conn *websocket.Conn, cli *openai.Client, mutex *sync.Mutex, reqMsgs []openai.ChatCompletionMessage) {
|
||||
var err error
|
||||
var strResp string
|
||||
|
||||
@@ -84,16 +84,12 @@ func (api *Api) GetChatMessage(conn *websocket.Conn, cli *openai.Client, mutex *
|
||||
|
||||
switch api.Config.Model {
|
||||
case openai.GPT3Dot5Turbo0301, openai.GPT3Dot5Turbo, openai.GPT4, openai.GPT40314, openai.GPT432K0314, openai.GPT432K:
|
||||
prompt := reqMsgs[len(reqMsgs)-1].Content
|
||||
req := openai.ChatCompletionRequest{
|
||||
Model: api.Config.Model,
|
||||
MaxTokens: api.Config.MaxLength,
|
||||
Temperature: 1.0,
|
||||
Messages: []openai.ChatCompletionMessage{
|
||||
{
|
||||
Role: openai.ChatMessageRoleUser,
|
||||
Content: requestMsg,
|
||||
},
|
||||
},
|
||||
Model: api.Config.Model,
|
||||
MaxTokens: api.Config.MaxLength,
|
||||
Temperature: 1.0,
|
||||
Messages: reqMsgs,
|
||||
Stream: true,
|
||||
TopP: 1,
|
||||
FrequencyPenalty: 0.1,
|
||||
@@ -151,7 +147,7 @@ func (api *Api) GetChatMessage(conn *websocket.Conn, cli *openai.Client, mutex *
|
||||
if len(response.Choices) > 0 {
|
||||
var s string
|
||||
if i == 0 {
|
||||
s = fmt.Sprintf(`%s# %s`, s, requestMsg)
|
||||
s = fmt.Sprintf("%s# %s\n\n", s, prompt)
|
||||
}
|
||||
for _, choice := range response.Choices {
|
||||
s = s + choice.Delta.Content
|
||||
@@ -173,11 +169,12 @@ func (api *Api) GetChatMessage(conn *websocket.Conn, cli *openai.Client, mutex *
|
||||
api.Logger.LogInfo(fmt.Sprintf("[RESPONSE] %s\n", strResp))
|
||||
}
|
||||
case openai.GPT3TextDavinci003, openai.GPT3TextDavinci002, openai.GPT3TextCurie001, openai.GPT3TextBabbage001, openai.GPT3TextAda001, openai.GPT3TextDavinci001, openai.GPT3DavinciInstructBeta, openai.GPT3Davinci, openai.GPT3CurieInstructBeta, openai.GPT3Curie, openai.GPT3Ada, openai.GPT3Babbage:
|
||||
prompt := reqMsgs[len(reqMsgs)-1].Content
|
||||
req := openai.CompletionRequest{
|
||||
Model: api.Config.Model,
|
||||
MaxTokens: api.Config.MaxLength,
|
||||
Temperature: 0.6,
|
||||
Prompt: requestMsg,
|
||||
Prompt: prompt,
|
||||
Stream: true,
|
||||
//Stop: []string{"\n\n\n"},
|
||||
TopP: 1,
|
||||
@@ -236,7 +233,7 @@ func (api *Api) GetChatMessage(conn *websocket.Conn, cli *openai.Client, mutex *
|
||||
if len(response.Choices) > 0 {
|
||||
var s string
|
||||
if i == 0 {
|
||||
s = fmt.Sprintf(`%s# %s`, s, requestMsg)
|
||||
s = fmt.Sprintf("%s# %s\n\n", s, prompt)
|
||||
}
|
||||
for _, choice := range response.Choices {
|
||||
s = s + choice.Text
|
||||
@@ -393,6 +390,8 @@ func (api *Api) WsChat(c *gin.Context) {
|
||||
api.Logger.LogInfo(fmt.Sprintf("websocket connection open"))
|
||||
cli := openai.NewClient(api.Config.ApiKey)
|
||||
|
||||
reqMsgs := make([]openai.ChatCompletionMessage, 0)
|
||||
|
||||
var latestRequestTime time.Time
|
||||
for {
|
||||
if isClosed {
|
||||
@@ -466,7 +465,11 @@ func (api *Api) WsChat(c *gin.Context) {
|
||||
mutex.Lock()
|
||||
_ = conn.WriteJSON(chatMsg)
|
||||
mutex.Unlock()
|
||||
go api.GetChatMessage(conn, cli, mutex, requestMsg)
|
||||
reqMsgs = append(reqMsgs, openai.ChatCompletionMessage{
|
||||
Role: openai.ChatMessageRoleUser,
|
||||
Content: requestMsg,
|
||||
})
|
||||
go api.GetChatMessage(conn, cli, mutex, reqMsgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
chatgpt-image.jpeg
Normal file
BIN
chatgpt-image.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
@@ -18,5 +18,6 @@ services:
|
||||
- "9000:9000"
|
||||
volumes:
|
||||
- ./config.yaml:/chatgpt-service/config.yaml
|
||||
- ./assets:/chatgpt-service/assets
|
||||
command: /chatgpt-service/chatgpt-service
|
||||
restart: always
|
||||
|
||||
Reference in New Issue
Block a user