<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title><![CDATA[六行·神算API]]></title> 
<atom:link href="https://doc.openai-ss.cn/rss.php" rel="self" type="application/rss+xml" />
<description><![CDATA[]]></description>
<link>https://doc.openai-ss.cn/</link>
<language>zh-cn</language>
<generator>www.emlog.net</generator>
<item>
    <title>API 统一请求格式</title>
    <link>https://doc.openai-ss.cn/?post=39</link>
    <description><![CDATA[<p>所有模型（包括非OpenAI模型）的请求格式已统一为OpenAI格式。</p>
<h2>功能特点</h2>
<ul>
<li>使用OpenAI请求格式可调用所有模型（Claude、Gemini、Doubao、Qwen等）</li>
<li>支持直接使用OpenAI SDK调用任意模型</li>
</ul>
<h2>基础信息</h2>
<ul>
<li><strong>Base URL</strong>: <code>openai-ss.cn</code></li>
<li><strong>认证方式</strong>: API Key (替换为<code>******</code>)</li>
</ul>
<h2>Python示例代码</h2>
<pre><code>import json
import requests

# 配置API参数
url = "https://openai-ss.cn/v1/chat/completions"  # API端点
payload = {
    "model": "gpt-4o-mini",  # 指定模型
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "周树人和鲁迅是兄弟吗？"},
    ],
}
headers = {
    "Accept": "application/json",
    "Authorization": "sk-************",  # 替换为你的API Key
    "Content-Type": "application/json",
}

# 发送请求
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)</code></pre>
<blockquote>
<p>注意：实际使用时请将<code>******</code>替换为你的真实API密钥</p>
</blockquote>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:37:27 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=39</guid>
</item>
<item>
    <title>Openai API 请求格式</title>
    <link>https://doc.openai-ss.cn/?post=38</link>
    <description><![CDATA[<h2>普通对话</h2>
<h2>基础信息</h2>
<ul>
<li>接口地址: <code>https://openai-ss.cn</code></li>
<li>认证方式: Bearer Token (API Key)</li>
</ul>
<h2>普通对话接口</h2>
<h3>POST 请求示例</h3>
<pre><code>import requests
import json

# 配置API参数
url = "https://openai-ss.cn/v1/chat/completions"  # API端点
payload = {
    "model": "gpt-4o-mini",  # 指定模型
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "9.8大还是9.11大？"
        }
    ]
}
headers = {
    'Accept': 'application/json',
    'Authorization': 'sk-*****************************',  # 替换为你的 神算API 令牌key
    'Content-Type': 'application/json'
}

# 发送请求
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)</code></pre>
<h2>使用OpenAI官方SDK</h2>
<pre><code>from openai import OpenAI

# 初始化客户端
client = OpenAI(
    api_key="sk-**********************", # 替换为你的令牌key
    base_url="https://openai-ss.cn/v1"  # 神算地址中转地址
)

# 创建对话
chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "周树人和鲁迅是兄弟吗？",
        }
    ],
    model="o1",  # 指定模型
)

print(chat_completion)</code></pre>
<h2>注意事项</h2>
<ol>
<li>请妥善保管API Key，不要泄露</li>
<li>所有请求必须通过HTTPS发送</li>
<li>响应格式为JSON</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:37:15 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=38</guid>
</item>
<item>
    <title>OpenAI API 文档</title>
    <link>https://doc.openai-ss.cn/?post=37</link>
    <description><![CDATA[<h2>基础信息</h2>
<ul>
<li>接口地址: <code>https://openai-ss.cn</code></li>
<li>认证方式: Bearer Token (API Key)</li>
</ul>
<h2>流式对话接口</h2>
<h3>请求参数</h3>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">model</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">模型名称(如gpt-4o-mini)</td>
</tr>
<tr>
<td style="text-align: left;">stream</td>
<td style="text-align: left;">boolean</td>
<td style="text-align: left;">是否开启流式输出</td>
</tr>
<tr>
<td style="text-align: left;">messages</td>
<td style="text-align: left;">array</td>
<td style="text-align: left;">对话消息列表</td>
</tr>
</tbody>
</table>
<h3>Python 请求示例</h3>
<pre><code>import json
import requests

# 配置请求参数
url = "https://openai-ss.cn/v1/chat/completions"
headers = {
    "Authorization": "Bearer sk-******",  # 替换为你的API Key
    "Content-Type": "application/json"
}
payload = {
    "model": "gpt-4o-mini",
    "stream": True,  # 开启流式输出
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "周树人和鲁迅是兄弟吗？"},
    ]
}

