Skip to content

Commit

Permalink
Release v0.0.2 (#35)
Browse files Browse the repository at this point in the history
Update CLI chat to use OpenAI chat completion
  • Loading branch information
seemywingz authored Apr 1, 2023
1 parent c5bf864 commit 7342dbe
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ponder image -p "watercolor of a corgie"

Ponder
GitHub: https://github.com/seemywingz/ponder
App Version: v0.0.1
App Version: v0.0.2

Ponder uses OpenAI's GPT-3.5-Turbo API to generate text responses to user input.
You can use Ponder as a Discord chat bot or to generate images using the DALL-E API.
Expand Down
12 changes: 4 additions & 8 deletions cmd/Discord_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ func discordOpenAIResponse(s *discordgo.Session, m *discordgo.MessageCreate, men
discord.ChannelTyping(m.ChannelID)
openaiMessages := []OPENAI_Message{{
Role: "system",
Content: discord_BotSystemMessage,
Content: discord_SystemMessage,
}}

discordMessages, err := discord.ChannelMessages(m.ChannelID, 30, "", "", "")
discordMessages, err := discord.ChannelMessages(m.ChannelID, 9, "", "", "")
catchErr(err)
discordMessages = discordReverseMessageOrder(discordMessages)

Expand All @@ -141,12 +141,8 @@ func discordOpenAIResponse(s *discordgo.Session, m *discordgo.MessageCreate, men

// Send the messages to OpenAI
openAIUser = ponderID + m.Author.Username
oaiResponse := openai_ChatComplete(openaiMessages)
responseMessage := oaiResponse.Choices[0].Message.Content
// if mention {
// responseMessage = m.Author.Mention() + " " + responseMessage
// }
s.ChannelMessageSend(m.ChannelID, responseMessage)
oaiResponse := openai_ChatCompletion(openaiMessages)
s.ChannelMessageSend(m.ChannelID, oaiResponse)
}

func discordGetChannelName(channelID string) string {
Expand Down
8 changes: 4 additions & 4 deletions cmd/OpenAI_API.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func openAI_ImageGen(prompt, imageFile string, n int) OPENAI_ImageResponse {
return oaiResponse
}

func openai_ChatComplete(messages []OPENAI_Message) OPENAI_ChatCompletionResponse {
func openai_ChatCompletion(messages []OPENAI_Message) string {
oaiResponse := OPENAI_ChatCompletionResponse{}
oaiRequest := OPENAI_ChatCompletionRequest{
Model: "gpt-3.5-turbo",
Expand All @@ -146,15 +146,15 @@ func openai_ChatComplete(messages []OPENAI_Message) OPENAI_ChatCompletionRespons
User: openAIUser,
}
openAI_PostJson(oaiRequest, &oaiResponse, openai_endpoint+"chat/completions")
return oaiResponse
return oaiResponse.Choices[0].Message.Content
}

func openAI_Chat(prompt string) OPENAI_ChatResponse {
func openAI_Completion(prompt string) OPENAI_ChatResponse {
oaiResponse := OPENAI_ChatResponse{}
oaiRequest := &OPENAI_ChatRequest{
Model: "text-davinci-003",
Prompt: prompt,
MaxTokens: 999,
Model: "text-davinci-003",
Temperature: 0,
TopP: 0.1,
FrequencyPenalty: 0.0,
Expand Down
54 changes: 36 additions & 18 deletions cmd/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ import (
"github.com/spf13/cobra"
)

var loop bool
var convo bool
var sayText bool
var ponderMessages = []OPENAI_Message{{
Role: "system",
Content: ponder_SystemMessage,
}}

func init() {
rootCmd.AddCommand(chatCmd)
chatCmd.Flags().BoolVarP(&convo, "convo", "c", false, "Conversational Style chat")
chatCmd.Flags().BoolVarP(&sayText, "say", "s", false, "Say text out loud (MacOS only)")
}

// chatCmd represents the chat command
var chatCmd = &cobra.Command{
Expand All @@ -24,38 +34,38 @@ var chatCmd = &cobra.Command{
Long: ``,
Run: func(cmd *cobra.Command, args []string) {

if loop {
if convo {
for {
fmt.Println("\nYou: ")
prompt, err := getUserInput()
catchErr(err)
fmt.Println("\nPonder: ")
chat(prompt)
fmt.Println("\nPonder:\n", chatCompletion(prompt))
}
} else {
chat(prompt)
textCompletion(prompt)
}

},
}

func init() {
rootCmd.AddCommand(chatCmd)
chatCmd.Flags().BoolVarP(&loop, "loop", "l", false, "Loop chat")
chatCmd.Flags().BoolVarP(&sayText, "say", "s", false, "Say text out loud (MacOS only)")
}
func chatCompletion(prompt string) string {
ponderMessages = append(ponderMessages, OPENAI_Message{
Role: "user",
Content: prompt,
})

func say(phrase string) {
say := exec.Command(`say`, phrase)
err := say.Start()
if err != nil {
fmt.Println(err)
}
// Send the messages to OpenAI
oaiResponse := openai_ChatCompletion(ponderMessages)
ponderMessages = append(ponderMessages, OPENAI_Message{
Role: "assistant",
Content: oaiResponse,
})
return oaiResponse
}

func chat(prompt string) {
func textCompletion(prompt string) {

oaiResponse := openAI_Chat(prompt)
oaiResponse := openAI_Completion(prompt)

for _, v := range oaiResponse.Choices {
text := v.Text
Expand Down Expand Up @@ -83,3 +93,11 @@ func getUserInput() (string, error) {
}
return input, nil
}

func say(phrase string) {
say := exec.Command(`say`, phrase)
err := say.Start()
if err != nil {
fmt.Println(err)
}
}
4 changes: 3 additions & 1 deletion cmd/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ const openai_endpoint = "https://api.openai.com/v1/"

const printify_endpoint = "https://api.printify.com/v1/"

const discord_BotSystemMessage = "You are Ponder. Ponder is here to help you with your Discord needs. Please be respectful and courteous when interacting with Ponder. Ponder will not tolerate any form of harassment, bullying, or discrimination. If you have any questions or concerns, please let us know. Thank you for using Ponder!"
const discord_SystemMessage = "You are Ponder. Ponder is here to help you with your Discord needs. Please be respectful and courteous when interacting with Ponder. Ponder will not tolerate any form of harassment, bullying, or discrimination. If you have any questions or concerns, please let us know. Thank you for using Ponder!"

const ponder_SystemMessage = "You are Ponder.Welcome to Ponder! I'm an advanced chat bot powered by GPT-3.5-Turbo, designed to assist you with your needs and provide helpful responses. Whether you have questions about a particular topic or need assistance with a task, I'm here to help. Please feel free to ask me anything, and I'll do my best to provide you with accurate and informative answers. Thank you for choosing Ponder!"
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func init() {
h := fnv.New32a()
h.Write([]byte(OPENAI_API_KEY))
ponderID = "ponder-" + strconv.Itoa(int(h.Sum32())) + "-"
openAIUser = ponderID + "user"
}

func trace() {
Expand Down
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: v0.0.1
version: v0.0.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.0.1"
appVersion: "v0.0.2"

0 comments on commit 7342dbe

Please sign in to comment.