sanbo commited on
Commit
184bb07
·
1 Parent(s): 5e0f525

update sth. at 2024-12-18 21:14:43

Browse files
Files changed (2) hide show
  1. README.md +3 -3
  2. main.go +47 -0
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
- title: dd
3
- emoji: 🐲
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: docker
7
  pinned: true
8
  app_port: 7860
9
- short_description: dd
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: ddchat
3
+ emoji: 🦀
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: docker
7
  pinned: true
8
  app_port: 7860
9
+ short_description: ddchat
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
main.go CHANGED
@@ -18,6 +18,7 @@ import (
18
  "github.com/joho/godotenv"
19
  )
20
 
 
21
  var staticFiles embed.FS
22
 
23
  type Config struct {
@@ -96,11 +97,20 @@ func main() {
96
  r.GET("/", func(c *gin.Context) {
97
  c.Redirect(http.StatusMovedPermanently, "/web")
98
  })
 
 
 
99
  // 3. 健康检查
100
  r.GET("/ping", func(c *gin.Context) {
101
  c.JSON(http.StatusOK, gin.H{"message": "pong"})
102
  })
103
  // 4. API 路由组
 
 
 
 
 
 
104
  apiGroup := r.Group("/")
105
  apiGroup.Use(authMiddleware()) // 可以选择性地提供 API 密钥
106
  {
@@ -337,6 +347,43 @@ func handleCompletion(c *gin.Context) {
337
  }
338
  }
339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  func requestToken() (string, error) {
341
  url := "https://duckduckgo.com/duckchat/v1/status"
342
  client := &http.Client{
 
18
  "github.com/joho/godotenv"
19
  )
20
 
21
+ //go:embed web/*
22
  var staticFiles embed.FS
23
 
24
  type Config struct {
 
97
  r.GET("/", func(c *gin.Context) {
98
  c.Redirect(http.StatusMovedPermanently, "/web")
99
  })
100
+ // r.GET("/", func(c *gin.Context) {
101
+ // c.JSON(http.StatusOK, gin.H{"message": "API 服务运行中~"})
102
+ // })
103
  // 3. 健康检查
104
  r.GET("/ping", func(c *gin.Context) {
105
  c.JSON(http.StatusOK, gin.H{"message": "pong"})
106
  })
107
  // 4. API 路由组
108
+ // authorized := r.Group("/")
109
+ // authorized.Use(authMiddleware())
110
+ // {
111
+ // authorized.GET("/hf/v1/models", handleModels)
112
+ // authorized.POST("/hf/v1/chat/completions", handleCompletion)
113
+ // }
114
  apiGroup := r.Group("/")
115
  apiGroup.Use(authMiddleware()) // 可以选择性地提供 API 密钥
116
  {
 
347
  }
348
  }
349
 
350
+ //func requestToken() (string, error) {
351
+ // req, err := http.NewRequest("GET", "https://duckduckgo.com/duckchat/v1/status", nil)
352
+ // if err != nil {
353
+ // return "", fmt.Errorf("创建请求失败: %v", err)
354
+ // }
355
+ // for k, v := range config.FakeHeaders {
356
+ // req.Header.Set(k, v)
357
+ // }
358
+ // req.Header.Set("x-vqd-accept", "1")
359
+ //
360
+ // client := &http.Client{
361
+ // Timeout: 10 * time.Second,
362
+ // }
363
+ //
364
+ // log.Println("发送 token 请求")
365
+ // resp, err := client.Do(req)
366
+ // if err != nil {
367
+ // return "", fmt.Errorf("请求失败: %v", err)
368
+ // }
369
+ // defer resp.Body.Close()
370
+ //
371
+ // if resp.StatusCode != http.StatusOK {
372
+ // bodyBytes, _ := io.ReadAll(resp.Body)
373
+ // bodyString := string(bodyBytes)
374
+ // log.Printf("requestToken: 非200响应: %d, 内容: %s\n", resp.StatusCode, bodyString)
375
+ // return "", fmt.Errorf("非200响应: %d, 内容: %s", resp.StatusCode, bodyString)
376
+ // }
377
+ //
378
+ // token := resp.Header.Get("x-vqd-4")
379
+ // if token == "" {
380
+ // return "", errors.New("响应中未包含x-vqd-4头")
381
+ // }
382
+ //
383
+ // // log.Printf("获取到的 token: %s\n", token)
384
+ // return token, nil
385
+ //}
386
+
387
  func requestToken() (string, error) {
388
  url := "https://duckduckgo.com/duckchat/v1/status"
389
  client := &http.Client{