Skip to content

Commit

Permalink
Merge pull request #22 from Gyarbij/dev
Browse files Browse the repository at this point in the history
1.0.5-rc
  • Loading branch information
Gyarbij authored Jul 25, 2024
2 parents 48a0d35 + 0e798a1 commit 9dec7bc
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 291 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
21 changes: 21 additions & 0 deletions .github/workflows/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
azure-oai-proxy:
# env_file: .env
image: 'gyarbij/azure-oai-proxy:latest'
# container_name: azure-oai-proxy
# Alternatively, use GitHub Container Registry:
# image: 'ghcr.io/gyarbij/azure-oai-proxy:latest'
restart: always
environment:
- AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
# - AZURE_OPENAI_PROXY_ADDRESS=0.0.0.0:11437
# - AZURE_OPENAI_PROXY_MODE=azure
# - AZURE_OPENAI_APIVERSION=2024-06-01
# - AZURE_OPENAI_MODEL_MAPPER=gpt-3.5-turbo=gpt-35-turbo,gpt-4=gpt-4-turbo
# - AZURE_AI_STUDIO_DEPLOYMENTS=mistral-large-2407=Mistral-large2:swedencentral,llama-3.1-405B=Meta-Llama-3-1-405B-Instruct:northcentralus,llama-3.1-70B=Llama-31-70B:swedencentral
# - AZURE_OPENAI_KEY_MISTRAL-LARGE-2407=your-api-key-1
# - AZURE_OPENAI_KEY_LLAMA-3.1-8B=your-api-key-2
# - AZURE_OPENAI_KEY_LLAMA-3.1-70B=your-api-key-3
ports:
- '11437:11437'
# Uncomment the following line to use an .env file:
30 changes: 29 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,32 @@
# Dependency directories (remove the comment below to include it)
# vendor/

.idea
.idea

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.22.5 AS builder
WORKDIR /build
COPY . .
RUN go get github.com/joho/godotenv
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o azure-oai-proxy .

FROM gcr.io/distroless/base-debian12
Expand Down
208 changes: 112 additions & 96 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
AZURE_OPENAI_APIVERSION=2024-06-01
AZURE_OPENAI_ENDPOINT=https://your-azure-openai-resource.openai.azure.com/
AZURE_OPENAI_API_KEY=your-azure-openai-api-key
AZURE_OPENAI_MODEL_MAPPER=gpt-3.5-turbo=gpt-35-turbo,gpt-4=gpt-4-0613
AZURE_AI_STUDIO_DEPLOYMENTS=mistral-large=Mistral-large2:swedencentral,llama-3=Meta-Llama-31-405B-Instruct:northcentralus
AZURE_OPENAI_PROXY_ADDRESS=0.0.0.0:11437
AZURE_OPENAI_PROXY_MODE=azure
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.4

require (
github.com/gin-gonic/gin v1.10.0
github.com/joho/godotenv v1.5.1
github.com/tidwall/gjson v1.17.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
Expand Down
33 changes: 33 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"log"
"net/http"
"os"
"strings"

"github.com/gin-gonic/gin"
"github.com/gyarbij/azure-oai-proxy/pkg/azure"
"github.com/gyarbij/azure-oai-proxy/pkg/openai"
"github.com/joho/godotenv"
)

var (
Expand Down Expand Up @@ -49,6 +51,11 @@ type Deprecation struct {
}

func init() {
// Load .env file if it exists
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
}

gin.SetMode(gin.ReleaseMode)
if v := os.Getenv("AZURE_OPENAI_PROXY_ADDRESS"); v != "" {
Address = v
Expand All @@ -58,6 +65,16 @@ func init() {
}
log.Printf("loading azure openai proxy address: %s", Address)
log.Printf("loading azure openai proxy mode: %s", ProxyMode)

// Load Azure OpenAI Model Mapper
if v := os.Getenv("AZURE_OPENAI_MODEL_MAPPER"); v != "" {
for _, pair := range strings.Split(v, ",") {
info := strings.Split(pair, "=")
if len(info) == 2 {
azure.AzureOpenAIModelMapper[info[0]] = info[1]
}
}
}
}

func main() {
Expand Down Expand Up @@ -109,6 +126,22 @@ func handleGetModels(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch deployed models"})
return
}

// Add serverless deployments to the models list
for deploymentName := range azure.ServerlessDeploymentInfo {
models = append(models, Model{
ID: deploymentName,
Object: "model",
Capabilities: Capabilities{
Completion: true,
ChatCompletion: true,
Inference: true,
},
LifecycleStatus: "active",
Status: "ready",
})
}

result := ModelList{
Object: "list",
Data: models,
Expand Down
Loading

0 comments on commit 9dec7bc

Please sign in to comment.