Skip to content

Commit

Permalink
use flatbuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonwang371 committed Jan 1, 2025
1 parent b50be2f commit 12f3d50
Show file tree
Hide file tree
Showing 144 changed files with 4,323 additions and 4,554 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
bin
bin/dummy_task
bin/worker
bin/spearlet
.idea
.DS_Store
*.whl
*.egg-info
sdk/python/dist
sdk/python/dist
__pycache__
56 changes: 39 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@

PROJECT_ROOT := $(shell pwd)
OUTPUT_DIR := $(PROJECT_ROOT)/bin
REPO_ROOT := $(shell pwd)
OUTPUT_DIR := $(REPO_ROOT)/bin


all: clean worker workload sdk
all: clean spearlet workload sdk


SUBDIRS := $(shell find $(REPO_ROOT) -mindepth 1 -maxdepth 3 -type d -exec test -e {}/Makefile \; -exec echo {} \;)
WORKLOAD_SUBDIRS := $(shell find $(REPO_ROOT)/workload -mindepth 1 -maxdepth 3 -type d -exec test -e {}/Makefile \; -exec echo {} \;)

clean:
@set -ex; \
docker system prune -f && \
rm -rf $(OUTPUT_DIR) && \
find $(PROJECT_ROOT)/workload -mindepth 1 -maxdepth 3 -type d -exec test -e {}/Makefile \; -exec make -C {} clean \;
find $(PROJECT_ROOT)/sdk -mindepth 1 -maxdepth 2 -type d -exec test -e {}/Makefile \; -exec make -C {} clean \;

worker:
go build -o $(OUTPUT_DIR)/worker \
$(PROJECT_ROOT)/cmd/worker/main.go
rm -rf $(REPO_ROOT)/pkg/spear && \
for dir in $(SUBDIRS); do \
make -C $$dir clean; \
done

test: workload
go test -v $(PROJECT_ROOT)/test/...
build: spearlet
@set -e; \
for dir in $(SUBDIRS); do \
make -C $$dir build; \
done

workload: sdk
find $(PROJECT_ROOT)/workload -mindepth 1 -maxdepth 3 -type d -exec test -e {}/Makefile \; -exec echo "make -C {}" \; -exec make -C {} \;
spearlet: pkg/spear
go build -o $(OUTPUT_DIR)/spearlet \
$(REPO_ROOT)/cmd/spearlet/main.go

sdk:
find $(PROJECT_ROOT)/sdk -mindepth 1 -maxdepth 2 -type d -exec test -e {}/Makefile \; -exec make -C {} \;
test: workload
@set -e; \
go test -v $(REPO_ROOT)/test/... && \
for dir in $(SUBDIRS); do \
make -C $$dir test; \
done

workload: build
@set -e; \
for dir in $(WORKLOAD_SUBDIRS); do \
make -C $$dir; \
done

format_python:
isort -rc $(PROJECT_ROOT)/
isort -rc $(REPO_ROOT)/

format_golang:
gofmt -w .

format: format_python format_golang

.PHONY: all worker test workload clean sdk format_python format
pkg/spear:
allfiles=`find ${REPO_ROOT}/proto -name "*.fbs"`; \
flatc -o $(REPO_ROOT)/pkg/ -I ${REPO_ROOT}/proto --go-module-name "github.com/lfedgeai/spear/pkg" --go $${allfiles}

