mirror of
https://github.com/alibaba/higress.git
synced 2026-07-28 15:20:24 +08:00
Compare commits
8 Commits
v2.1.3
...
cr7258-pat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a289d914f | ||
|
|
675a8ce4a9 | ||
|
|
06c5ddd80b | ||
|
|
8ccc170500 | ||
|
|
ff308d5292 | ||
|
|
af8502b0b0 | ||
|
|
c683936b1c | ||
|
|
8b3f1aab1a |
108
.github/workflows/helm-docs.yaml
vendored
108
.github/workflows/helm-docs.yaml
vendored
@@ -6,11 +6,13 @@ on:
|
|||||||
- "*"
|
- "*"
|
||||||
paths:
|
paths:
|
||||||
- 'helm/**'
|
- 'helm/**'
|
||||||
|
- '!helm/higress/README.zh.md'
|
||||||
workflow_dispatch: ~
|
workflow_dispatch: ~
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
paths:
|
paths:
|
||||||
- 'helm/**'
|
- 'helm/**'
|
||||||
|
- '!helm/higress/README.zh.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
helm:
|
helm:
|
||||||
@@ -31,7 +33,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
GOBIN=$PWD GO111MODULE=on go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2
|
GOBIN=$PWD GO111MODULE=on go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2
|
||||||
./helm-docs -c ${GITHUB_WORKSPACE}/helm/higress -f ../core/values.yaml
|
./helm-docs -c ${GITHUB_WORKSPACE}/helm/higress -f ../core/values.yaml
|
||||||
DIFF=$(git diff ${GITHUB_WORKSPACE}/helm/higress/*md)
|
DIFF=$(git diff ${GITHUB_WORKSPACE}/helm/higress/README.md)
|
||||||
if [ ! -z "$DIFF" ]; then
|
if [ ! -z "$DIFF" ]; then
|
||||||
echo "Please use helm-docs in your clone, of your fork, of the project, and commit a updated README.md for the chart."
|
echo "Please use helm-docs in your clone, of your fork, of the project, and commit a updated README.md for the chart."
|
||||||
fi
|
fi
|
||||||
@@ -55,18 +57,19 @@ jobs:
|
|||||||
id: compare_readme
|
id: compare_readme
|
||||||
run: |
|
run: |
|
||||||
cd ./helm/higress
|
cd ./helm/higress
|
||||||
BASE_BRANCH=main
|
|
||||||
UPSTREAM_REPO=https://github.com/alibaba/higress.git
|
|
||||||
|
|
||||||
TEMP_DIR=$(mktemp -d)
|
BASE_BRANCH=${GITHUB_BASE_REF:-main}
|
||||||
git clone --depth 1 --branch $BASE_BRANCH $UPSTREAM_REPO $TEMP_DIR
|
git fetch origin $BASE_BRANCH
|
||||||
|
|
||||||
if diff -q "$TEMP_DIR/README.md" README.md > /dev/null; then
|
if git diff --quiet origin/$BASE_BRANCH -- README.md; then
|
||||||
echo "README.md has no changes in comparison to base branch. Skipping translation."
|
echo "README.md has no local changes compared to $BASE_BRANCH. Skipping translation."
|
||||||
echo "skip_translation=true" >> $GITHUB_ENV
|
echo "skip_translation=true" >> $GITHUB_ENV
|
||||||
else
|
else
|
||||||
echo "README.md has changed in comparison to base branch. Proceeding with translation."
|
echo "README.md has local changes compared to $BASE_BRANCH. Proceeding with translation."
|
||||||
echo "skip_translation=false" >> $GITHUB_ENV
|
echo "skip_translation=false" >> $GITHUB_ENV
|
||||||
|
echo "--------- diff ---------"
|
||||||
|
git diff origin/$BASE_BRANCH -- README.md
|
||||||
|
echo "------------------------"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Translate README.md to Chinese
|
- name: Translate README.md to Chinese
|
||||||
@@ -76,39 +79,74 @@ jobs:
|
|||||||
API_KEY: ${{ secrets.HIGRESS_OPENAI_API_KEY }}
|
API_KEY: ${{ secrets.HIGRESS_OPENAI_API_KEY }}
|
||||||
API_MODEL: ${{ secrets.HIGRESS_OPENAI_API_MODEL }}
|
API_MODEL: ${{ secrets.HIGRESS_OPENAI_API_MODEL }}
|
||||||
run: |
|
run: |
|
||||||
cd ./helm/higress
|
cat << 'EOF' > translate_readme.py
|
||||||
FILE_CONTENT=$(cat README.md)
|
import os
|
||||||
|
import json
|
||||||
|
import requests
|
||||||
|
|
||||||
PAYLOAD=$(jq -n \
|
API_URL = os.environ["API_URL"]
|
||||||
--arg model "$API_MODEL" \
|
API_KEY = os.environ["API_KEY"]
|
||||||
--arg content "$FILE_CONTENT" \
|
API_MODEL = os.environ["API_MODEL"]
|
||||||
'{
|
README_PATH = "./helm/higress/README.md"
|
||||||
model: $model,
|
OUTPUT_PATH = "./helm/higress/README.zh.md"
|
||||||
messages: [
|
|
||||||
{"role": "system", "content": "You are a translation assistant that translates English Markdown text to Chinese."},
|
|
||||||
{"role": "user", "content": $content}
|
|
||||||
],
|
|
||||||
temperature: 1.1,
|
|
||||||
stream: false
|
|
||||||
}')
|
|
||||||
|
|
||||||
RESPONSE=$(curl -s -X POST "$API_URL" \
|
def stream_translation(api_url, api_key, payload):
|
||||||
-H "Content-Type: application/json" \
|
headers = {
|
||||||
-H "Authorization: Bearer $API_KEY" \
|
"Content-Type": "application/json",
|
||||||
-d "$PAYLOAD")
|
"Authorization": f"Bearer {api_key}",
|
||||||
|
}
|
||||||
|
response = requests.post(api_url, headers=headers, json=payload, stream=True)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
echo "Response: $RESPONSE"
|
with open(OUTPUT_PATH, "w", encoding="utf-8") as out_file:
|
||||||
|
for line in response.iter_lines(decode_unicode=True):
|
||||||
|
if line.strip() == "" or not line.startswith("data: "):
|
||||||
|
continue
|
||||||
|
data = line[6:]
|
||||||
|
if data.strip() == "[DONE]":
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
chunk = json.loads(data)
|
||||||
|
content = chunk["choices"][0]["delta"].get("content", "")
|
||||||
|
if content:
|
||||||
|
out_file.write(content)
|
||||||
|
except Exception as e:
|
||||||
|
print("Error parsing chunk:", e)
|
||||||
|
|
||||||
echo "$RESPONSE" | jq -c -r '.choices[] | .message.content' > README.zh.new.md
|
def main():
|
||||||
|
if not os.path.exists(README_PATH):
|
||||||
|
print("README.md not found!")
|
||||||
|
return
|
||||||
|
|
||||||
if [ -f "README.zh.new.md" ]; then
|
with open(README_PATH, "r", encoding="utf-8") as f:
|
||||||
echo "Translation completed and saved to README.zh.new.md."
|
content = f.read()
|
||||||
else
|
|
||||||
echo "Translation failed or no content returned!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mv README.zh.new.md README.zh.md
|
payload = {
|
||||||
|
"model": API_MODEL,
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "You are a translation assistant that translates English Markdown text to Chinese. Preserve original Markdown formatting and line breaks."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": content
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"temperature": 0.3,
|
||||||
|
"stream": True
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Streaming translation started...")
|
||||||
|
stream_translation(API_URL, API_KEY, payload)
|
||||||
|
print(f"Translation completed and saved to {OUTPUT_PATH}.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
EOF
|
||||||
|
|
||||||
|
python3 translate_readme.py
|
||||||
|
rm -rf translate_readme.py
|
||||||
|
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
if: env.skip_translation == 'false'
|
if: env.skip_translation == 'false'
|
||||||
|
|||||||
29
.github/workflows/translate-test.yml
vendored
Normal file
29
.github/workflows/translate-test.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: 'Translate GitHub content into English'
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened, edited]
|
||||||
|
issue_comment:
|
||||||
|
types: [created, edited]
|
||||||
|
discussion:
|
||||||
|
types: [created, edited]
|
||||||
|
discussion_comment:
|
||||||
|
types: [created, edited]
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened, edited]
|
||||||
|
pull_request_review_comment:
|
||||||
|
types: [created, edited]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
translate:
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
discussions: write
|
||||||
|
pull-requests: write
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: lizheming/github-translate-action@main
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
APPEND_TRANSLATION: true
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
[](https://github.com/alibaba/higress/actions)
|
[](https://github.com/alibaba/higress/actions)
|
||||||
[](https://www.apache.org/licenses/LICENSE-2.0.html)
|
[](https://www.apache.org/licenses/LICENSE-2.0.html)
|
||||||
|
[](https://discord.gg/reymxYM5)
|
||||||
|
|
||||||
<a href="https://trendshift.io/repositories/10918" target="_blank"><img src="https://trendshift.io/api/badge/repositories/10918" alt="alibaba%2Fhigress | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a> <a href="https://www.producthunt.com/posts/higress?embed=true&utm_source=badge-featured&utm_medium=badge&utm_souce=badge-higress" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=951287&theme=light&t=1745492822283" alt="Higress - Global APIs as MCP powered by AI Gateway | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
<a href="https://trendshift.io/repositories/10918" target="_blank"><img src="https://trendshift.io/api/badge/repositories/10918" alt="alibaba%2Fhigress | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a> <a href="https://www.producthunt.com/posts/higress?embed=true&utm_source=badge-featured&utm_medium=badge&utm_souce=badge-higress" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=951287&theme=light&t=1745492822283" alt="Higress - Global APIs as MCP powered by AI Gateway | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
English | <a href="README_ZH.md">中文<a/> | <a href="README_JP.md">日本語<a/>
|
English | <a href="README_ZH.md">中文<a/> | <a href="README_JP.md">日本語<a/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## What is Higress?
|
## Test What is Higress?
|
||||||
|
|
||||||
Higress is a cloud-native API gateway based on Istio and Envoy, which can be extended with Wasm plugins written in Go/Rust/JS. It provides dozens of ready-to-use general-purpose plugins and an out-of-the-box console (try the [demo here](http://demo.higress.io/)).
|
Higress is a cloud-native API gateway based on Istio and Envoy, which can be extended with Wasm plugins written in Go/Rust/JS. It provides dozens of ready-to-use general-purpose plugins and an out-of-the-box console (try the [demo here](http://demo.higress.io/)).
|
||||||
|
|
||||||
@@ -140,7 +141,10 @@ For other installation methods such as Helm deployment under K8s, please refer t
|
|||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
[Slack](https://w1689142780-euk177225.slack.com/archives/C05GEL4TGTG): to get invited go [here](https://communityinviter.com/apps/w1689142780-euk177225/higress).
|
Join our Discord community! This is where you can connect with developers and other enthusiastic users of Higress.
|
||||||
|
|
||||||
|
[](https://discord.gg/reymxYM5)
|
||||||
|
|
||||||
|
|
||||||
### Thanks
|
### Thanks
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
ARG BUILDER=higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/wasm-go-builder:go1.20.14-tinygo0.29.0-oras1.0.0
|
ARG BUILDER=higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/wasm-go-builder:go1.20.14-tinygo0.29.0-oras1.0.0
|
||||||
FROM $BUILDER as builder
|
FROM $BUILDER AS builder
|
||||||
|
|
||||||
|
|
||||||
ARG GOPROXY
|
ARG GOPROXY
|
||||||
@@ -26,6 +26,6 @@ RUN \
|
|||||||
tinygo build -o /main.wasm -scheduler=none -gc=custom -tags="custommalloc nottinygc_finalizer $EXTRA_TAGS" -target=wasi ./ ; \
|
tinygo build -o /main.wasm -scheduler=none -gc=custom -tags="custommalloc nottinygc_finalizer $EXTRA_TAGS" -target=wasi ./ ; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FROM scratch as output
|
FROM scratch AS output
|
||||||
|
|
||||||
COPY --from=builder /main.wasm plugin.wasm
|
COPY --from=builder /main.wasm plugin.wasm
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ require (
|
|||||||
github.com/higress-group/proxy-wasm-go-sdk v1.0.0
|
github.com/higress-group/proxy-wasm-go-sdk v1.0.0
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/tidwall/gjson v1.17.3
|
github.com/tidwall/gjson v1.17.3
|
||||||
|
github.com/wasilibs/go-re2 v1.6.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/tetratelabs/wazero v1.7.2 // indirect
|
github.com/tetratelabs/wazero v1.7.2 // indirect
|
||||||
github.com/wasilibs/go-re2 v1.6.0 // indirect
|
|
||||||
golang.org/x/sys v0.21.0 // indirect
|
golang.org/x/sys v0.21.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ github.com/higress-group/nottinygc v0.0.0-20231101025119-e93c4c2f8520 h1:IHDghbG
|
|||||||
github.com/higress-group/nottinygc v0.0.0-20231101025119-e93c4c2f8520/go.mod h1:Nz8ORLaFiLWotg6GeKlJMhv8cci8mM43uEnLA5t8iew=
|
github.com/higress-group/nottinygc v0.0.0-20231101025119-e93c4c2f8520/go.mod h1:Nz8ORLaFiLWotg6GeKlJMhv8cci8mM43uEnLA5t8iew=
|
||||||
github.com/higress-group/proxy-wasm-go-sdk v1.0.0 h1:BZRNf4R7jr9hwRivg/E29nkVaKEak5MWjBDhWjuHijU=
|
github.com/higress-group/proxy-wasm-go-sdk v1.0.0 h1:BZRNf4R7jr9hwRivg/E29nkVaKEak5MWjBDhWjuHijU=
|
||||||
github.com/higress-group/proxy-wasm-go-sdk v1.0.0/go.mod h1:iiSyFbo+rAtbtGt/bsefv8GU57h9CCLYGJA74/tF5/0=
|
github.com/higress-group/proxy-wasm-go-sdk v1.0.0/go.mod h1:iiSyFbo+rAtbtGt/bsefv8GU57h9CCLYGJA74/tF5/0=
|
||||||
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
|
|
||||||
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
|
||||||
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a h1:tdPcGgyiH0K+SbsJBBm2oPyEIOTAvLBwD9TuUwVtZho=
|
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a h1:tdPcGgyiH0K+SbsJBBm2oPyEIOTAvLBwD9TuUwVtZho=
|
||||||
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
@@ -29,6 +27,7 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
|||||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||||
github.com/wasilibs/go-re2 v1.6.0 h1:CLlhDebt38wtl/zz4ww+hkXBMcxjrKFvTDXzFW2VOz8=
|
github.com/wasilibs/go-re2 v1.6.0 h1:CLlhDebt38wtl/zz4ww+hkXBMcxjrKFvTDXzFW2VOz8=
|
||||||
github.com/wasilibs/go-re2 v1.6.0/go.mod h1:prArCyErsypRBI/jFAFJEbzyHzjABKqkzlidF0SNA04=
|
github.com/wasilibs/go-re2 v1.6.0/go.mod h1:prArCyErsypRBI/jFAFJEbzyHzjABKqkzlidF0SNA04=
|
||||||
|
github.com/wasilibs/nottinygc v0.4.0 h1:h1TJMihMC4neN6Zq+WKpLxgd9xCFMw7O9ETLwY2exJQ=
|
||||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -32,7 +33,10 @@ const (
|
|||||||
bedrockChatCompletionPath = "/model/%s/converse"
|
bedrockChatCompletionPath = "/model/%s/converse"
|
||||||
// converseStream路径 /model/{modelId}/converse-stream
|
// converseStream路径 /model/{modelId}/converse-stream
|
||||||
bedrockStreamChatCompletionPath = "/model/%s/converse-stream"
|
bedrockStreamChatCompletionPath = "/model/%s/converse-stream"
|
||||||
bedrockSignedHeaders = "host;x-amz-date"
|
// invoke_model 路径 /model/{modelId}/invoke
|
||||||
|
bedrockInvokeModelPath = "/model/%s/invoke"
|
||||||
|
bedrockSignedHeaders = "host;x-amz-date"
|
||||||
|
requestIdHeader = "X-Amzn-Requestid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bedrockProviderInitializer struct {
|
type bedrockProviderInitializer struct {
|
||||||
@@ -50,7 +54,8 @@ func (b *bedrockProviderInitializer) ValidateConfig(config *ProviderConfig) erro
|
|||||||
|
|
||||||
func (b *bedrockProviderInitializer) DefaultCapabilities() map[string]string {
|
func (b *bedrockProviderInitializer) DefaultCapabilities() map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
string(ApiNameChatCompletion): bedrockChatCompletionPath,
|
string(ApiNameChatCompletion): bedrockChatCompletionPath,
|
||||||
|
string(ApiNameImageGeneration): bedrockInvokeModelPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +104,7 @@ func (b *bedrockProvider) convertEventFromBedrockToOpenAI(ctx wrapper.HttpContex
|
|||||||
chatChoice.FinishReason = stopReasonBedrock2OpenAI(*bedrockEvent.StopReason)
|
chatChoice.FinishReason = stopReasonBedrock2OpenAI(*bedrockEvent.StopReason)
|
||||||
}
|
}
|
||||||
choices = append(choices, chatChoice)
|
choices = append(choices, chatChoice)
|
||||||
requestId := ctx.GetStringContext("X-Amzn-Requestid", "")
|
requestId := ctx.GetStringContext(requestIdHeader, "")
|
||||||
openAIFormattedChunk := &chatCompletionResponse{
|
openAIFormattedChunk := &chatCompletionResponse{
|
||||||
Id: requestId,
|
Id: requestId,
|
||||||
Created: time.Now().UnixMilli() / 1000,
|
Created: time.Now().UnixMilli() / 1000,
|
||||||
@@ -152,6 +157,74 @@ type toolUseBlockDelta struct {
|
|||||||
Input string `json:"input"`
|
Input string `json:"input"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationResponse struct {
|
||||||
|
Images []string `json:"images"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationTextToImageParams struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
NegativeText string `json:"negativeText,omitempty"`
|
||||||
|
ConditionImage string `json:"conditionImage,omitempty"`
|
||||||
|
ControlMode string `json:"controlMode,omitempty"`
|
||||||
|
ControlStrength float32 `json:"controlLength,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationConfig struct {
|
||||||
|
Width int `json:"width"`
|
||||||
|
Height int `json:"height"`
|
||||||
|
Quality string `json:"quality,omitempty"`
|
||||||
|
CfgScale float32 `json:"cfgScale,omitempty"`
|
||||||
|
Seed int `json:"seed,omitempty"`
|
||||||
|
NumberOfImages int `json:"numberOfImages"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationColorGuidedGenerationParams struct {
|
||||||
|
Colors []string `json:"colors"`
|
||||||
|
ReferenceImage string `json:"referenceImage"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
NegativeText string `json:"negativeText,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationImageVariationParams struct {
|
||||||
|
Images []string `json:"images"`
|
||||||
|
SimilarityStrength float32 `json:"similarityStrength"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
NegativeText string `json:"negativeText,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationInPaintingParams struct {
|
||||||
|
Image string `json:"image"`
|
||||||
|
MaskPrompt string `json:"maskPrompt"`
|
||||||
|
MaskImage string `json:"maskImage"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
NegativeText string `json:"negativeText,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationOutPaintingParams struct {
|
||||||
|
Image string `json:"image"`
|
||||||
|
MaskPrompt string `json:"maskPrompt"`
|
||||||
|
MaskImage string `json:"maskImage"`
|
||||||
|
OutPaintingMode string `json:"outPaintingMode"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
NegativeText string `json:"negativeText,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationBackgroundRemovalParams struct {
|
||||||
|
Image string `json:"image"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type bedrockImageGenerationRequest struct {
|
||||||
|
TaskType string `json:"taskType"`
|
||||||
|
ImageGenerationConfig *bedrockImageGenerationConfig `json:"imageGenerationConfig"`
|
||||||
|
TextToImageParams *bedrockImageGenerationTextToImageParams `json:"textToImageParams,omitempty"`
|
||||||
|
ColorGuidedGenerationParams *bedrockImageGenerationColorGuidedGenerationParams `json:"colorGuidedGenerationParams,omitempty"`
|
||||||
|
ImageVariationParams *bedrockImageGenerationImageVariationParams `json:"imageVariationParams,omitempty"`
|
||||||
|
InPaintingParams *bedrockImageGenerationInPaintingParams `json:"inPaintingParams,omitempty"`
|
||||||
|
OutPaintingParams *bedrockImageGenerationOutPaintingParams `json:"outPaintingParams,omitempty"`
|
||||||
|
BackgroundRemovalParams *bedrockImageGenerationBackgroundRemovalParams `json:"backgroundRemovalParams,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
func extractAmazonEventStreamEvents(ctx wrapper.HttpContext, chunk []byte) []ConverseStreamEvent {
|
func extractAmazonEventStreamEvents(ctx wrapper.HttpContext, chunk []byte) []ConverseStreamEvent {
|
||||||
body := chunk
|
body := chunk
|
||||||
if bufferedStreamingBody, has := ctx.GetContext(ctxKeyStreamingBody).([]byte); has {
|
if bufferedStreamingBody, has := ctx.GetContext(ctxKeyStreamingBody).([]byte); has {
|
||||||
@@ -489,7 +562,7 @@ func validateCRC(r io.Reader, expect uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *bedrockProvider) TransformResponseHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header) {
|
func (b *bedrockProvider) TransformResponseHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header) {
|
||||||
ctx.SetContext("X-Amzn-Requestid", headers.Get("X-Amzn-Requestid"))
|
ctx.SetContext(requestIdHeader, headers.Get(requestIdHeader))
|
||||||
if headers.Get("Content-Type") == "application/vnd.amazon.eventstream" {
|
if headers.Get("Content-Type") == "application/vnd.amazon.eventstream" {
|
||||||
headers.Set("Content-Type", "text/event-stream; charset=utf-8")
|
headers.Set("Content-Type", "text/event-stream; charset=utf-8")
|
||||||
}
|
}
|
||||||
@@ -537,18 +610,83 @@ func (b *bedrockProvider) TransformRequestBodyHeaders(ctx wrapper.HttpContext, a
|
|||||||
switch apiName {
|
switch apiName {
|
||||||
case ApiNameChatCompletion:
|
case ApiNameChatCompletion:
|
||||||
return b.onChatCompletionRequestBody(ctx, body, headers)
|
return b.onChatCompletionRequestBody(ctx, body, headers)
|
||||||
|
case ApiNameImageGeneration:
|
||||||
|
return b.onImageGenerationRequestBody(ctx, body, headers)
|
||||||
default:
|
default:
|
||||||
return b.config.defaultTransformRequestBody(ctx, apiName, body)
|
return b.config.defaultTransformRequestBody(ctx, apiName, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bedrockProvider) TransformResponseBody(ctx wrapper.HttpContext, apiName ApiName, body []byte) ([]byte, error) {
|
func (b *bedrockProvider) TransformResponseBody(ctx wrapper.HttpContext, apiName ApiName, body []byte) ([]byte, error) {
|
||||||
if apiName == ApiNameChatCompletion {
|
switch apiName {
|
||||||
|
case ApiNameChatCompletion:
|
||||||
return b.onChatCompletionResponseBody(ctx, body)
|
return b.onChatCompletionResponseBody(ctx, body)
|
||||||
|
case ApiNameImageGeneration:
|
||||||
|
return b.onImageGenerationResponseBody(ctx, body)
|
||||||
}
|
}
|
||||||
return nil, errUnsupportedApiName
|
return nil, errUnsupportedApiName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *bedrockProvider) onImageGenerationResponseBody(ctx wrapper.HttpContext, body []byte) ([]byte, error) {
|
||||||
|
bedrockResponse := &bedrockImageGenerationResponse{}
|
||||||
|
if err := json.Unmarshal(body, bedrockResponse); err != nil {
|
||||||
|
log.Errorf("unable to unmarshal bedrock image gerneration response: %v", err)
|
||||||
|
return nil, fmt.Errorf("unable to unmarshal bedrock image generation response: %v", err)
|
||||||
|
}
|
||||||
|
response := b.buildBedrockImageGenerationResponse(ctx, bedrockResponse)
|
||||||
|
return json.Marshal(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *bedrockProvider) onImageGenerationRequestBody(ctx wrapper.HttpContext, body []byte, headers http.Header) ([]byte, error) {
|
||||||
|
request := &imageGenerationRequest{}
|
||||||
|
err := b.config.parseRequestAndMapModel(ctx, request, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
headers.Set("Accept", "*/*")
|
||||||
|
util.OverwriteRequestPathHeader(headers, fmt.Sprintf(bedrockInvokeModelPath, request.Model))
|
||||||
|
return b.buildBedrockImageGenerationRequest(request, headers)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *bedrockProvider) buildBedrockImageGenerationRequest(origRequest *imageGenerationRequest, headers http.Header) ([]byte, error) {
|
||||||
|
width, height := 1024, 1024
|
||||||
|
pairs := strings.Split(origRequest.Size, "x")
|
||||||
|
if len(pairs) == 2 {
|
||||||
|
width, _ = strconv.Atoi(pairs[0])
|
||||||
|
height, _ = strconv.Atoi(pairs[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &bedrockImageGenerationRequest{
|
||||||
|
TaskType: "TEXT_IMAGE",
|
||||||
|
TextToImageParams: &bedrockImageGenerationTextToImageParams{
|
||||||
|
Text: origRequest.Prompt,
|
||||||
|
},
|
||||||
|
ImageGenerationConfig: &bedrockImageGenerationConfig{
|
||||||
|
NumberOfImages: origRequest.N,
|
||||||
|
Width: width,
|
||||||
|
Height: height,
|
||||||
|
Quality: origRequest.Quality,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
util.OverwriteRequestPathHeader(headers, fmt.Sprintf(bedrockInvokeModelPath, origRequest.Model))
|
||||||
|
requestBytes, err := json.Marshal(request)
|
||||||
|
b.setAuthHeaders(requestBytes, headers)
|
||||||
|
return requestBytes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *bedrockProvider) buildBedrockImageGenerationResponse(ctx wrapper.HttpContext, bedrockResponse *bedrockImageGenerationResponse) *imageGenerationResponse {
|
||||||
|
data := make([]imageGenerationData, len(bedrockResponse.Images))
|
||||||
|
for i, image := range bedrockResponse.Images {
|
||||||
|
data[i] = imageGenerationData{
|
||||||
|
B64: image,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &imageGenerationResponse{
|
||||||
|
Created: time.Now().UnixMilli() / 1000,
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *bedrockProvider) onChatCompletionResponseBody(ctx wrapper.HttpContext, body []byte) ([]byte, error) {
|
func (b *bedrockProvider) onChatCompletionResponseBody(ctx wrapper.HttpContext, body []byte) ([]byte, error) {
|
||||||
bedrockResponse := &bedrockConverseResponse{}
|
bedrockResponse := &bedrockConverseResponse{}
|
||||||
if err := json.Unmarshal(body, bedrockResponse); err != nil {
|
if err := json.Unmarshal(body, bedrockResponse); err != nil {
|
||||||
@@ -613,7 +751,7 @@ func (b *bedrockProvider) buildChatCompletionResponse(ctx wrapper.HttpContext, b
|
|||||||
FinishReason: stopReasonBedrock2OpenAI(bedrockResponse.StopReason),
|
FinishReason: stopReasonBedrock2OpenAI(bedrockResponse.StopReason),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
requestId := ctx.GetStringContext("X-Amzn-Requestid", "")
|
requestId := ctx.GetStringContext(requestIdHeader, "")
|
||||||
return &chatCompletionResponse{
|
return &chatCompletionResponse{
|
||||||
Id: requestId,
|
Id: requestId,
|
||||||
Created: time.Now().UnixMilli() / 1000,
|
Created: time.Now().UnixMilli() / 1000,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ func (g *geminiProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiNa
|
|||||||
func (g *geminiProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header) {
|
func (g *geminiProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header) {
|
||||||
util.OverwriteRequestHostHeader(headers, geminiDomain)
|
util.OverwriteRequestHostHeader(headers, geminiDomain)
|
||||||
headers.Set(geminiApiKeyHeader, g.config.GetApiTokenInUse(ctx))
|
headers.Set(geminiApiKeyHeader, g.config.GetApiTokenInUse(ctx))
|
||||||
|
util.OverwriteRequestAuthorizationHeader(headers, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *geminiProvider) OnRequestBody(ctx wrapper.HttpContext, apiName ApiName, body []byte) (types.Action, error) {
|
func (g *geminiProvider) OnRequestBody(ctx wrapper.HttpContext, apiName ApiName, body []byte) (types.Action, error) {
|
||||||
|
|||||||
@@ -356,10 +356,39 @@ func (e *StreamEvent) ToHttpString() string {
|
|||||||
|
|
||||||
// https://platform.openai.com/docs/guides/images
|
// https://platform.openai.com/docs/guides/images
|
||||||
type imageGenerationRequest struct {
|
type imageGenerationRequest struct {
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Prompt string `json:"prompt"`
|
Prompt string `json:"prompt"`
|
||||||
N int `json:"n,omitempty"`
|
Background string `json:"background,omitempty"`
|
||||||
Size string `json:"size,omitempty"`
|
Moderation string `json:"moderation,omitempty"`
|
||||||
|
OutputCompression int `json:"output_compression,omitempty"`
|
||||||
|
OutputFormat string `json:"output_format,omitempty"`
|
||||||
|
Quality string `json:"quality,omitempty"`
|
||||||
|
ResponseFormat string `json:"response_format,omitempty"`
|
||||||
|
Style string `json:"style,omitempty"`
|
||||||
|
N int `json:"n,omitempty"`
|
||||||
|
Size string `json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type imageGenerationData struct {
|
||||||
|
URL string `json:"url,omitempty"`
|
||||||
|
B64 string `json:"b64_json,omitempty"`
|
||||||
|
RevisedPrompt string `json:"revised_prompt,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type imageGenerationUsage struct {
|
||||||
|
TotalTokens int `json:"total_tokens"`
|
||||||
|
InputTokens int `json:"input_tokens"`
|
||||||
|
OutputTokens int `json:"output_tokens"`
|
||||||
|
InputTokensDetails struct {
|
||||||
|
TextTokens int `json:"text_tokens"`
|
||||||
|
ImageTokens int `json:"image_tokens"`
|
||||||
|
} `json:"input_tokens_details"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type imageGenerationResponse struct {
|
||||||
|
Created int64 `json:"created"`
|
||||||
|
Data []imageGenerationData `json:"data"`
|
||||||
|
Usage *imageGenerationUsage `json:"usage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://platform.openai.com/docs/guides/speech-to-text
|
// https://platform.openai.com/docs/guides/speech-to-text
|
||||||
|
|||||||
@@ -534,6 +534,11 @@ func (c *ProviderConfig) parseRequestAndMapModel(ctx wrapper.HttpContext, reques
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.setRequestModel(ctx, req)
|
return c.setRequestModel(ctx, req)
|
||||||
|
case *imageGenerationRequest:
|
||||||
|
if err := decodeImageGenerationRequest(body, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.setRequestModel(ctx, req)
|
||||||
default:
|
default:
|
||||||
return errors.New("unsupported request type")
|
return errors.New("unsupported request type")
|
||||||
}
|
}
|
||||||
@@ -547,6 +552,8 @@ func (c *ProviderConfig) setRequestModel(ctx wrapper.HttpContext, request interf
|
|||||||
model = &req.Model
|
model = &req.Model
|
||||||
case *embeddingsRequest:
|
case *embeddingsRequest:
|
||||||
model = &req.Model
|
model = &req.Model
|
||||||
|
case *imageGenerationRequest:
|
||||||
|
model = &req.Model
|
||||||
default:
|
default:
|
||||||
return errors.New("unsupported request type")
|
return errors.New("unsupported request type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ func decodeEmbeddingsRequest(body []byte, request *embeddingsRequest) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeImageGenerationRequest(body []byte, request *imageGenerationRequest) error {
|
||||||
|
if err := json.Unmarshal(body, request); err != nil {
|
||||||
|
return fmt.Errorf("unable to unmarshal request: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func replaceJsonRequestBody(request interface{}) error {
|
func replaceJsonRequestBody(request interface{}) error {
|
||||||
body, err := json.Marshal(request)
|
body, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ type ToolArgs struct {
|
|||||||
Required bool `json:"required,omitempty"`
|
Required bool `json:"required,omitempty"`
|
||||||
Default interface{} `json:"default,omitempty"`
|
Default interface{} `json:"default,omitempty"`
|
||||||
Enum []interface{} `json:"enum,omitempty"`
|
Enum []interface{} `json:"enum,omitempty"`
|
||||||
Items []interface{} `json:"items,omitempty"`
|
Items interface{} `json:"items,omitempty"`
|
||||||
Properties interface{} `json:"properties,omitempty"`
|
Properties interface{} `json:"properties,omitempty"`
|
||||||
Position string `json:"position,omitempty"`
|
Position string `json:"position,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -748,9 +748,6 @@ func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.Service
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
Rewrite: &v1alpha3.HTTPRewrite{
|
|
||||||
Uri: path,
|
|
||||||
},
|
|
||||||
Route: []*v1alpha3.HTTPRouteDestination{{
|
Route: []*v1alpha3.HTTPRouteDestination{{
|
||||||
Destination: &v1alpha3.Destination{
|
Destination: &v1alpha3.Destination{
|
||||||
Host: serviceentry.Hosts[0],
|
Host: serviceentry.Hosts[0],
|
||||||
|
|||||||
Reference in New Issue
Block a user