Spaces:
Sleeping
Sleeping
sanbo
commited on
Commit
·
6390a71
1
Parent(s):
aba79e2
update sth. at 2024-12-18 21:09:42
Browse files
README.md
CHANGED
@@ -1,51 +1,60 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 🦀
|
4 |
colorFrom: indigo
|
5 |
colorTo: blue
|
6 |
sdk: docker
|
7 |
pinned: true
|
8 |
app_port: 7860
|
9 |
-
short_description:
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
|
14 |
# 请求
|
15 |
|
16 |
-
*
|
17 |
|
18 |
``` bash
|
19 |
-
curl https
|
20 |
```
|
21 |
|
22 |
-
*
|
|
|
23 |
``` bash
|
24 |
-
curl --location --request POST 'https
|
25 |
--header 'Content-Type: application/json' \
|
26 |
--data-raw '{
|
27 |
"model": "gpt-4o-mini",
|
28 |
"messages": [
|
29 |
{
|
30 |
"role": "user",
|
31 |
-
"content": "
|
32 |
}
|
33 |
],
|
34 |
"stream": true
|
35 |
}'
|
36 |
|
37 |
|
38 |
-
|
|
|
39 |
--header 'Content-Type: application/json' \
|
40 |
--data-raw '{
|
41 |
"model": "gpt-4o-mini",
|
42 |
"messages": [
|
43 |
{
|
44 |
"role": "user",
|
45 |
-
"content": "
|
46 |
}
|
47 |
],
|
48 |
"stream": true
|
49 |
}'
|
50 |
|
51 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: dc
|
3 |
emoji: 🦀
|
4 |
colorFrom: indigo
|
5 |
colorTo: blue
|
6 |
sdk: docker
|
7 |
pinned: true
|
8 |
app_port: 7860
|
9 |
+
short_description: هذه أداة عملية للغاية يمكن استخدامها للتسلية والترفيه.
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
|
14 |
# 请求
|
15 |
|
16 |
+
* لحصول على النموذج
|
17 |
|
18 |
``` bash
|
19 |
+
curl https://${look |Embed this Space|--|Direct URL|}/models
|
20 |
```
|
21 |
|
22 |
+
* إرسال طلب محادثة
|
23 |
+
|
24 |
``` bash
|
25 |
+
curl --location --request POST 'https://${look |Embed this Space|--|Direct URL|}/hf/v1/chat/completions' \
|
26 |
--header 'Content-Type: application/json' \
|
27 |
--data-raw '{
|
28 |
"model": "gpt-4o-mini",
|
29 |
"messages": [
|
30 |
{
|
31 |
"role": "user",
|
32 |
+
"content": "What is the price of Bitcoin, why, and what are the basic principles behind it?"
|
33 |
}
|
34 |
],
|
35 |
"stream": true
|
36 |
}'
|
37 |
|
38 |
|
39 |
+
# Local Debugging
|
40 |
+
curl --location --request POST 'http://0.0.0.0:7860/completions' \
|
41 |
--header 'Content-Type: application/json' \
|
42 |
--data-raw '{
|
43 |
"model": "gpt-4o-mini",
|
44 |
"messages": [
|
45 |
{
|
46 |
"role": "user",
|
47 |
+
"content": "What is the price of Bitcoin, why, and what are the basic principles behind it?"
|
48 |
}
|
49 |
],
|
50 |
"stream": true
|
51 |
}'
|
52 |
|
53 |
+
```
|
54 |
+
|
55 |
+
# support models
|
56 |
+
|
57 |
+
- claude-3-haiku
|
58 |
+
- llama-3.1-70b
|
59 |
+
- mixtral-8x7b
|
60 |
+
- gpt-4o-mini
|
main.go
CHANGED
@@ -18,7 +18,6 @@ import (
|
|
18 |
"github.com/joho/godotenv"
|
19 |
)
|
20 |
|
21 |
-
//go:embed web/*
|
22 |
var staticFiles embed.FS
|
23 |
|
24 |
type Config struct {
|
@@ -97,20 +96,11 @@ func main() {
|
|
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,43 +337,6 @@ func handleCompletion(c *gin.Context) {
|
|
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{
|
|
|
18 |
"github.com/joho/godotenv"
|
19 |
)
|
20 |
|
|
|
21 |
var staticFiles embed.FS
|
22 |
|
23 |
type Config struct {
|
|
|
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 |
}
|
338 |
}
|
339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
func requestToken() (string, error) {
|
341 |
url := "https://duckduckgo.com/duckchat/v1/status"
|
342 |
client := &http.Client{
|