2026-01-19 23:45:08 +08:00
|
|
|
|
<!--
|
2026-02-23 01:50:43 +08:00
|
|
|
|
ApiDocumentDemo.vue - 紧凑版
|
|
|
|
|
|
目标:演示如何阅读 API 文档
|
2026-01-19 23:45:08 +08:00
|
|
|
|
-->
|
|
|
|
|
|
<template>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="demo-root">
|
|
|
|
|
|
<div class="demo-header">
|
|
|
|
|
|
<span class="icon">📖</span>
|
|
|
|
|
|
<span class="title">API 文档翻译机</span>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="demo-layout">
|
|
|
|
|
|
<div class="left-panel">
|
|
|
|
|
|
<div class="doc-section">
|
|
|
|
|
|
<div class="doc-title">Base URL</div>
|
|
|
|
|
|
<code class="doc-code">https://api.deepseek.com</code>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="doc-section">
|
|
|
|
|
|
<div class="doc-title">Endpoint</div>
|
|
|
|
|
|
<code class="doc-code">POST /v1/chat/completions</code>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="doc-section">
|
|
|
|
|
|
<div class="doc-title">Headers</div>
|
|
|
|
|
|
<pre class="doc-pre">
|
|
|
|
|
|
Authorization: Bearer sk-xxx
|
2026-02-23 12:09:47 +08:00
|
|
|
|
Content-Type: application/json</pre>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="doc-section">
|
|
|
|
|
|
<div class="doc-title">Body 参数</div>
|
|
|
|
|
|
<div class="params-list">
|
|
|
|
|
|
<div class="param-item">
|
|
|
|
|
|
<span class="p-name">model</span>
|
|
|
|
|
|
<span class="p-req">必填</span>
|
|
|
|
|
|
<span class="p-desc">模型名称</span>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="param-item">
|
|
|
|
|
|
<span class="p-name">messages</span>
|
|
|
|
|
|
<span class="p-req">必填</span>
|
|
|
|
|
|
<span class="p-desc">对话消息</span>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
</div>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="param-item">
|
|
|
|
|
|
<span class="p-name">temperature</span>
|
|
|
|
|
|
<span class="p-opt">可选</span>
|
|
|
|
|
|
<span class="p-desc">0-2,默认1</span>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
</div>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="right-panel">
|
|
|
|
|
|
<div class="result-title">翻译成代码</div>
|
|
|
|
|
|
<pre class="result-code"><code>from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
|
|
client = OpenAI(
|
|
|
|
|
|
api_key="sk-xxx",
|
|
|
|
|
|
base_url="https://api.deepseek.com"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
response = client.chat.completions.create(
|
|
|
|
|
|
model="deepseek-chat",
|
|
|
|
|
|
messages=[{"role": "user", "content": "你好"}]
|
|
|
|
|
|
)</code></pre>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="info-box">
|
|
|
|
|
|
<strong>核心思想:</strong>
|
2026-02-23 12:09:47 +08:00
|
|
|
|
<span>看文档找三样:地址(Base
|
|
|
|
|
|
URL)、鉴权(Authorization)、参数(Parameters)。</span>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
</div>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<script setup></script>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.demo-root {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-02-23 01:50:43 +08:00
|
|
|
|
border-radius: 10px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
overflow: hidden;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
|
|
margin: 1rem 0;
|
|
|
|
|
|
font-size: 0.85rem;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.demo-header {
|
|
|
|
|
|
padding: 10px 16px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
gap: 8px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.icon {
|
2026-02-23 01:50:43 +08:00
|
|
|
|
font-size: 18px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
.title {
|
2026-01-20 17:53:22 +08:00
|
|
|
|
font-weight: 600;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
font-size: 0.9rem;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.demo-layout {
|
|
|
|
|
|
display: flex;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.left-panel {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
border-right: 1px solid var(--vp-c-divider);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.right-panel {
|
|
|
|
|
|
width: 280px;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
background: var(--vp-c-bg);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
@media (max-width: 640px) {
|
|
|
|
|
|
.demo-layout {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
.left-panel {
|
|
|
|
|
|
border-right: none;
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
}
|
|
|
|
|
|
.right-panel {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.doc-section {
|
|
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
overflow: hidden;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.doc-title {
|
|
|
|
|
|
padding: 6px 10px;
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.doc-code {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
padding: 8px 10px;
|
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
color: var(--vp-c-brand);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.doc-pre {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 8px 10px;
|
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
|
color: var(--vp-c-text-1);
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.params-list {
|
|
|
|
|
|
padding: 6px 10px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.param-item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
padding: 4px 0;
|
|
|
|
|
|
font-size: 0.75rem;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.p-name {
|
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
|
font-weight: 600;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.p-req {
|
|
|
|
|
|
background: #fee2e2;
|
|
|
|
|
|
color: #991b1b;
|
|
|
|
|
|
padding: 1px 6px;
|
|
|
|
|
|
border-radius: 3px;
|
|
|
|
|
|
font-size: 0.65rem;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.p-opt {
|
|
|
|
|
|
background: #dbeafe;
|
|
|
|
|
|
color: #1e40af;
|
|
|
|
|
|
padding: 1px 6px;
|
|
|
|
|
|
border-radius: 3px;
|
|
|
|
|
|
font-size: 0.65rem;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.p-desc {
|
|
|
|
|
|
color: var(--vp-c-text-3);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.result-title {
|
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
margin-bottom: 8px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.result-code {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
background: #1e293b;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
font-family: 'Menlo', 'Monaco', monospace;
|
|
|
|
|
|
font-size: 0.7rem;
|
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
|
color: #e2e8f0;
|
|
|
|
|
|
overflow-x: auto;
|
2026-01-20 08:51:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.info-box {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 0.25rem;
|
|
|
|
|
|
padding: 10px 14px;
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
border-top: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.info-box strong {
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
flex-shrink: 0;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|