# 发送请求并处理流式响应
response = requests.post(url, headers=headers, json=payload, stream=True)
buffer = ""

for chunk in response.iter_content(chunk_size=None):
    if chunk:
        buffer += chunk.decode("utf-8")
        while "\n" in buffer:
            line, buffer = buffer.split("\n", 1)
            if not line.strip():  # 跳过空行
                continue

            if line.startswith("data: "):
                data_line = line[6:].strip()  # 去除"data: "前缀

                if data_line == "[DONE]":  # 流式结束标记
                    break

                try:
                    data = json.loads(data_line)
                    # 提取并打印响应内容
                    content = data["choices"][0]["delta"].get("content", "")
                    print(content, end="", flush=True)
                except json.JSONDecodeError:
                    # 处理不完整JSON数据
                    buffer = line + "\n" + buffer
                    break</code></pre>
<h2>注意事项</h2>
<ol>
<li>请妥善保管API Key</li>
<li>建议使用HTTPS协议</li>
<li>响应格式为JSON</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:37:01 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=37</guid>
</item>
<item>
    <title>OpenAI 格式 接口文档</title>
    <link>https://doc.openai-ss.cn/?post=36</link>
    <description><![CDATA[<h2>格式化输出 接口说明</h2>
<p>通过OpenAI API获取产品信息，返回JSON格式数据。</p>
<h2>请求地址</h2>
<pre><code>POST https://openai-ss.cn/v1/chat/completions</code></pre>
<h2>请求参数</h2>
<h3>Headers</h3>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">必填</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Authorization</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">API密钥，格式: <code>Bearer ******</code></td>
</tr>
<tr>
<td style="text-align: left;">Content-Type</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">固定值: <code>application/json</code></td>
</tr>
</tbody>
</table>
<h3>Body</h3>
<pre><code>{
  "model": "gpt-4o-2024-08-06",
  "messages": [
    {
      "role": "system",
      "content": "根据给出的产品进行分析，按json格式用中文回答,json format:product_name, price, description."
    },
    {
      "role": "user",
      "content": "产品描述"
    }
  ],
  "response_format": {
    "type": "json_object"
  }
}</code></pre>
<h2>Python示例代码</h2>
<pre><code>from pydantic import BaseModel
from openai import OpenAI
from dotenv import load_dotenv
import json
from textwrap import dedent

# 加载环境变量，例如 API key 等配置信息
load_dotenv()

# 设置 OpenAI API 的工厂名称，默认为 "openai"
factory = "openai"

# 初始化 OpenAI 客户端，传入 API key 和 base URL
client = OpenAI(
    api_key="sk-***********************************************",  # 替换为你的 key
    base_url="https://openai-ss.cn/v1/"   # 这里是的 base url，注意这里需要 /v1/
)

# 定义一个产品信息类，用于解析 API 返回的数据
class ProductInfo(BaseModel):
    product_name: str  # 产品名称，字符串类型
    price: float  # 价格，浮点数类型
    description: str  # 产品描述，字符串类型

# 定义一个提示信息，用于请求模型返回 JSON 格式的产品信息
product_prompt = '''根据给出的产品进行分析，按json格式用中文回答,json format:product_name, price, description.'''

# 获取产品信息的函数，传入用户的问题
def get_product_info(question: str):
    # 使用 OpenAI 客户端进行聊天模型的请求
    completion = client.beta.chat.completions.parse(
        model="gpt-4o-2024-08-06",  # 指定使用的模型
        messages=[
            {"role": "system", "content": dedent(product_prompt)},  # 发送系统消息，设置模型的行为
            {"role": "user", "content": question},  # 发送用户消息，用户提出问题
        ],
        response_format=ProductInfo,  # 指定返回的数据格式为 ProductInfo
    )

    # 返回模型解析的第一个选项的消息结果
    return completion.choices[0].message.parsed

# 初始化一个空的产品信息字典
product_inform = {}

# 定义将解析的结果转换为 JSON 的函数
def transform2JSON(parsed_result):
    # print(parsed_result)  # 打印解析结果

    # 将解析的结果存储到字典中
    product_inform["product_name"] = parsed_result.product_name
    product_inform["price"] = parsed_result.price
    product_inform["description"] = parsed_result.description

    # 将字典转换为 JSON 字符串并返回，ensure_ascii=False 允许中文字符正常显示
    return json.dumps(product_inform, ensure_ascii=False, indent=4)

# 定义用户输入的问题，即一个产品信息的描述
question = "75寸小米电视机"

# 调用函数获取产品信息
result = get_product_info(question)

# 将解析结果转换为 JSON 格式并打印
json_result = transform2JSON(result)
print(json_result)</code></pre>
<h2>返回示例</h2>
<pre><code>{
    "product_name": "小米电视75寸",
    "price": 4999.0,
    "description": "4K超高清画质，支持HDR，内置小爱同学语音助手"
}</code></pre>
<h2>注意事项</h2>
<ol>
<li>请妥善保管API密钥</li>
<li>产品信息由AI生成，仅供参考</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:36:47 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=36</guid>
</item>
<item>
    <title>Openai 请求格式 文本向量化 API</title>
    <link>https://doc.openai-ss.cn/?post=35</link>
    <description><![CDATA[<h2>基本概念</h2>
<h3>什么是Embedding？</h3>
<p>Embedding（嵌入）是将离散数据（如单词、句子）映射到连续向量空间的技术。通过Embedding：</p>
<ul>
<li>语义相似的文本在向量空间中距离更近</li>
<li>便于机器学习模型处理文本数据</li>
<li>典型应用：搜索、推荐、分类等场景</li>
</ul>
<h3>常见Embedding模型</h3>
<ol>
<li><strong>text-embedding-3-small</strong> Openai主流emb模型</li>
<li>text-embedding-3-large</li>
<li>text-embedding-ada-002</li>
<li>doubao-embedding-large-text</li>
</ol>
<h2>技术特点</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">特性</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">维度</td>
<td style="text-align: left;">通常为数百到数千维（如1024维）</td>
</tr>
<tr>
<td style="text-align: left;">归一化</td>
<td style="text-align: left;">多数Embedding会做L2归一化</td>
</tr>
<tr>
<td style="text-align: left;">距离度量</td>
<td style="text-align: left;">常用余弦相似度计算向量距离</td>
</tr>
<tr>
<td style="text-align: left;">多语言支持</td>
<td style="text-align: left;">现代模型通常支持多语言嵌入</td>
</tr>
</tbody>
</table>
<h2>请求地址</h2>
<pre><code>POST https://openai-ss.cn/v1/embeddings</code></pre>
<h2>认证方式</h2>
<p>需要在请求头中添加 API Key：</p>
<pre><code>headers = {
    "Authorization": "Bearer sk-******",  # 替换为你的API令牌
    "Content-Type": "application/json"
}</code></pre>
<h2>请求参数</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">必填</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">input</td>
<td style="text-align: left;">string/array</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">单条文本或文本列表</td>
</tr>
<tr>
<td style="text-align: left;">model</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">使用的模型名称</td>
</tr>
<tr>
<td style="text-align: left;">encoding_format</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">否</td>
<td style="text-align: left;">返回格式（float/base64）</td>
</tr>
</tbody>
</table>
<h2>请求示例</h2>
<pre><code>import openai

# 设置OpenAI API密钥和基础URL
openai.api_key = "sk-***********************************************"  # 替换为你的 key
openai.base_url = "https://openai-ss.cn/v1/"  #  这里是DMXAPI的 base url，注意这里v1后面需要/，最后的 / 很容易漏掉。

def get_embedding(text):
    response = openai.embeddings.create(
        model="text-embedding-3-small",
        input=text
    )
    return response.data[0].embedding

# 示例文本
text = "这是一个示例文本,用于演示如何获取文本嵌入。"

# 获取文本嵌入
embedding = get_embedding(text)

print(f"文本: {text}")
print(f"嵌入向量维度: {len(embedding)}")
print(f"嵌入向量前5个元素: {embedding[:5]}")</code></pre>
<h2>典型应用场景</h2>
<ol>
<li><strong>语义搜索</strong>：通过向量相似度匹配查询和文档</li>
<li><strong>聚类分析</strong>：将相似文本自动归类</li>
<li><strong>推荐系统</strong>：寻找内容相似的物品</li>
<li><strong>异常检测</strong>：识别语义异常的文本</li>
</ol>
<h2>性能优化建议</h2>
<ol>
<li>批量处理文本（最多支持2048 tokens/请求）</li>
<li>对静态内容缓存嵌入结果</li>
<li>使用近似最近邻(ANN)算法加速搜索</li>
</ol>
<h2>响应示例</h2>
<p>成功响应(200):</p>
<pre><code>{
    "object": "list",
    "data": [
        {
            "object": "embedding",
            "embedding": [0.1, -0.2, 0.3, ...],
            "index": 0
        }
    ],
    "model": "text-embedding-ada-002",
    "usage": {
        "prompt_tokens": 5,
        "total_tokens": 5
    }
}</code></pre>
<p>错误响应:</p>
<pre><code>{
    "error": {
        "message": "Invalid input text",
        "type": "invalid_request_error"
    }
}</code></pre>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:36:34 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=35</guid>
</item>
<item>
    <title>Openai请求格式 网络图片分析 API 文档</title>
    <link>https://doc.openai-ss.cn/?post=34</link>
    <description><![CDATA[<h2>接口说明</h2>
<p>通过多模态AI模型分析图片内容，理解图片、提取图片信息，包括OCR功能。</p>
<h2>注意：推荐使用 Openai Responses 新版接口，兼容性更好</h2>
<p>旧版接口偶尔会遇到图片识别报错，但无法查明原因，请改用新版接口进行图片分析</p>
<h2>主流图片分析模型</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">模型名称</th>
<th style="text-align: left;">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">gpt-4o</td>
<td style="text-align: left;">目前图片分析调用量最大的模型，稳定、并发高</td>
</tr>
<tr>
<td style="text-align: left;">gemini-2.5-flash</td>
<td style="text-align: left;">谷歌旗舰模型，速度快，性价比好</td>
</tr>
<tr>
<td style="text-align: left;">claude-sonnet-4-20250514</td>
<td style="text-align: left;">图片分析做的不错，但性价比略差</td>
</tr>
<tr>
<td style="text-align: left;">doubao-1.5-vision-pro-250328</td>
<td style="text-align: left;">国内图片分析主流模型，性价比好，稳定、并发高</td>
</tr>
</tbody>
</table>
<h2>基础信息</h2>
<ul>
<li><strong>Base URL</strong>: <code>https://openai-ss.cn/</code></li>
<li><strong>请求方式</strong>: POST</li>
<li><strong>Content-Type</strong>: <code>application/json</code></li>
</ul>
<h2>接口地址</h2>
<pre><code>POST /v1/chat/completions</code></pre>
<h2>请求头</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">必填</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Authorization</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">Bearer token，格式：<code>Bearer ******</code></td>
</tr>
<tr>
<td style="text-align: left;">Content-Type</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">固定值：<code>application/json</code></td>
</tr>
<tr>
<td style="text-align: left;">User-Agent</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">否</td>
<td style="text-align: left;">客户端标识</td>
</tr>
</tbody>
</table>
<h2>请求参数</h2>
<pre><code>{
  "model": "gemini-2.0-flash-thinking-exp-1219",
  "messages": [
    {
      "role": "system",
      "content": [
        {"type": "text", "text": "你是一个图片分析助手。"}
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "图片URL"
          }
        },
        {
          "type": "text",
          "text": "分析提示词"
        }
      ]
    }
  ],
  "temperature": 0.1,
  "user": "SHENSUAN_APIs"
}</code></pre>
<h2>参数说明</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">必填</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">model</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">模型名称，推荐：<code>gemini-2.5-flash</code> 或 <code>gpt-4o</code></td>
</tr>
<tr>
<td style="text-align: left;">messages</td>
<td style="text-align: left;">array</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">消息内容数组</td>
</tr>
<tr>
<td style="text-align: left;">temperature</td>
<td style="text-align: left;">float</td>
<td style="text-align: left;">否</td>
<td style="text-align: left;">生成文本的随机性，0-1之间</td>
</tr>
<tr>
<td style="text-align: left;">user</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">否</td>
<td style="text-align: left;">用户标识</td>
</tr>
</tbody>
</table>
<h2>Python 调用示例</h2>
<pre><code>import requests

# API配置
BASE_URL = "https://openai-ss.cn.cn/"
API_ENDPOINT = BASE_URL + "v1/chat/completions"
API_KEY = "sk-******"  # 替换为你的API密钥
IMAGE_URL = "https://openai-ss.cn/111.jpg"  # 替换为你的图片URL

def analyze_image(image_url, prompt):
    """
    图片分析函数
    :param image_url: 图片URL
    :param prompt: 分析提示词
    :return: 分析结果文本
    """
    payload = {
        "model": "gemini-2.0-flash-thinking-exp-1219",
        "messages": [
            {
                "role": "system",
                "content": [{"type": "text", "text": "你是一个图片分析助手。"}]
            },
            {
                "role": "user",
                "content": [
                    {"type": "image_url", "image_url": {"url": image_url}},
                    {"type": "text", "text": prompt}
                ]
            }
        ],
        "temperature": 0.1
    }

    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {API_KEY}"
    }

    try:
        response = requests.post(API_ENDPOINT, headers=headers, json=payload)
        response.raise_for_status()
        return response.json()["choices"][0]["message"]["content"]
    except Exception as e:
        print(f"请求失败: {e}")
        return None

# 使用示例
if __name__ == "__main__":
    result = analyze_image(IMAGE_URL, "请描述这张图片的内容")
    if result:
        print("分析结果:", result)</code></pre>
<h2>常见错误码</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">状态码</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">400</td>
<td style="text-align: left;">请求参数错误，看看图片是不是太大了</td>
</tr>
<tr>
<td style="text-align: left;">500</td>
<td style="text-align: left;">服务器内部错误</td>
</tr>
</tbody>
</table>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:36:19 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=34</guid>
</item>
<item>
    <title>Openai 请求格式 本地图片分析 API 文档</title>
    <link>https://doc.openai-ss.cn/?post=33</link>
    <description><![CDATA[<h2>接口说明</h2>
<p>通过多模态AI模型分析图片内容，支持OCR和图片信息提取功能。</p>
<h2>主流图片分析模型</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">模型名称</th>
<th style="text-align: left;">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">gpt-4o</td>
<td style="text-align: left;">目前图片分析调用量最大的模型，稳定、并发高</td>
</tr>
<tr>
<td style="text-align: left;">gemini-2.5-flash</td>
<td style="text-align: left;">谷歌旗舰模型，速度快，性价比好</td>
</tr>
<tr>
<td style="text-align: left;">claude-sonnet-4-20250514</td>
<td style="text-align: left;">图片分析做的不错，但性价比略差</td>
</tr>
<tr>
<td style="text-align: left;">doubao-1.5-vision-pro-250328</td>
<td style="text-align: left;">国内图片分析主流模型，性价比好，稳定、并发高</td>
</tr>
</tbody>
</table>
<h2>本地图片分析预处理</h2>
<p>需要先把本地图片转为 <code>base64</code> 再提交给模型。</p>
<h2>参数说明</h2>
<ul>
<li><code>model</code>: 指定使用的AI模型</li>
<li><code>messages</code>: 包含用户指令和图片数据</li>
<li><code>temperature</code>: 控制输出随机性(0-1)</li>
<li><code>image_url</code>: 支持Base64编码的本地图片或网络图片URL</li>
</ul>
<h2>请求示例</h2>
<pre><code>import base64
import requests

def encode_image(image_path):
    """将本地图片编码为Base64字符串"""
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

# API配置
BASE_URL = "https://openai-ss.cn/"
API_ENDPOINT = BASE_URL + "v1/chat/completions"
API_KEY = "sk-******"  # 替换为你的API密钥

# 准备请求数据
image_data = encode_image("example.png")  # 本地图片路径

payload = {
    "model": "gpt-4o",  # 指定分析模型
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "请分析图片内容"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/png;base64,{image_data}"
                    }
                }
            ]
        }
    ],
    "temperature": 0.1
}

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_KEY}"
}

