Skip to content

Commit

Permalink
v0.3.0 (#40)
Browse files Browse the repository at this point in the history
* v0.3.0
  • Loading branch information
seemywingz authored Dec 12, 2023
1 parent 0e62308 commit 0d5b35e
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 180 deletions.
21 changes: 13 additions & 8 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ DISCORD_PUB_KEY={YOUR DISCORD BOT PUB KEY}
## Ponder a single thought
### CLI
```bash
ponder chat --prompt "AI is Amazing"
ponder --prompt "AI is Amazing"
```
### Docker
#### Running ponder in docker is exactly the same, but you have to provide the env vars when running
```bash
docker run -e OPENAI_API_KEY=$OPENAI_API_KEY ghcr.io/seemywingz/ponder:latest chat --prompt "Ai is Amazing"
docker run -e OPENAI_API_KEY=$OPENAI_API_KEY ghcr.io/seemywingz/ponder:latest --prompt "Ai is Amazing"
```
#### Example Output
```bash
Expand All @@ -44,7 +44,7 @@ AI is indeed amazing. It has the potential to revolutionize many industries, fro

## A small chat
```bash
ponder chat --convo
ponder --convo
```
#### Example Ouput
```bash
Expand All @@ -63,28 +63,30 @@ Thank you for your kind words!

## Image Generation
```bash
ponder image -p "watercolor of a corgie"
ponder image -p "a ferocious cat with wings and fire"
```
#### Example Ouput
```bash
🖼 Creating Image...
🌐 Image URL: https://oaidalleapiprodscus.blob.core.windows.net/private/org-RCMQxIXre0Olhs0AvLVp672o/user-F1wdcIVNf2VrRqBRD0JWUczI/img-AWku5cm91XAv32jj27XWXZBE.png?st=2023-03-05T05%3A19%3A33Z&se=2023-03-05T07%3A19%3A33Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-03-05T01%3A25%3A44Z&ske=2023-03-06T01%3A25%3A44Z&sks=b&skv=2021-08-06&sig=xs9vSD0nA0mkxyulHEKABn5cbWH%2B6YOpab25yTAU/nc%3D
🌐 Image URL: https://oaidalleapiprodscus.blob.core.windows.net/private/org-RCMQxIXre0Olhs0AvLVp672o/user-F1wdcIVNf2VrRqBRD0JWUczI/img-B4gaFhJQFl25authc5zMdw3T.png?st=2023-12-12T19%3A42%3A45Z&se=2023-12-12T21%3A42%3A45Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-12-12T05%3A22%3A04Z&ske=2023-12-13T05%3A22%3A04Z&sks=b&skv=2021-08-06&sig=RteaU2hpHlz5VElxgxdwUahGHoQmy6SEAVdpsjDbt%2Bg%3D
```

### You can always refer to the `--help` menu as well.
```yaml
Ponder
GitHub: https://github.com/seemywingz/ponder
App Version: v0.1.0
App Version: v0.3.0

Ponder uses OpenAI's GPT-3.5-Turbo API to generate text responses to user input.
Ponder uses OpenAI's 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.
Or whatever else you can think of...

Usage:
ponder [flags]
ponder [command]

Available Commands:
adventure lets you dive into a captivating text adventure
chat Open ended chat with OpenAI
completion Generate the autocompletion script for the specified shell
discord-bot Discord Chat Bot Integration
Expand All @@ -93,9 +95,12 @@ Available Commands:
printify Interact with the Printify API

Flags:
--config string config file (default "$HOME/.ponder/config")
--config string config file
-c, --convo Conversational Style chat
-h, --help help for ponder
-x, --perform Attempt to perform the response as cli command
-p, --prompt string Prompt AI generation
-s, --say Say text out loud (MacOS only)
-v, --verbose verbose output

Use "ponder [command] --help" for more information about a command.
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM golang:1.20.1-alpine3.17 AS builder
FROM golang:1.21.5-alpine3.19 AS builder
ENV APP_NAME ponder
ENV WORKDIR /app
WORKDIR $WORKDIR
Expand All @@ -8,7 +8,7 @@ RUN go mod download
RUN go build -o /$APP_NAME

## Deploy
FROM alpine:3.17.2
FROM alpine:3.19.0
ENV APP_NAME ponder
WORKDIR /
COPY --from=builder /$APP_NAME /$APP_NAME
Expand Down
111 changes: 70 additions & 41 deletions cmd/Discord_api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"log"
"strings"

Expand Down Expand Up @@ -29,12 +28,12 @@ func initDiscord() {
registerCommands()
deregisterCommands()

log.Println("Ponder Discord Bot is now running...")
log.Println("🤖 Ponder Discord Bot is Running...")
select {} // Block forever to prevent the program from terminating.
}

func setStatusOnline() {
fmt.Println("Setting Status to Online...")
log.Println("🛜 Setting Status to Online...")
// Set status to online with active activity
err := discord.UpdateStatusComplex(discordgo.UpdateStatusData{
Status: "online",
Expand All @@ -50,43 +49,61 @@ func setStatusOnline() {
}

func registerHandlers() {
fmt.Println("Registering Handlers...")
// A handler function for the "interactionCreate" event
log.Println("💾 Registering Handlers...")
discord.AddHandler(handleCommands)
// Add a handler function for the "messageCreate" event
discord.AddHandler(handleMessages)
}

func deregisterCommands() {
fmt.Println("Deregistering Slash Commands...")
// Set the ID of the slash command to deregister
slashCommandIDs := []string{}

for _, slashCommandID := range slashCommandIDs {
err := discord.ApplicationCommandDelete(discord.State.User.ID, "", slashCommandID)
if err != nil {
fmt.Println("Error deleting slash command: ", err)
return

if removeCMDIds != "" {
slashCommandIDs := strings.Split(removeCMDIds, ",")
for _, slashCommandID := range slashCommandIDs {
log.Println("➖ Removing Command: ", slashCommandID)
err := discord.ApplicationCommandDelete(discord.State.User.ID, "", slashCommandID)
if err != nil {
log.Println("Error deleting slash command: ", err)
return
}
}
}
}

func registerCommands() {
fmt.Println("Registering Slash Commands...")
// /chat command
command := &discordgo.ApplicationCommand{
Name: "scrape",
Description: "Scrape Discord channel for Upscaled Midjourney Images!",

commands := []*discordgo.ApplicationCommand{
{
Name: "scrape",
Description: "Scrape Discord channel for Upscaled Midjourney Images",
},
{
Name: "ponder-image",
Description: "Use DALL-E 3 to generate an Image",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "prompt",
Description: "Prompt for Image Generation",
Required: true,
},
},
},
}

for _, command := range commands {
log.Println("➕ Adding Command: /"+command.Name, "-", command.Description)
_, err := discord.ApplicationCommandCreate(discord.State.User.ID, "", command)
catchErr(err)
}
_, err := discord.ApplicationCommandCreate(discord.State.User.ID, "", command)
catchErr(err)
}

func handleCommands(s *discordgo.Session, i *discordgo.InteractionCreate) {
discordInitialResponse("Thinking...", s, i)
discordInitialResponse("Pondering...", s, i)
switch i.ApplicationCommandData().Name {
case "scrape":
discordScrapeImages(s, i)
case "ponder-image":
discordPonderImage(s, i)
default: // Handle unknown slash commands
log.Printf("Unknown Ponder Command: %s", i.ApplicationCommandData().Name)
}
Expand Down Expand Up @@ -142,35 +159,34 @@ func discordOpenAIResponse(s *discordgo.Session, m *discordgo.MessageCreate, men
}

// Send the messages to OpenAI
openai.User = openai.User + m.Author.Username
oaiResponse, err := openai.ChatCompletion(openaiMessages)
ai.User = ai.User + m.Author.Username
oaiResponse, err := ai.ChatCompletion(openaiMessages)
catchErr(err)
s.ChannelMessageSend(m.ChannelID, oaiResponse.Choices[0].Message.Content)
}

// func discordGetChannelName(channelID string) string {
// channel, err := discord.Channel(channelID)
// catchErr(err)
// return channel.Name
// }

func discordGetChannelID(s *discordgo.Session, guildID string, channelName string) string {
channels, err := s.GuildChannels(guildID)
catchErr(err)

for _, channel := range channels {
if channel.Name == channelName {
return channel.ID
}
func discordPonderImage(s *discordgo.Session, i *discordgo.InteractionCreate) {
channelID := i.ChannelID
discord.ChannelTyping(channelID)
commandData := i.ApplicationCommandData()

// Check if there are options and retrieve the prompt
if len(commandData.Options) > 0 {
promptOption := commandData.Options[0]
prompt := promptOption.StringValue()
discordFollowUp("Using DALL-E 3 to generate an image: "+prompt, s, i)
res := ai.ImageGen(prompt, "", 1)
s.ChannelMessageSend(channelID, res.Data[0].URL)
} else {
discordFollowUp("Please Provide a Prompt for Image Generation", s, i)
}

return ""
}

func discordScrapeImages(s *discordgo.Session, i *discordgo.InteractionCreate) {
discord.ChannelTyping(i.ChannelID)
// Get the interaction channel ID
channelID := i.ChannelID
discord.ChannelTyping(channelID)
messages, err := discord.ChannelMessages(channelID, 100, "", "", "")
catchErr(err)
discordFollowUp("Scraping Discord Channel for ALL Image URLs and sending them to #saved-images.\nAll `Upscaled` Midjourney Images will be sent to Printify as well...", s, i)
Expand Down Expand Up @@ -201,6 +217,19 @@ func discordInitialResponse(content string, s *discordgo.Session, i *discordgo.I
catchErr(err)
}

func discordGetChannelID(s *discordgo.Session, guildID string, channelName string) string {
channels, err := s.GuildChannels(guildID)
catchErr(err)

for _, channel := range channels {
if channel.Name == channelName {
return channel.ID
}
}

return ""
}

func discordFollowUp(message string, s *discordgo.Session, i *discordgo.InteractionCreate) {
followup := &discordgo.WebhookParams{
Content: message,
Expand Down
5 changes: 0 additions & 5 deletions cmd/Discord_json.go

This file was deleted.

32 changes: 26 additions & 6 deletions cmd/adventure.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ Proceed wisely, for Your Character's path is filled with challenges and secrets
The key to success lies not only in your strategic thinking but also in your adherence to the rules and limitations set by this realm.
May your journey be both thrilling and strategic as you navigate this richly detailed realm!
only provide the stats if asked or the character leveled up.
`

var generateImages = false
var adventureMessages = []goai.Message{}

// adventureCmd represents the adventure command
Expand All @@ -81,15 +84,15 @@ var adventureCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(adventureCmd)
adventureCmd.Flags().BoolVarP(&sayText, "say", "s", false, "Say text out loud (MacOS only)")
adventureCmd.Flags().BoolVarP(&generateImages, "images", "i", false, "Generate Images")
}

