Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions conf/llm_factories.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
{
"factory_llm_infos": [
{
"name": "GreenPT",
"logo": "",
"tags": "LLM,TEXT EMBEDDING,TEXT RE-RANK,SPEECH2TEXT",
"status": "1",
"rank": "50",
"url": "https://api.greenpt.ai/v1",
"llm": [
{
"llm_name": "glm-5.2",
"tags": "LLM,CHAT,1M",
"max_tokens": 1000000,
"model_type": "chat",
"is_tools": true
},
{
"llm_name": "kimi-k2.7-code",
"tags": "LLM,CHAT,256K",
"max_tokens": 262144,
"model_type": "chat",
"is_tools": true
},
{
"llm_name": "green-embedding",
"tags": "TEXT EMBEDDING,32K",
"max_tokens": 32768,
"model_type": "embedding",
"is_tools": false
},
{
"llm_name": "green-rerank",
"tags": "RE-RANK,32K",
"max_tokens": 32768,
"model_type": "rerank",
"is_tools": false
},
{
"llm_name": "green-s",
"tags": "SPEECH2TEXT",
"max_tokens": 0,
"model_type": "speech2text",
"is_tools": false
},
{
"llm_name": "green-s-pro",
"tags": "SPEECH2TEXT",
"max_tokens": 0,
"model_type": "speech2text",
"is_tools": false
}
]
},
{
"name": "aimlapi.com",
"logo": "",
Expand Down
69 changes: 69 additions & 0 deletions conf/models/greenpt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "GreenPT",
"rank": 50,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the rank, I suggest set it as 500 or remove it, since:

factoryRankMapping[factory.Name] = -factory.Rank
for _, llm := range factory.Models {
rank := 500
if llm.Rank != nil {
rank = *llm.Rank
}
modelRankMap[factory.Name+"@"+llm.Name] = rank

If you set it as 50, It will always let GreenPT in the end of the model provider list

Suggested change
"rank": 50,

"url": {
"default": "https://api.greenpt.ai"
},
"url_suffix": {
"chat": "v1/chat/completions",
"models": "v1/models",
"embedding": "v1/embeddings",
"rerank": "v1/rerank",
"asr": "v1/listen"
},
"class": "greenpt",
"models": [
{
"name": "glm-5.2",
"max_tokens": 1000000,
"model_types": [
"chat"
],
"tools": {
"support": true
}
},
{
"name": "kimi-k2.7-code",
"max_tokens": 262144,
"model_types": [
"chat"
],
"tools": {
"support": true
}
},
{
"name": "green-embedding",
"max_tokens": 32768,
"max_dimension": 2560,
"dimensions": [
2560
],
"model_types": [
"embedding"
]
},
{
"name": "green-rerank",
"max_tokens": 32768,
"model_types": [
"rerank"
]
},
{
"name": "green-s",
"max_tokens": 0,
"model_types": [
"asr"
]
},
{
"name": "green-s-pro",
"max_tokens": 0,
"model_types": [
"asr"
]
}
]
}
1 change: 1 addition & 0 deletions docs/guides/models/supported_models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ A complete list of model providers supported by RAGFlow, which will continue to
| Google Cloud | `https://cloud.google.com` |
| GPUStack | `https://gpustack.ai` |
| Groq | `https://groq.com` |
| GreenPT | `https://greenpt.ai` |
| HuggingFace | `https://huggingface.co` |
| Jina | `https://jina.ai` |
| LocalAI | `https://localai.io` |
Expand Down
2 changes: 2 additions & 0 deletions internal/entity/models/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func (f *ModelFactory) CreateModelDriver(providerName string, baseURL map[string
return NewXiaomiModel(baseURL, urlSuffix), nil
case "funasr":
return NewFunASRModel(baseURL, urlSuffix), nil
case "greenpt":
return NewGreenPTModel(baseURL, urlSuffix), nil
default:
return NewDummyModel(baseURL, urlSuffix), nil
}
Expand Down
145 changes: 145 additions & 0 deletions internal/entity/models/greenpt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package models

import (
"context"
"encoding/json"
"fmt"
"io"
"mime"
"net/http"
"net/url"
"os"
"path/filepath"
"ragflow/internal/common"
"strings"
)

// GreenPTModel implements GreenPT's OpenAI-compatible chat, embedding,
// reranking, and model-list APIs, plus its Deepgram-compatible STT endpoint.
type GreenPTModel struct {
*OpenAIAPICompatibleModel
}

// NewGreenPTModel creates a GreenPT model driver.
func NewGreenPTModel(baseURL map[string]string, urlSuffix URLSuffix) *GreenPTModel {
return &GreenPTModel{
OpenAIAPICompatibleModel: NewOpenAIAPICompatibleModel(baseURL, urlSuffix),
}
}

func (m *GreenPTModel) Name() string {
return "GreenPT"
}

func (m *GreenPTModel) NewInstance(baseURL map[string]string) ModelDriver {
return NewGreenPTModel(baseURL, m.baseModel.URLSuffix)
}

// ListModels uses GreenPT's live /v1/models endpoint and corrects the two
// speech model IDs, whose names do not contain an ASR hint.
func (m *GreenPTModel) ListModels(ctx context.Context, apiConfig *APIConfig) ([]ListModelResponse, error) {
models, err := m.OpenAIAPICompatibleModel.ListModels(ctx, apiConfig)
if err != nil {
return nil, err
}
for i := range models {
switch models[i].Name {
case "green-s", "green-s-pro":
models[i].ModelTypes = []string{"asr"}
}
}
return models, nil
}

// TranscribeAudio calls GreenPT's Deepgram-compatible /v1/listen endpoint.
func (m *GreenPTModel) TranscribeAudio(ctx context.Context, modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, modelUsage *common.ModelUsage) (*ASRResponse, error) {
if err := m.baseModel.APIConfigCheck(apiConfig); err != nil {
return nil, err
}
if modelName == nil || strings.TrimSpace(*modelName) == "" {
return nil, fmt.Errorf("model name is required")
}
if file == nil || strings.TrimSpace(*file) == "" {
return nil, fmt.Errorf("file is missing")
}

ctx, cancel := context.WithTimeout(ctx, nonStreamCallTimeout)
defer cancel()

audio, err := os.Open(*file)
if err != nil {
return nil, fmt.Errorf("failed to open audio file: %w", err)
}
defer audio.Close()

baseURL, err := m.baseModel.GetBaseURL(apiConfig)
if err != nil {
return nil, err
}
endpoint := fmt.Sprintf("%s/%s", strings.TrimSuffix(baseURL, "/"), strings.TrimPrefix(m.baseModel.URLSuffix.ASR, "/"))
query := url.Values{"model": {*modelName}}
if asrConfig != nil {
for key, value := range asrConfig.Params {
query.Set(key, fmt.Sprintf("%v", value))
}
}
endpoint += "?" + query.Encode()

req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, audio)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
contentType := mime.TypeByExtension(strings.ToLower(filepath.Ext(*file)))
if contentType == "" {
contentType = "application/octet-stream"
}
req.Header.Set("Content-Type", contentType)
req.Header.Set("Authorization", "Token "+*apiConfig.ApiKey)

resp, err := m.baseModel.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("GreenPT ASR API error: %s, body: %s", resp.Status, string(body))
}

var result struct {
Results struct {
Channels []struct {
Alternatives []struct {
Transcript string `json:"transcript"`
} `json:"alternatives"`
} `json:"channels"`
} `json:"results"`
}
if err := json.Unmarshal(body, &result); err != nil {
return nil, fmt.Errorf("failed to parse GreenPT ASR response: %w", err)
}
if len(result.Results.Channels) == 0 || len(result.Results.Channels[0].Alternatives) == 0 {
return nil, fmt.Errorf("GreenPT ASR response contains no transcript")
}
return &ASRResponse{Text: result.Results.Channels[0].Alternatives[0].Transcript}, nil
}
Loading
Loading