# 发送请求
response = requests.post(API_ENDPOINT, headers=headers, json=payload)
print(response.json())  # 输出响应结果</code></pre>
<h2>注意事项</h2>
<ol>
<li>图片需小于20MB</li>
<li>支持PNG/JPEG格式；非普通扩展名的图片（例如.file）请先处理成<code>base64</code>再给模型。</li>
<li>响应时间取决于图片大小和模型选择</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:36:05 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=33</guid>
</item>
<item>
    <title>OpenAI 函数调用(Function Calling) API 文档</title>
    <link>https://doc.openai-ss.cn/?post=32</link>
    <description><![CDATA[<h2>概念介绍</h2>
<p>函数调用(Function Calling)是AI大模型的一种能力。允许大语言模型在对话过程中调用外部函数/工具。当用户提问需要实时数据(如天气、股票等)时，模型会返回函数调用请求，开发者可以在后端执行相应函数并返回结果。</p>
<h2>API 基础信息</h2>
<ul>
<li>请求地址: <code>https://openai-ss.cn/v1/chat/completions</code></li>
<li>请求方法: POST</li>
<li>认证方式: Bearer Token</li>
</ul>
<h2>请求示例</h2>
<pre><code>import http.client
import json

# 创建HTTPS连接
conn = http.client.HTTPSConnection("www.openai-ss.cn")

# 构造请求体
payload = json.dumps({
    "model": "gpt-4o",  # 指定模型
    "max_tokens": 300,  # 最大返回token数
    "temperature": 0.8,  # 生成结果的随机性控制
    "stream": False,  # 是否流式输出
    "messages": [{
        "role": "user",
        "content": "上海今天几度？"  # 用户提问
    }],
    "tools": [{  # 定义可用工具
        "type": "function",
        "function": {
            "name": "get_current_weather",  # 函数名称
            "description": "获得天气信息",  # 功能描述
            "parameters": {  # 参数定义
                "type": "object",
                "properties": {
                    "location": {  # 必填参数：地点
                        "type": "string",
                        "description": "城市和州名，例如：上海, 中国"
                    },
                    "unit": {  # 可选参数：温度单位
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"]
                    }
                },
                "required": ["location"]  # 必填参数列表
            }
        }
    }]
})

# 请求头设置
headers = {
    "Accept": "application/json",
    "Authorization": "Bearer sk-**********************",  # 替换为你的令牌
    "Content-Type": "application/json"
}

# 发送请求
conn.request("POST", "/v1/chat/completions", payload, headers)

# 获取响应
res = conn.getresponse()
data = res.read()

# 输出结果
print(data.decode("utf-8"))</code></pre>
<h2>响应处理</h2>
<p>当用户提问需要调用函数时，API会返回包含函数调用信息的JSON响应。开发者需要：</p>
<ol>
<li>解析响应中的函数调用请求</li>
<li>在后端执行对应函数</li>
<li>将函数结果再次发送给API获取最终回答</li>
</ol>
<h2>注意事项</h2>
<ol>
<li>请妥善保管API密钥，不要泄露</li>
<li>函数定义中的description很重要，会影响模型是否/如何调用该函数</li>
<li>温度参数(temperature)控制生成结果的随机性，值越大结果越多样</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:35:52 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=32</guid>
</item>
<item>
    <title>OpenAI 请求格式 STT(ASR)语音转文本 API 文档</title>
    <link>https://doc.openai-ss.cn/?post=31</link>
    <description><![CDATA[<h2>whisper 模型接口说明</h2>
<p>该接口基于 Whisper 模型实现语音转文本功能，支持常见音频格式。</p>
<h2>基础概念</h2>
<ul>
<li><strong>Whisper模型</strong>: OpenAI 开源的语音识别模型，支持多语言转写</li>
<li><strong>音频格式</strong>: 支持 mp3、wav、m4a 等常见格式</li>
</ul>
<h2>接口地址</h2>
<pre><code>POST https://openai-ss.cn/v1/audio/transcriptions</code></pre>
<h2>请求参数</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">必填</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">model</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">固定值 &quot;whisper-1&quot;</td>
</tr>
<tr>
<td style="text-align: left;">file</td>
<td style="text-align: left;">file</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">要转写的音频文件</td>
</tr>
</tbody>
</table>
<h2>请求头</h2>
<pre><code>Authorization: Bearer sk-*********************  # 替换为你的令牌</code></pre>
<h2>Python 调用示例</h2>
<pre><code>import json
import requests

def voice_to_text(file_path):
    """
    语音转文本功能

    参数:
        file_path: 音频文件路径

    返回:
        识别出的文本内容
    """
    url = "https://openai-ss.cn/v1/audio/transcriptions"

    # 构造请求参数
    payload = {"model": "whisper-1"}
    files = {"file": ("audio.mp3", open(file_path, "rb"))}

    # 设置请求头(请替换为你的API密钥)
    headers = {"Authorization": "Bearer sk-***************************"} # 替换为你的令牌

    # 发送POST请求
    response = requests.post(url, headers=headers, data=payload, files=files)

    # 解析响应数据
    data = json.loads(response.text)

    # 返回识别结果
    return data.get("text", "")

# 使用示例
print(voice_to_text("audio.mp3"))  # 替换为你的音频文件路径</code></pre>
<h2>注意事项</h2>
<ol>
<li>音频文件大小建议不超过25MB</li>
<li>支持中文、英文等多种语言</li>
<li>请妥善保管API密钥，不要泄露</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:35:32 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=31</guid>
</item>
<item>
    <title>Openai 请求格式 TTS 语音合成 API 文档</title>
    <link>https://doc.openai-ss.cn/?post=30</link>
    <description><![CDATA[<h2>接口说明</h2>
<p>提供基于 <code>gpt-4o-mini-tts</code> TTS 模型的文本转语音服务，支持多种音色选择。</p>
<h2>基础概念</h2>
<ul>
<li><strong>TTS(Text-to-Speech)</strong>: 将文本转换为自然语音的技术</li>
<li><strong>音色(Voice)</strong>: 合成语音的声音特征，本API支持多种预设音色</li>
</ul>
<h2>请求地址</h2>
<pre><code>POST https://openai-ss.cn/v1/audio/speech</code></pre>
<h2>请求头</h2>
<pre><code>headers = {
    "Authorization": "Bearer ******",  # 替换为您的API密钥
    "Content-Type": "application/json"
}</code></pre>
<h2>请求参数</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th style="text-align: left;">必填</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">model</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">固定值 &quot;gpt-4o-mini-tts&quot;</td>
</tr>
<tr>
<td style="text-align: left;">input</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">需要转换为语音的文本内容</td>
</tr>
<tr>
<td style="text-align: left;">voice</td>
<td style="text-align: left;">string</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">音色类型，如 &quot;alloy&quot;</td>
</tr>
</tbody>
</table>
<h2>Python 调用示例</h2>
<pre><code>import requests
import json

url = "https://openai-ss.cn/v1/audio/speech"
api_key = "******"  # 替换为您的API密钥

payload = {
    "model": "gpt-4o-mini-tts",
    "input": "我是六行君，欢迎使用语音合成服务",
    "voice": "alloy"
}

try:
    # 发送POST请求
    response = requests.post(url, 
                           headers={"Authorization": f"Bearer {api_key}"},
                           json=payload)

    # 检查响应状态
    response.raise_for_status()

    # 处理音频响应
    if response.headers["Content-Type"] in ("audio/mpeg", "audio/mp3"):
        with open("output.mp3", "wb") as f:
            f.write(response.content)  # 写入音频文件
        print("语音合成成功，已保存为output.mp3")
    else:
        print("错误响应:", response.text)

except Exception as e:
    print(f"请求出错: {e}")</code></pre>
<h2>响应说明</h2>
<ul>
<li>成功: 返回MP3格式的音频流，Content-Type为<code>audio/mpeg</code></li>
<li>失败: 返回JSON格式的错误信息</li>
</ul>
<h2>注意事项</h2>
<ol>
<li>API密钥需妥善保管，不要暴露在客户端代码中</li>
<li>输入文本长度建议不超过500字符</li>
<li>音频采样率为24kHz，比特率128kbps</li>
</ol>]]></description>
    <pubDate>Tue, 23 Sep 2025 14:35:17 +0800</pubDate>
    <dc:creator>shensuan</dc:creator>
    <guid>https://doc.openai-ss.cn/?post=30</guid>
</item></channel>
</rss>