func adventureChat(prompt string) string {
adventureMessages = append(adventureMessages, goai.Message{
Role: "user",
Content: prompt,
})
oaiResponse, err := openai.ChatCompletion(adventureMessages)
oaiResponse, err := ai.ChatCompletion(adventureMessages)
catchErr(err)
adventureMessages = append(adventureMessages, goai.Message{
Role: "assistant",
Expand All @@ -98,9 +101,9 @@ func adventureChat(prompt string) string {
return oaiResponse.Choices[0].Message.Content
}

func adventureImage(prompt, imageFile string) {
func adventureImage(prompt string) {
fmt.Println("🖼 Creating Image...")
res := openai.ImageGen(prompt, "", 1)
res := ai.ImageGen(prompt, "", 1)

url := res.Data[0].URL
// fmt.Println("🌐 Image URL: " + url)
Expand Down Expand Up @@ -153,6 +156,14 @@ func getPlayerInput(player *Character) string {
return playerInput
}

func totalMessageCharacters() int {
totalCharacters := 0
for _, message := range adventureMessages {
totalCharacters += len(message.Content)
}
return totalCharacters
}

func startAdventure() {
narratorSay("Please type your name.")
playerName, err := getUserInput()
Expand Down Expand Up @@ -187,12 +198,21 @@ func startAdventure() {

startMessage := adventureChat("My name is " + player.Name + " start adventure")
narratorSay(startMessage)
// adventureImage(startMessage, startMessage)
if generateImages {
adventureImage(startMessage)
}

for {

if totalMessageCharacters() > 4096 {
adventureMessages = append(adventureMessages[:2], adventureMessages[3:]...)
}

playerInput := getPlayerInput(&player)
adventureResponse := adventureChat(playerInput)
narratorSay(adventureResponse)
// adventureImage(adventureResponse, adventureResponse)
if generateImages {
adventureImage(adventureResponse)
}
}
}
Loading

0 comments on commit 0d5b35e

Please sign in to comment.