-
Notifications
You must be signed in to change notification settings - Fork 13
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 #8 from Lumerin-protocol/main
Add
- Loading branch information
Showing
72 changed files
with
10,503 additions
and
755 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,13 @@ | ||
version: '3.8' | ||
services: | ||
ollama: | ||
image: ollama/ollama | ||
container_name: ollama | ||
volumes: | ||
- ollama:/root/.ollama | ||
ports: | ||
- "11434:11434" | ||
restart: unless-stopped | ||
|
||
volumes: | ||
ollama: |
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,14 @@ | ||
package aiengine | ||
|
||
import "context" | ||
|
||
type AiEngine struct { | ||
} | ||
|
||
func NewAiEngine() *AiEngine { | ||
return &AiEngine{} | ||
} | ||
|
||
func (aiEngine *AiEngine) Prompt(ctx context.Context) (string, error) { | ||
return "Hello!", 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,47 @@ | ||
package apibus | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/aiengine" | ||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/proxyapi" | ||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/rpcproxy" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type ApiBus struct { | ||
rpcProxy *rpcproxy.RpcProxy | ||
aiEngine *aiengine.AiEngine | ||
proxyRouterApi *proxyapi.ProxyRouterApi | ||
} | ||
|
||
func NewApiBus(rpcProxy *rpcproxy.RpcProxy, aiEngine *aiengine.AiEngine, proxyRouterApi *proxyapi.ProxyRouterApi) *ApiBus { | ||
return &ApiBus{ | ||
rpcProxy: rpcProxy, | ||
aiEngine: aiEngine, | ||
proxyRouterApi: proxyRouterApi, | ||
} | ||
} | ||
|
||
// Proxy Router Api | ||
func (apiBus *ApiBus) GetConfig(ctx context.Context) interface{} { | ||
return apiBus.proxyRouterApi.GetConfig(ctx) | ||
} | ||
|
||
func (apiBus *ApiBus) GetFiles(ctx *gin.Context) (int, interface{}) { | ||
return apiBus.proxyRouterApi.GetFiles(ctx) | ||
} | ||
|
||
func (apiBus *ApiBus) HealthCheck(ctx context.Context) interface{} { | ||
return apiBus.proxyRouterApi.HealthCheck(ctx) | ||
} | ||
|
||
// AiEngine | ||
func (apiBus *ApiBus) Prompt(ctx context.Context) (string, error) { | ||
return apiBus.aiEngine.Prompt(ctx) | ||
} | ||
|
||
// RpcProxy | ||
func (apiBus *ApiBus) GetLatestBlock(ctx context.Context) (uint64, error) { | ||
return apiBus.rpcProxy.GetLatestBlock(ctx) | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,118 @@ | ||
package proxyapi | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/url" | ||
"os" | ||
"time" | ||
|
||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/config" | ||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/interfaces" | ||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/lib" | ||
"github.com/MorpheusAIs/Morpheus-Lumerin-Node/proxy-router/internal/internal/system" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type Sanitizable interface { | ||
GetSanitized() any | ||
} | ||
|
||
type ConfigResponse struct { | ||
Version string | ||
Commit string | ||
DerivedConfig interface{} | ||
Config interface{} | ||
} | ||
|
||
type ProxyRouterApi struct { | ||
sysConfig *system.SystemConfigurator | ||
publicUrl *url.URL | ||
pubKey string | ||
config Sanitizable | ||
derivedConfig *config.DerivedConfig | ||
appStartTime time.Time | ||
logStorage *lib.Collection[*interfaces.LogStorage] | ||
log interfaces.ILogger | ||
} | ||
|
||
func NewProxyRouterApi(sysConfig *system.SystemConfigurator, publicUrl *url.URL, pubKey string, config Sanitizable, derivedConfig *config.DerivedConfig, appStartTime time.Time, logStorage *lib.Collection[*interfaces.LogStorage], log interfaces.ILogger) *ProxyRouterApi { | ||
return &ProxyRouterApi{ | ||
sysConfig: sysConfig, | ||
publicUrl: publicUrl, | ||
pubKey: pubKey, | ||
config: config, | ||
derivedConfig: derivedConfig, | ||
appStartTime: appStartTime, | ||
logStorage: logStorage, | ||
log: log, | ||
} | ||
} | ||
|
||
func (p *ProxyRouterApi) GetConfig(ctx context.Context) ConfigResponse { | ||
return ConfigResponse{ | ||
Version: config.BuildVersion, | ||
Commit: config.Commit, | ||
Config: p.config.GetSanitized(), | ||
DerivedConfig: p.derivedConfig, | ||
} | ||
} | ||
|
||
func (p *ProxyRouterApi) HealthCheck(ctx context.Context) gin.H { | ||
return gin.H{ | ||
"status": "healthy", | ||
"version": config.BuildVersion, | ||
"uptime": time.Since(p.appStartTime).Round(time.Second).String(), | ||
} | ||
} | ||
|
||
func (p *ProxyRouterApi) GetFiles(ctx *gin.Context) (int, gin.H) { | ||
files, err := p.sysConfig.GetFileDescriptors(ctx, os.Getpid()) | ||
if err != nil { | ||
return 500, gin.H{"error": err.Error()} | ||
} | ||
|
||
systemCfg, err := p.sysConfig.GetConfig() | ||
if err != nil { | ||
fmt.Fprintf(ctx.Writer, "failed to get system config: %s\n", err) | ||
} else { | ||
json, err := json.Marshal(systemCfg) | ||
if err != nil { | ||
fmt.Fprintf(ctx.Writer, "failed to marshal system config: %s\n", err) | ||
} else { | ||
fmt.Fprintf(ctx.Writer, "system config: %s\n", json) | ||
} | ||
} | ||
|
||
fmt.Fprintf(ctx.Writer, "\n") | ||
|
||
err = writeFiles(ctx.Writer, files) | ||
if err != nil { | ||
p.log.Errorf("failed to write files: %s", err) | ||
_ = ctx.Error(err) | ||
ctx.Abort() | ||
} | ||
return 200, gin.H{} | ||
} | ||
|
||
func writeFiles(writer io.Writer, files []system.FD) error { | ||
text := fmt.Sprintf("Total: %d\n", len(files)) | ||
text += "\n" | ||
text += "fd\tpath\n" | ||
|
||
_, err := fmt.Fprintf(writer, text) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, f := range files { | ||
_, err := fmt.Fprintf(writer, "%s\t%s\n", f.ID, f.Path) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.