mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 04:37:31 +08:00
Ai proxy support coze (#1387)
This commit is contained in:
@@ -669,6 +669,18 @@ provider:
|
|||||||
timeout: 1200000
|
timeout: 1200000
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 使用 original 协议代理 Coze 应用
|
||||||
|
|
||||||
|
**配置信息**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
provider:
|
||||||
|
type: coze
|
||||||
|
apiTokens:
|
||||||
|
- YOUR_COZE_API_KEY
|
||||||
|
protocol: original
|
||||||
|
```
|
||||||
|
|
||||||
### 使用月之暗面配合其原生的文件上下文
|
### 使用月之暗面配合其原生的文件上下文
|
||||||
|
|
||||||
提前上传文件至月之暗面,以文件内容作为上下文使用其 AI 服务。
|
提前上传文件至月之暗面,以文件内容作为上下文使用其 AI 服务。
|
||||||
|
|||||||
@@ -656,6 +656,16 @@ providers:
|
|||||||
timeout: 1200000
|
timeout: 1200000
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using original Protocol Proxy for Coze applications
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
provider:
|
||||||
|
type: coze
|
||||||
|
apiTokens:
|
||||||
|
- YOUR_COZE_API_KEY
|
||||||
|
protocol: original
|
||||||
|
```
|
||||||
|
|
||||||
### Utilizing Moonshot with its Native File Context
|
### Utilizing Moonshot with its Native File Context
|
||||||
|
|
||||||
Upload files to Moonshot in advance and use its AI services based on file content.
|
Upload files to Moonshot in advance and use its AI services based on file content.
|
||||||
|
|||||||
44
plugins/wasm-go/extensions/ai-proxy/provider/coze.go
Normal file
44
plugins/wasm-go/extensions/ai-proxy/provider/coze.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package provider
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/alibaba/higress/plugins/wasm-go/extensions/ai-proxy/util"
|
||||||
|
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
|
||||||
|
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
cozeDomain = "api.coze.cn"
|
||||||
|
)
|
||||||
|
|
||||||
|
type cozeProviderInitializer struct{}
|
||||||
|
|
||||||
|
func (m *cozeProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
||||||
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
|
return errors.New("no apiToken found in provider config")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *cozeProviderInitializer) CreateProvider(config ProviderConfig) (Provider, error) {
|
||||||
|
return &cozeProvider{
|
||||||
|
config: config,
|
||||||
|
contextCache: createContextCache(&config),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type cozeProvider struct {
|
||||||
|
config ProviderConfig
|
||||||
|
contextCache *contextCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *cozeProvider) GetProviderType() string {
|
||||||
|
return providerTypeCoze
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *cozeProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, log wrapper.Log) (types.Action, error) {
|
||||||
|
_ = util.OverwriteRequestHost(cozeDomain)
|
||||||
|
_ = util.OverwriteRequestAuthorization("Bearer " + m.config.GetRandomToken())
|
||||||
|
return types.ActionContinue, nil
|
||||||
|
}
|
||||||
@@ -42,6 +42,7 @@ const (
|
|||||||
providerTypeMistral = "mistral"
|
providerTypeMistral = "mistral"
|
||||||
providerTypeCohere = "cohere"
|
providerTypeCohere = "cohere"
|
||||||
providerTypeDoubao = "doubao"
|
providerTypeDoubao = "doubao"
|
||||||
|
providerTypeCoze = "coze"
|
||||||
|
|
||||||
protocolOpenAI = "openai"
|
protocolOpenAI = "openai"
|
||||||
protocolOriginal = "original"
|
protocolOriginal = "original"
|
||||||
@@ -101,6 +102,7 @@ var (
|
|||||||
providerTypeMistral: &mistralProviderInitializer{},
|
providerTypeMistral: &mistralProviderInitializer{},
|
||||||
providerTypeCohere: &cohereProviderInitializer{},
|
providerTypeCohere: &cohereProviderInitializer{},
|
||||||
providerTypeDoubao: &doubaoProviderInitializer{},
|
providerTypeDoubao: &doubaoProviderInitializer{},
|
||||||
|
providerTypeCoze: &cozeProviderInitializer{},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user