Skip to content

Commit 29370b1

Browse files
authored
feat: Support /v1/models API in ai-proxy (#2164)
1 parent c9733d4 commit 29370b1

File tree

5 files changed

+10
-0
lines changed

5 files changed

+10
-0
lines changed

plugins/wasm-go/extensions/ai-proxy/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ func getApiName(path string) provider.ApiName {
358358
if strings.HasSuffix(path, "/v1/files") {
359359
return provider.ApiNameFiles
360360
}
361+
if strings.HasSuffix(path, "/v1/models") {
362+
return provider.ApiNameModels
363+
}
361364
// cohere style
362365
if strings.HasSuffix(path, "/v1/rerank") {
363366
return provider.ApiNameCohereV1Rerank

plugins/wasm-go/extensions/ai-proxy/provider/moonshot.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
const (
2121
moonshotDomain = "api.moonshot.cn"
2222
moonshotChatCompletionPath = "/v1/chat/completions"
23+
moonshotModelsPath = "/v1/models"
2324
)
2425

2526
type moonshotProviderInitializer struct {
@@ -38,6 +39,7 @@ func (m *moonshotProviderInitializer) ValidateConfig(config *ProviderConfig) err
3839
func (m *moonshotProviderInitializer) DefaultCapabilities() map[string]string {
3940
return map[string]string{
4041
string(ApiNameChatCompletion): moonshotChatCompletionPath,
42+
string(ApiNameModels): moonshotModelsPath,
4143
}
4244
}
4345

plugins/wasm-go/extensions/ai-proxy/provider/ollama.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (m *ollamaProviderInitializer) DefaultCapabilities() map[string]string {
3030
// ollama的chat接口path和OpenAI的chat接口一样
3131
string(ApiNameChatCompletion): PathOpenAIChatCompletions,
3232
string(ApiNameEmbeddings): PathOpenAIEmbeddings,
33+
string(ApiNameModels): PathOpenAIModels,
3334
}
3435
}
3536

plugins/wasm-go/extensions/ai-proxy/provider/openai.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
defaultOpenaiEmbeddingsPath = "/v1/embeddings"
2222
defaultOpenaiAudioSpeech = "/v1/audio/speech"
2323
defaultOpenaiImageGeneration = "/v1/images/generations"
24+
defaultOpenaiModels = "/v1/models"
2425
)
2526

2627
type openaiProviderInitializer struct {
@@ -37,6 +38,7 @@ func (m *openaiProviderInitializer) DefaultCapabilities() map[string]string {
3738
string(ApiNameEmbeddings): defaultOpenaiEmbeddingsPath,
3839
string(ApiNameImageGeneration): defaultOpenaiImageGeneration,
3940
string(ApiNameAudioSpeech): defaultOpenaiAudioSpeech,
41+
string(ApiNameModels): defaultOpenaiModels,
4042
}
4143
}
4244

plugins/wasm-go/extensions/ai-proxy/provider/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ const (
3131
ApiNameAudioSpeech ApiName = "openai/v1/audiospeech"
3232
ApiNameFiles ApiName = "openai/v1/files"
3333
ApiNameBatches ApiName = "openai/v1/batches"
34+
ApiNameModels ApiName = "openai/v1/models"
3435

3536
PathOpenAICompletions = "/v1/completions"
3637
PathOpenAIChatCompletions = "/v1/chat/completions"
3738
PathOpenAIEmbeddings = "/v1/embeddings"
3839
PathOpenAIFiles = "/v1/files"
3940
PathOpenAIBatches = "/v1/batches"
41+
PathOpenAIModels = "/v1/models"
4042

4143
// TODO: 以下是一些非标准的API名称,需要进一步确认是否支持
4244
ApiNameCohereV1Rerank ApiName = "cohere/v1/rerank"

0 commit comments

Comments
 (0)