link0518 commited on
Commit
27307b4
·
1 Parent(s): 7a7d699

显示优化

Browse files
Files changed (1) hide show
  1. client/src/pages/Docs.jsx +18 -7
client/src/pages/Docs.jsx CHANGED
@@ -1,13 +1,24 @@
 
1
  import { Book, Globe, MessageSquare, Shield, Zap, Lightbulb, Code2 } from 'lucide-react';
2
  import CodeBlock from '../components/CodeBlock';
3
  import { cn } from '../lib/utils';
4
 
5
  export default function Docs() {
 
 
 
 
 
 
 
 
 
 
6
  return (
7
  <div className="space-y-8 max-w-4xl mx-auto pb-12">
8
  <div>
9
  <h2 className="text-2xl font-semibold text-zinc-900 mb-2 tracking-tight">API 文档</h2>
10
- <p className="text-zinc-500">Antigravity API 提供与 OpenAI 兼容的接口可无缝对接现有应用。</p>
11
  </div>
12
 
13
  {/* Base URL */}
@@ -16,7 +27,7 @@ export default function Docs() {
16
  <Globe className="w-5 h-5 text-zinc-900" />
17
  基础 URL
18
  </h3>
19
- <CodeBlock code="http://localhost:8045" />
20
  </div>
21
 
22
  {/* Endpoints */}
@@ -26,7 +37,7 @@ export default function Docs() {
26
  path="/v1/models"
27
  title="获取模型列表"
28
  desc="获取所有可用的 AI 模型列表。"
29
- req={`curl http://localhost:8045/v1/models \\
30
  -H "Authorization: Bearer YOUR_API_KEY"`}
31
  res={`{
32
  "object": "list",
@@ -45,8 +56,8 @@ export default function Docs() {
45
  method="POST"
46
  path="/v1/chat/completions"
47
  title="聊天补全"
48
- desc="创建聊天对话补全支持流式和非流式响应。"
49
- req={`curl http://localhost:8045/v1/chat/completions \\
50
  -H "Content-Type: application/json" \\
51
  -H "Authorization: Bearer YOUR_API_KEY" \\
52
  -d '{
@@ -70,7 +81,7 @@ data: [DONE]`}
70
  认证方式
71
  </h3>
72
  <p className="text-zinc-600 text-sm mb-4 leading-relaxed">
73
- 所有 API 请求都需要在请求头中包含有效的 API 密钥
74
  </p>
75
  <CodeBlock code="Authorization: Bearer YOUR_API_KEY" />
76
  </div>
@@ -81,7 +92,7 @@ data: [DONE]`}
81
  频率限制
82
  </h3>
83
  <p className="text-zinc-600 text-sm mb-4 leading-relaxed">
84
- 当请求超过频率限制时API 会返回 429 状态码。响应头包含限制详情
85
  </p>
86
  <ul className="text-sm text-zinc-500 space-y-2 list-disc list-inside marker:text-zinc-300">
87
  <li><code className="bg-zinc-100 px-1.5 py-0.5 rounded text-zinc-700 border border-zinc-200">X-RateLimit-Limit</code>: 最大请求数</li>
 
1
+ import { useState, useEffect } from 'react';
2
  import { Book, Globe, MessageSquare, Shield, Zap, Lightbulb, Code2 } from 'lucide-react';
3
  import CodeBlock from '../components/CodeBlock';
4
  import { cn } from '../lib/utils';
5
 
6
  export default function Docs() {
7
+ // 动态获取基础 URL
8
+ const [baseUrl, setBaseUrl] = useState('');
9
+
10
+ useEffect(() => {
11
+ // 获取当前访问的协议、域名/IP 和端口
12
+ const protocol = window.location.protocol; // http: 或 https:
13
+ const host = window.location.host; // 包含域名/IP 和端口
14
+ setBaseUrl(`${protocol}//${host}`);
15
+ }, []);
16
+
17
  return (
18
  <div className="space-y-8 max-w-4xl mx-auto pb-12">
19
  <div>
20
  <h2 className="text-2xl font-semibold text-zinc-900 mb-2 tracking-tight">API 文档</h2>
21
+ <p className="text-zinc-500">Antigravity API 提供与 OpenAI 兼容的接口,可无缝对接现有应用。</p>
22
  </div>
23
 
24
  {/* Base URL */}
 
27
  <Globe className="w-5 h-5 text-zinc-900" />
28
  基础 URL
29
  </h3>
30
+ <CodeBlock code={baseUrl || 'Loading...'} />
31
  </div>
32
 
33
  {/* Endpoints */}
 
37
  path="/v1/models"
38
  title="获取模型列表"
39
  desc="获取所有可用的 AI 模型列表。"
40
+ req={`curl ${baseUrl}/v1/models \\
41
  -H "Authorization: Bearer YOUR_API_KEY"`}
42
  res={`{
43
  "object": "list",
 
56
  method="POST"
57
  path="/v1/chat/completions"
58
  title="聊天补全"
59
+ desc="创建聊天对话补全,支持流式和非流式响应。"
60
+ req={`curl ${baseUrl}/v1/chat/completions \\
61
  -H "Content-Type: application/json" \\
62
  -H "Authorization: Bearer YOUR_API_KEY" \\
63
  -d '{
 
81
  认证方式
82
  </h3>
83
  <p className="text-zinc-600 text-sm mb-4 leading-relaxed">
84
+ 所有 API 请求都需要在请求头中包含有效的 API 密钥:
85
  </p>
86
  <CodeBlock code="Authorization: Bearer YOUR_API_KEY" />
87
  </div>
 
92
  频率限制
93
  </h3>
94
  <p className="text-zinc-600 text-sm mb-4 leading-relaxed">
95
+ 当请求超过频率限制时,API 会返回 429 状态码。响应头包含限制详情:
96
  </p>
97
  <ul className="text-sm text-zinc-500 space-y-2 list-disc list-inside marker:text-zinc-300">
98
  <li><code className="bg-zinc-100 px-1.5 py-0.5 rounded text-zinc-700 border border-zinc-200">X-RateLimit-Limit</code>: 最大请求数</li>