Skip to content

Commit

Permalink
#29: Merge remote-tracking branch 'origin/develop' into 29-setup-open…
Browse files Browse the repository at this point in the history
…ai-client
  • Loading branch information
mkrueger12 committed Dec 26, 2023
2 parents a9598e9 + 9ddf477 commit 5a858a6
Show file tree
Hide file tree
Showing 21 changed files with 394 additions and 35 deletions.
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.21
23 changes: 23 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ linters:
- nolintlint
- revive
- staticcheck
- asasalint
- bodyclose
- contextcheck
- cyclop
- dupword
- errname
- exhaustive
- loggercheck
- misspell
- nestif
- perfsprint
- prealloc
- predeclared
- testifylint
- unconvert
- usestdlibvars
- wsl

linters-settings:
govet:
Expand All @@ -17,3 +34,9 @@ linters-settings:
- reflectvaluecompare
- sortslice
- unusedwrite
- defers
- atomic
- nilfunc
- printf
- sortslice
- tests
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ help:
install-checkers: ## Install static checkers
@echo "🚚 Downloading binaries.."
@GOBIN=$(CHECKER_BIN) go install mvdan.cc/gofumpt@latest
@GOBIN=$(CHECKER_BIN) go install go.uber.org/nilaway/cmd/nilaway@latest
@GOBIN=$(CHECKER_BIN) go install golang.org/x/vuln/cmd/govulncheck@latest
@GOBIN=$(CHECKER_BIN) go install github.com/securego/gosec/v2/cmd/gosec@latest

Expand All @@ -32,8 +31,6 @@ lint: install-checkers ## Lint the source code
static-checks: install-checkers ## Static Analysis
@echo "🧹 GoCI Lint.."
@golangci-lint run ./...
@echo "🧹 Nilaway.."
@$(CHECKER_BIN)/nilaway ./...

vuln: install-checkers ## Check for vulnerabilities
@echo "🔍 Checking for vulnerabilities"
Expand Down
84 changes: 71 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@
# Glide - An LLM Routing Engine
Achieve 100% uptime for your Generative AI applications. Glide sits between your applications and your API endpoint. Pass your model preferences to the API endpoint and your call will be routed to the correct model based on model availability.
# Glide
<div align="center">
<img src="docs/images/glide.png" width="400px" alt="Glide GH Header" />
</div>

