added -model
This commit is contained in:
@@ -375,29 +375,34 @@ func parseGradioStreamData(dataJSON string) (string, string, []ToolCall, bool) {
|
||||
}
|
||||
|
||||
type HunyuanService struct {
|
||||
endpoint string
|
||||
client *http.Client
|
||||
endpoint string
|
||||
modelName string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func NewHunyuanService(endpoint string) *HunyuanService {
|
||||
func NewHunyuanService(endpoint string, modelName string) *HunyuanService {
|
||||
cleanEndpoint := strings.TrimRight(endpoint, "/")
|
||||
if modelName == "" {
|
||||
modelName = "hy3"
|
||||
}
|
||||
return &HunyuanService{
|
||||
endpoint: cleanEndpoint,
|
||||
client: &http.Client{Timeout: 300 * time.Second},
|
||||
endpoint: cleanEndpoint,
|
||||
modelName: modelName,
|
||||
client: &http.Client{Timeout: 300 * time.Second},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HunyuanService) ListModels() []ModelItem {
|
||||
now := time.Now().Unix()
|
||||
return []ModelItem{
|
||||
{ID: "hy3", Object: "model", Created: now, OwnedBy: "hunyuan"},
|
||||
{ID: s.modelName, Object: "model", Created: now, OwnedBy: "hunyuan"},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HunyuanService) Chat(w http.ResponseWriter, r *http.Request, req ChatCompletionRequest) error {
|
||||
modelName := req.Model
|
||||
if modelName == "" {
|
||||
modelName = "hy3"
|
||||
modelName = s.modelName
|
||||
}
|
||||
maxTokens := ResolveMaxTokens(req)
|
||||
|
||||
@@ -722,6 +727,7 @@ func NewMux(service *HunyuanService) *http.ServeMux {
|
||||
func main() {
|
||||
portFlag := flag.String("port", "8080", "Port to listen on")
|
||||
endpointFlag := flag.String("endpoint", "https://tencent-hy3.hf.space", "Root URL of the Hunyuan Gradio space")
|
||||
modelFlag := flag.String("model", "hy3", "Exposed model name")
|
||||
uaFlag := flag.String("user-agent", DefaultUserAgent, "Custom User-Agent header")
|
||||
uaShortFlag := flag.String("ua", "", "Alias for -user-agent")
|
||||
flag.Parse()
|
||||
@@ -731,11 +737,12 @@ func main() {
|
||||
ConfiguredUserAgent = *uaShortFlag
|
||||
}
|
||||
|
||||
service := NewHunyuanService(*endpointFlag)
|
||||
service := NewHunyuanService(*endpointFlag, *modelFlag)
|
||||
mux := NewMux(service)
|
||||
|
||||
fmt.Printf("hygate starting on port %s...\n", *portFlag)
|
||||
fmt.Printf("Target Endpoint: %s\n", service.endpoint)
|
||||
fmt.Printf("Model Name: %s\n", service.modelName)
|
||||
fmt.Printf("User-Agent: %s\n", ConfiguredUserAgent)
|
||||
fmt.Printf("Endpoints:\n")
|
||||
fmt.Printf(" GET http://localhost:%s/v1/models\n", *portFlag)
|
||||
|
||||
Reference in New Issue
Block a user