-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from TimeleapLabs/develop
v0.13
- Loading branch information
Showing
153 changed files
with
7,628 additions
and
5,073 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
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,50 @@ | ||
package handler | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/TimeleapLabs/unchained/cmd/handler/plugins" | ||
"github.com/gorilla/websocket" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var conn *websocket.Conn | ||
|
||
func Read() <-chan []byte { | ||
out := make(chan []byte) | ||
|
||
go func() { | ||
for { | ||
_, payload, err := conn.ReadMessage() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
out <- payload | ||
} | ||
}() | ||
|
||
return out | ||
} | ||
|
||
// plugin represents the plugin command. | ||
var plugin = &cobra.Command{ | ||
Use: "plugin", | ||
Short: "Run an Unchained plugin locally", | ||
Long: `Run an Unchained plugin locally`, | ||
|
||
Run: func(cmd *cobra.Command, _ []string) { | ||
os.Exit(1) | ||
}, | ||
} | ||
|
||
// WithPluginCmd appends the plugin command to the root command. | ||
func WithPluginCmd(cmd *cobra.Command) { | ||
cmd.AddCommand(plugin) | ||
} | ||
|
||
func init() { | ||
plugins.WithAIPluginCmd(plugin) | ||
plugins.WithTextToImagePluginCmd(plugin) | ||
plugins.WithTranslatePluginCmd(plugin) | ||
} |
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,41 @@ | ||
package plugins | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/TimeleapLabs/unchained/internal/service/ai" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// worker represents the worker command. | ||
var aiPlugin = &cobra.Command{ | ||
Use: "ai", | ||
Short: "Start the Unchained ai server for local invocation", | ||
Long: `Start the Unchained ai server for local invocation`, | ||
|
||
Run: func(cmd *cobra.Command, _ []string) { | ||
wg, cancel := ai.StartServer(cmd.Context()) | ||
|
||
// Set up signal handling | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) | ||
|
||
go func() { | ||
sig := <-sigChan | ||
log.Printf("Received signal: %v. Shutting down gracefully...", sig) | ||
cancel() // Cancel the context to stop all managed processes | ||
}() | ||
|
||
// Wait for all processes to finish | ||
wg.Wait() | ||
log.Println("All processes have been stopped.") | ||
}, | ||
} | ||
|
||
// WithRunCmd appends the run command to the root command. | ||
func WithAIPluginCmd(cmd *cobra.Command) { | ||
cmd.AddCommand(aiPlugin) | ||
} |
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,41 @@ | ||
package plugins | ||
|
||
import "github.com/gorilla/websocket" | ||
|
||
var conn *websocket.Conn | ||
var closed = false | ||
|
||
func Read() <-chan []byte { | ||
out := make(chan []byte) | ||
|
||
go func() { | ||
for { | ||
_, payload, err := conn.ReadMessage() | ||
if err != nil { | ||
if !closed { | ||
panic(err) | ||
} | ||
} | ||
|
||
out <- payload | ||
} | ||
}() | ||
|
||
return out | ||
} | ||
|
||
func CloseSocket() { | ||
if conn != nil { | ||
closed = true | ||
err := conn.WriteMessage( | ||
websocket.CloseMessage, | ||
websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) | ||
if err != nil { | ||
return | ||
} | ||
err = conn.Close() | ||
if err != nil { | ||
return | ||
} | ||
} | ||
} |
Oops, something went wrong.