[![LICENSE](https://img.shields.io/github/license/modelgateway/glide.svg?style=flat-square&color=%233f90c8)](https://github.com/modelgateway/glide/blob/main/LICENSE)

Glide is a cloud-native open source high-performant model gateway. All LLMOps you needed is packed in one lightweight service.

We take all problems and toll of managing and communicating with external providers out of your applications,
so you could focus solving your core problems.

Glide sits between your application and model providers that you use to seamlessly handle various LLMOps tasks like
model failover, caching, etc.

> [!Warning]
> Glide is under active development right now. Give us a star to support the project ✨
## Features

- **Unified REST API** across providers. Avoid vendor lock-ins and changes in your applications when you adopt new providers.
- **High availability** and **resiliency** working with external model providers. Automatic **fallbacks** on provider failures, rate limits, transient errors. Smart retries to reduce communication latency.
- Support **popular LLM providers**.
- **High performance**. Performance is our priority. We want to keep Glide "invisible" for your latency-wise, while providing rich functionality.
- **Production-ready observability** via OpenTelemetry, emit metrics on models health, allows whitebox monitoring.
- Straightforward and simple maintenance and configuration, API key rotation, etc.

## Supported Providers

|| Provider | Support Status
|---|---|---|
| <img src="docs/images/openai.png" width=18 />| OpenAI | 🏗️ Coming Soon |
| <img src="docs/images/azure.png" width=18>| Azure OpenAI | 🏗️ Coming Soon |
| <img src="docs/images/anthropic.png" width=18>| Anthropic | 🏗️ Coming Soon |
| <img src="docs/images/cohere.png" width=18>| Cohere | 🏗️ Coming Soon|
| <img src="docs/images/bard.png" width=18>| Google Gemini | 🏗️ Coming Soon | |
| <img src="docs/images/localai.png" width=18>| LocalAI | 🏗️ Coming Soon | |
### Large Language Models

<br />
| | Provider | Support Status |
|-----------------------------------------------------|---------------|-----------------|
| <img src="docs/images/openai.svg" width="18" /> | OpenAI | 🏗️ Coming Soon |
| <img src="docs/images/azure.svg" width="18" /> | Azure OpenAI | 🏗️ Coming Soon |
| <img src="docs/images/anthropic.svg" width="18" /> | Anthropic | 🏗️ Coming Soon |
| <img src="docs/images/cohere.png" width="18" /> | Cohere | 🏗️ Coming Soon |
| <img src="docs/images/bard.svg" width="18" /> | Google Gemini | 🏗️ Coming Soon |
| <img src="docs/images/localai.webp" width="18" /> | LocalAI | 🏗️ Coming Soon |


## Get Started

TBU

## Roadmap

- REST API to set primary and secondary models based on LLM API status
- Open an issue if there is a feature you'd like to see
### MVP (Coming soon)

- Unified LLM Chat REST API
- Support for most popular LLM providers
- Seamless model fallbacking
- The Main Load Balancing: Priority, Round Robin, Weighted Round Robin, Latency

### Future

- Exact & Semantic Caching
- Cost Management & Budgeting
- and many more!

Open [an issue](https://github.com/modelgateway/glide/issues) or start [a discussion](https://github.com/modelgateway/glide/discussions)
if there is a feature or an enhancement you'd like to see in Glide.

## Community

- Join Discord for real-time discussions

## Contribute

- Maintainers

- [Roman Hlushko](https://github.com/roma-glushko), Software Engineer, Distributed Systems & MLOps
- [Max Krueger](https://github.com/mkrueger12), Data Engineer, Data Scientist

Thanks everyone for already put their effort to make Glide better and more feature-rich:

<a href="https://github.com/modelgateway/glide/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=modelgateway/glide" />
</a>

8 changes: 8 additions & 0 deletions docs/images/anthropic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/azure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions docs/images/bard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cohere.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/glide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/localai.webp
Binary file not shown.
1 change: 1 addition & 0 deletions docs/images/openai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ go 1.21.5
require (
github.com/cloudwego/hertz v0.7.3
github.com/joho/godotenv v1.5.1
github.com/hertz-contrib/logger/zap v1.1.0
github.com/spf13/cobra v1.8.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/henrylee2cn/ameda v1.4.10 h1:JdvI2Ekq7tapdPsuhrc4CaFiqw6QXFvZIULWJgQy
github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4=
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 h1:yE9ULgp02BhYIrO6sdV/FPe0xQM6fNHkVQW2IAymfM0=
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ=
github.com/hertz-contrib/logger/zap v1.1.0 h1:4efINiIDJrXEtAFeEdDJvc3Hye0VFxp+0X4BwaZgxNs=
github.com/hertz-contrib/logger/zap v1.1.0/go.mod h1:D/rJJgsYn+SGaHVfVqWS3vHTbbc7ODAlJO+6smWgTeE=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
Expand Down Expand Up @@ -83,6 +85,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
Expand Down
21 changes: 16 additions & 5 deletions pkg/api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@ import (
"fmt"
"time"

"glide/pkg/pools"
"glide/pkg/telemetry"

"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/utils"
"github.com/cloudwego/hertz/pkg/protocol/consts"
)

type Server struct {
server *server.Hertz
telemetry *telemetry.Telemetry
router *pools.Router
server *server.Hertz
}

func NewServer(config *ServerConfig) (*Server, error) {
func NewServer(config *ServerConfig, tel *telemetry.Telemetry, router *pools.Router) (*Server, error) {
srv := config.ToServer()

return &Server{
server: config.ToServer(),
telemetry: tel,
router: router,
server: srv,
}, nil
}

Expand All @@ -32,10 +41,12 @@ func (srv *Server) Run() error {
func (srv *Server) Shutdown(_ context.Context) error {
exitWaitTime := srv.server.GetOptions().ExitWaitTimeout

println(fmt.Sprintf("Begin graceful shutdown, wait at most %d seconds...", exitWaitTime/time.Second))
srv.telemetry.Logger.Info(
fmt.Sprintf("Begin graceful shutdown, wait at most %d seconds...", exitWaitTime/time.Second),
)

ctx, cancel := context.WithTimeout(context.Background(), exitWaitTime)
defer cancel()

return srv.server.Shutdown(ctx)
return srv.server.Shutdown(ctx) //nolint:contextcheck
}
10 changes: 7 additions & 3 deletions pkg/api/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"sync"

"glide/pkg/pools"
"glide/pkg/telemetry"

"glide/pkg/api/http"
)

Expand All @@ -12,13 +15,14 @@ type ServerManager struct {
shutdownWG *sync.WaitGroup
}

func NewServerManager(httpConfig *http.ServerConfig) (*ServerManager, error) {
httpServer, err := http.NewServer(httpConfig)
// TODO: init other servers like gRPC in future
func NewServerManager(httpConfig *http.ServerConfig, tel *telemetry.Telemetry, router *pools.Router) (*ServerManager, error) {
httpServer, err := http.NewServer(httpConfig, tel, router)
if err != nil {
return nil, err
}

// TODO: init other servers like gRPC in future

return &ServerManager{
httpServer: httpServer,
shutdownWG: &sync.WaitGroup{},
Expand Down
58 changes: 58 additions & 0 deletions pkg/buildAPIRequest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// this file contains the BuildAPIRequest function which takes in the provider name, params map, and mode and returns the providerConfig map and error
// The providerConfig map can be used to build the API request to the provider
package pkg

import (
"errors"
"fmt"

"glide/pkg/providers"

Check failure on line 9 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

"glide/pkg/providers" imported and not used
"glide/pkg/providers/openai"

"github.com/go-playground/validator/v10"

Check failure on line 12 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

no required module provides package github.com/go-playground/validator/v10; to add it:

Check failure on line 12 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

could not import github.com/go-playground/validator/v10 (invalid package name: "")

Check failure on line 12 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Tests

no required module provides package github.com/go-playground/validator/v10; to add it:

Check failure on line 12 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Lint

no required module provides package github.com/go-playground/validator/v10; to add it:

Check failure on line 12 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Build

no required module provides package github.com/go-playground/validator/v10; to add it:
)

type ProviderConfigs = pkg.ProviderConfigs

Check failure on line 15 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

undefined: pkg

// Initialize configList

var configList = map[string]interface{}{
"openai": openai.OpenAIConfig,

Check failure on line 20 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

undefined: openai.OpenAIConfig
}

// Create a new validator instance
var validate *validator.Validate = validator.New()

Check failure on line 24 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

undefined: validator

Check failure on line 24 in pkg/buildAPIRequest.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

undefined: validator

func BuildAPIRequest(provider string, params map[string]string, mode string) (interface{}, error) {
// provider is the name of the provider, e.g. "openai", params is the map of parameters from the client,
// mode is the mode of the provider, e.g. "chat", configList is the list of provider configurations
var providerConfig map[string]interface{}

if config, ok := configList[provider].(ProviderConfigs); ok {
if modeConfig, ok := config[mode].(map[string]interface{}); ok {
providerConfig = modeConfig
}
}

// If the provider is not supported, return an error
if providerConfig == nil {
return nil, errors.New("unsupported provider")
}

// Build the providerConfig map by iterating over the keys in the providerConfig map and checking if the key exists in the params map

for key := range providerConfig {
if value, exists := params[key]; exists {
providerConfig[key] = value
}
}

// Validate the providerConfig map using the validator package
err := validate.Struct(providerConfig)
if err != nil {
// Handle validation error
return nil, fmt.Errorf("validation error: %v", err)
}
// If everything is fine, return the providerConfig and nil error
return providerConfig, nil
}
Loading

0 comments on commit 5a858a6

Please sign in to comment.