-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b0086b
commit ef3a2df
Showing
19 changed files
with
325 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json", | ||
"packages": ["[email protected]"], | ||
"shell": { | ||
"init_hook": [ | ||
"echo 'Welcome to devbox!' > /dev/null" | ||
], | ||
"scripts": { | ||
"test": [ | ||
"echo \"Error: no test specified\" && exit 1" | ||
] | ||
} | ||
} | ||
} |
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,53 @@ | ||
{ | ||
"lockfile_version": "1", | ||
"packages": { | ||
"[email protected]": { | ||
"last_modified": "2024-08-31T10:12:23Z", | ||
"resolved": "github:NixOS/nixpkgs/5629520edecb69630a3f4d17d3d33fc96c13f6fe#go_1_23", | ||
"source": "devbox-search", | ||
"version": "1.23.0", | ||
"systems": { | ||
"aarch64-darwin": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/4cijk6gwv59c84h1l9yhxzsaz93f67mz-go-1.23.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/4cijk6gwv59c84h1l9yhxzsaz93f67mz-go-1.23.0" | ||
}, | ||
"aarch64-linux": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/mhwsyzk9v43q67ic34c02sxnsnbj7qbh-go-1.23.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/mhwsyzk9v43q67ic34c02sxnsnbj7qbh-go-1.23.0" | ||
}, | ||
"x86_64-darwin": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/vbcqda38ha9gqsbwjw4q0swpwlvmnb1i-go-1.23.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/vbcqda38ha9gqsbwjw4q0swpwlvmnb1i-go-1.23.0" | ||
}, | ||
"x86_64-linux": { | ||
"outputs": [ | ||
{ | ||
"name": "out", | ||
"path": "/nix/store/h5wkf711ql98c59n7yxa146jbjf9vrj5-go-1.23.0", | ||
"default": true | ||
} | ||
], | ||
"store_path": "/nix/store/h5wkf711ql98c59n7yxa146jbjf9vrj5-go-1.23.0" | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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,42 @@ | ||
package ai | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/discord/service" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/view" | ||
"github.com/dwarvesf/fortress-discord/pkg/logger" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type AI struct { | ||
L logger.Logger | ||
svc service.Servicer | ||
view view.Viewer | ||
} | ||
|
||
func New(l logger.Logger, svc service.Servicer, view view.Viewer) AICommander { | ||
return &AI{ | ||
L: l, | ||
svc: svc, | ||
view: view, | ||
} | ||
} | ||
|
||
func (a *AI) ProcessAI(message *model.DiscordMessage) error { | ||
input := strings.TrimSpace(strings.TrimPrefix(message.RawContent, "?ai")) | ||
|
||
if input == "" { | ||
return a.view.Error().Raise(message, "Please provide some text to process.") | ||
} | ||
|
||
// Process the text using the AI service | ||
response, err := a.svc.AI().ProcessText(input) | ||
if err != nil { | ||
a.L.Error(err, "failed to process AI text") | ||
return err | ||
} | ||
|
||
// Send the AI response back to the user | ||
return a.view.AI().SendResponse(message, response) | ||
} |
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,35 @@ | ||
package ai | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (a *AI) Prefix() []string { | ||
return []string{"ai"} | ||
} | ||
|
||
// Execute is where we handle logic for each command | ||
func (a *AI) Execute(message *model.DiscordMessage) error { | ||
// For AI command, we always process the input, regardless of the number of arguments | ||
return a.DefaultCommand(message) | ||
} | ||
|
||
func (a *AI) Name() string { | ||
return "AI Command" | ||
} | ||
|
||
func (a *AI) Help(message *model.DiscordMessage) error { | ||
helpText := "The AI command processes any text input using an AI model.\n\n" + | ||
"Usage: ?ai <your text here>\n" + | ||
"Example: ?ai What is the capital of France?" | ||
|
||
return a.view.Error().Raise(message, helpText) | ||
} | ||
|
||
func (a *AI) DefaultCommand(message *model.DiscordMessage) error { | ||
return a.ProcessAI(message) | ||
} | ||
|
||
func (a *AI) PermissionCheck(message *model.DiscordMessage) (bool, []string) { | ||
return true, []string{} | ||
} |
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,12 @@ | ||
package ai | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/base" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type AICommander interface { | ||
base.TextCommander | ||
|
||
ProcessAI(message *model.DiscordMessage) error | ||
} |
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,34 @@ | ||
package ai | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/adapter" | ||
"github.com/dwarvesf/fortress-discord/pkg/logger" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type AI struct { | ||
adapter adapter.IAdapter | ||
l logger.Logger | ||
} | ||
|
||
func New(adapter adapter.IAdapter, l logger.Logger) AIServicer { | ||
return &AI{ | ||
adapter: adapter, | ||
l: l, | ||
} | ||
} | ||
|
||
func (a *AI) ProcessText(input string) (*model.AIResponse, error) { | ||
response, err := a.adapter.Dify().ProcessAIText(input) | ||
if err != nil { | ||
fmt.Printf("failed to process AI text. Error: %v", err) | ||
return nil, err | ||
} | ||
|
||
return &model.AIResponse{ | ||
Input: input, | ||
Response: response, | ||
}, nil | ||
} |
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,9 @@ | ||
package ai | ||
|
||
import ( | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
type AIServicer interface { | ||
ProcessText(input string) (*model.AIResponse, error) | ||
} |
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
Oops, something went wrong.