.PHONY: all spearlet test workload clean format_python format
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SPEAR is an advanced AI Agent platform designed to support multiple runtime envi
```bash
python -m pip install --upgrade pip
pip install build
apt install portaudio19-dev libx11-dev libxtst-dev
apt install portaudio19-dev libx11-dev libxtst-dev flatbuffers-compiler
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
```
Expand All @@ -105,11 +105,11 @@ To run SPEAR in local mode, use the following command:
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
export HUGGINGFACEHUB_API_TOKEN=<YOUR_HUGGINGFACEHUB_API_TOKEN>
export SPEAR_RPC_ADDR=<YOUR_LOCAL_SPEAR_RPC_ADDR>
bin/worker exec -n pyconversation
bin/spearlet exec -n pyconversation
```

This command will:
- Start the SPEAR worker process in local mode.
- Start the SPEAR spearlet process in local mode.
- Run the AI agent workload with an ID of 6. (pyconversation-local)

Also, you need to set the environment variable `OPENAI_API_KEY` to your OpenAI API key. In the future, we will support other LLM providers.
Expand All @@ -122,7 +122,7 @@ Also, you need to set the environment variable `OPENAI_API_KEY` to your OpenAI A
PortAudio is required for the audio processing component. To install PortAudio on MacOS, use the following command:

```bash
brew install portaudio
brew install portaudio flatbuffers
```
### Build Instructions

Expand All @@ -142,11 +142,11 @@ To run SPEAR in local mode, use the following command:

```bash
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
bin/worker exec -n pyconversation
bin/spearlet exec -n pyconversation
```

This command will:
- Start the SPEAR worker process in local mode.
- Start the SPEAR spearlet process in local mode.
- Run the AI agent workload with an ID of 6. (pyconversation-local)

Also, you need to set the environment variable `OPENAI_API_KEY` to your OpenAI API key. In the future, we will support other LLM providers.
Expand Down
26 changes: 13 additions & 13 deletions cmd/worker/main.go → cmd/spearlet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package main

import (
"github.com/lfedgeai/spear/pkg/common"
"github.com/lfedgeai/spear/worker"
"github.com/lfedgeai/spear/worker/task"
spearlet "github.com/lfedgeai/spear/spearlet"
"github.com/lfedgeai/spear/spearlet/task"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"os"
)

type WorkerConfig struct {
type SpearletConfig struct {
Addr string
Port string
}
Expand All @@ -27,8 +27,8 @@ var (

func NewRootCmd() *cobra.Command {
var rootCmd = &cobra.Command{
Use: "worker",
Short: "Worker is the command line tool for the worker",
Use: "spearlet",
Short: "spearlet is the command line tool for the SPEAR spearlet",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Expand Down Expand Up @@ -65,12 +65,12 @@ func NewRootCmd() *cobra.Command {
log.Infof("Executing workload %s with runtime type %v", execWorkloadName, rtType)
// set log level
if execVerbose {
worker.SetLogLevel(log.DebugLevel)
spearlet.SetLogLevel(log.DebugLevel)
}

// create config
config := worker.NewExecWorkerConfig(execDebug, execSpearAddr)
w := worker.NewWorker(config)
config := spearlet.NewExecSpearletConfig(execDebug, execSpearAddr)
w := spearlet.NewSpearlet(config)
w.Initialize()

// lookup task id
Expand Down Expand Up @@ -110,7 +110,7 @@ func NewRootCmd() *cobra.Command {

var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start the worker server",
Short: "Start the spearlet server",
Run: func(cmd *cobra.Command, args []string) {
// parse flags
addr, _ := cmd.Flags().GetString("addr")
Expand All @@ -121,17 +121,17 @@ func NewRootCmd() *cobra.Command {

// set log level
if verbose {
worker.SetLogLevel(log.DebugLevel)
spearlet.SetLogLevel(log.DebugLevel)
}

if execSpearAddr == "" {
execSpearAddr = common.SpearPlatformAddress
}

// create config
config := worker.NewServeWorkerConfig(addr, port, paths,
config := spearlet.NewServeSpearletConfig(addr, port, paths,
debug, execSpearAddr)
w := worker.NewWorker(config)
w := spearlet.NewSpearlet(config)
w.Initialize()
w.StartServer()
},
Expand All @@ -144,7 +144,7 @@ func NewRootCmd() *cobra.Command {
serveCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
// search path
serveCmd.PersistentFlags().StringArrayP("search-path", "L", []string{},
"search path list for the worker")
"search path list for the spearlet")
// debug flag
serveCmd.PersistentFlags().BoolP("debug", "d", false, "debug mode")
rootCmd.AddCommand(serveCmd)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ require (
github.com/chromedp/chromedp v0.11.2
github.com/faiface/beep v1.1.0
github.com/go-vgo/robotgo v0.110.5
github.com/google/flatbuffers v24.3.25+incompatible
github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5
github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down
13 changes: 12 additions & 1 deletion pkg/common/const.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package common

import "runtime"

const MaxDataResponseSize = 4096 * 1024
const SpearPlatformAddress = "172.17.0.1"

var SpearPlatformAddress string

func init() {
SpearPlatformAddress = map[string]string{
"darwin": "host.docker.internal",
"linux": "172.17.0.1",
"windows": "host.docker.internal",
}[runtime.GOOS]
}
Loading

0 comments on commit 12f3d50

Please sign in to comment.