Skip to content

Commit 9dec7bc

Browse files
authored
Merge pull request #22 from Gyarbij/dev
1.0.5-rc
2 parents 48a0d35 + 0e798a1 commit 9dec7bc

File tree

11 files changed

+436
-291
lines changed

11 files changed

+436
-291
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,3 @@ updates:
1313
directory: "/" # Location of package manifests
1414
schedule:
1515
interval: "weekly"
16-
- package-ecosystem: "cargo" # See documentation for possible values
17-
directory: "/" # Location of package manifests
18-
schedule:
19-
interval: "weekly"

.github/workflows/compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
azure-oai-proxy:
3+
# env_file: .env
4+
image: 'gyarbij/azure-oai-proxy:latest'
5+
# container_name: azure-oai-proxy
6+
# Alternatively, use GitHub Container Registry:
7+
# image: 'ghcr.io/gyarbij/azure-oai-proxy:latest'
8+
restart: always
9+
environment:
10+
- AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
11+
# - AZURE_OPENAI_PROXY_ADDRESS=0.0.0.0:11437
12+
# - AZURE_OPENAI_PROXY_MODE=azure
13+
# - AZURE_OPENAI_APIVERSION=2024-06-01
14+
# - AZURE_OPENAI_MODEL_MAPPER=gpt-3.5-turbo=gpt-35-turbo,gpt-4=gpt-4-turbo
15+
# - 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
16+
# - AZURE_OPENAI_KEY_MISTRAL-LARGE-2407=your-api-key-1
17+
# - AZURE_OPENAI_KEY_LLAMA-3.1-8B=your-api-key-2
18+
# - AZURE_OPENAI_KEY_LLAMA-3.1-70B=your-api-key-3
19+
ports:
20+
- '11437:11437'
21+
# Uncomment the following line to use an .env file:

.gitignore

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,32 @@
1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
1616

17-
.idea
17+
.idea
18+
19+
# General
20+
.DS_Store
21+
.AppleDouble
22+
.LSOverride
23+
24+
# Icon must end with two \r
25+
Icon
26+
27+
28+
# Thumbnails
29+
._*
30+
31+
# Files that might appear in the root of a volume
32+
.DocumentRevisions-V100
33+
.fseventsd
34+
.Spotlight-V100
35+
.TemporaryItems
36+
.Trashes
37+
.VolumeIcon.icns
38+
.com.apple.timemachine.donotpresent
39+
40+
# Directories potentially created on remote AFP share
41+
.AppleDB
42+
.AppleDesktop
43+
Network Trash Folder
44+
Temporary Items
45+
.apdisk

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM golang:1.22.5 AS builder
22
WORKDIR /build
33
COPY . .
4+
RUN go get github.com/joho/godotenv
45
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o azure-oai-proxy .
56

67
FROM gcr.io/distroless/base-debian12

README.md

Lines changed: 112 additions & 96 deletions
Large diffs are not rendered by default.

example.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AZURE_OPENAI_APIVERSION=2024-06-01
2+
AZURE_OPENAI_ENDPOINT=https://your-azure-openai-resource.openai.azure.com/
3+
AZURE_OPENAI_API_KEY=your-azure-openai-api-key
4+
AZURE_OPENAI_MODEL_MAPPER=gpt-3.5-turbo=gpt-35-turbo,gpt-4=gpt-4-0613
5+
AZURE_AI_STUDIO_DEPLOYMENTS=mistral-large=Mistral-large2:swedencentral,llama-3=Meta-Llama-31-405B-Instruct:northcentralus
6+
AZURE_OPENAI_PROXY_ADDRESS=0.0.0.0:11437
7+
AZURE_OPENAI_PROXY_MODE=azure

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.22.4
44

55
require (
66
github.com/gin-gonic/gin v1.10.0
7+
github.com/joho/godotenv v1.5.1
78
github.com/tidwall/gjson v1.17.1
89
)
910

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
2828
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
2929
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3030
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
31+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
32+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
3133
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
3234
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
3335
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=

main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"log"
88
"net/http"
99
"os"
10+
"strings"
1011

1112
"github.com/gin-gonic/gin"
1213
"github.com/gyarbij/azure-oai-proxy/pkg/azure"
1314
"github.com/gyarbij/azure-oai-proxy/pkg/openai"
15+
"github.com/joho/godotenv"
1416
)
1517

1618
var (
@@ -49,6 +51,11 @@ type Deprecation struct {
4951
}
5052

5153
func init() {
54+
// Load .env file if it exists
55+
if err := godotenv.Load(); err != nil {
56+
log.Println("No .env file found")
57+
}
58+
5259
gin.SetMode(gin.ReleaseMode)
5360
if v := os.Getenv("AZURE_OPENAI_PROXY_ADDRESS"); v != "" {
5461
Address = v
@@ -58,6 +65,16 @@ func init() {
5865
}
5966
log.Printf("loading azure openai proxy address: %s", Address)
6067
log.Printf("loading azure openai proxy mode: %s", ProxyMode)
68+
69+
// Load Azure OpenAI Model Mapper
70+
if v := os.Getenv("AZURE_OPENAI_MODEL_MAPPER"); v != "" {
71+
for _, pair := range strings.Split(v, ",") {
72+
info := strings.Split(pair, "=")
73+
if len(info) == 2 {
74+
azure.AzureOpenAIModelMapper[info[0]] = info[1]
75+
}
76+
}
77+
}
6178
}
6279

6380
func main() {
@@ -109,6 +126,22 @@ func handleGetModels(c *gin.Context) {
109126
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch deployed models"})
110127
return
111128
}
129+
130+
// Add serverless deployments to the models list
131+
for deploymentName := range azure.ServerlessDeploymentInfo {
132+
models = append(models, Model{
133+
ID: deploymentName,
134+
Object: "model",
135+
Capabilities: Capabilities{
136+
Completion: true,
137+
ChatCompletion: true,
138+
Inference: true,
139+
},
140+
LifecycleStatus: "active",
141+
Status: "ready",
142+
})
143+
}
144+
112145
result := ModelList{
113146
Object: "list",
114147
Data: models,

0 commit comments

Comments
 (0)