Token502 API文档
  1. 文本生成
Token502 API文档
  • 产品介绍
  • 基本使用
    • 在API客户端中使用
    • 获取API令牌(API密钥)
    • 常用大模型
  • API
    • 发出请求
    • 完成对象
    • 常见问题
    • OpenAI
      • 聊天(Chat)
        • 创建聊天补全(带图片)
        • 创建聊天补全
      • 音频(Audio)
        • 创建语音
        • 创建转录
        • 创建翻译
      • 图像(Images)
        • 创建图像
        • 创建图片编辑
      • 自动补全(Completions)
        • 创建 Completions
      • 嵌入(Embeddings)
        • 创建嵌入
      • 模型(Models)
        • 列出模型
        • 检索模型
        • 删除微调模型
    • Anthropic
      • 模型
        • 列出模型
        • 获取模型
      • 消息
        • 消息
        • 强制返回思考
        • 图片理解
        • 函数调用
        • 多轮函数调用
        • Web search / 联网搜索
    • Gemini
      • 图片生成
        • 使用 Gemini 生成图片
        • 使用 Gemini 编辑图片
        • 使用 Imagen 3 生成图片
        • 使用 Gemini 生成图片 Copy
      • 文本生成
        • 文字输入
          POST
        • 多轮对话
          POST
        • 流式输出
          POST
        • 多轮对话(流式)
          POST
    • Midjourney
      • 查询
        • 查询接口
        • 批量查询接口
        • 获取种子(Seed)接口
      • 图像
        • 文生图(Imagine)接口
        • 图片融合(Blend)接口
      • 视频
        • 生成视频(Video)接口
      • 其他操作
        • 按钮点击(Action)接口
        • 图生文(Describe)接口
        • 上传(upload)接口
    • 其他厂商LLM
      • grok
        • OpenAI兼容接口
          • 联网搜索 / OpenAI兼容接口
      • 通义千问
    • 图片生成
      • Flux
        • flux-kontext-pro / OpenAI兼容接口
        • flux携带参考图 / OpenAI兼容接口
      • Nano-banana
        • 接口请求和格式
        • chat格式
          • 图片编辑(Nano-banana)
        • dalle格式
          • 图像生成(Nano-banana)
          • 创建图像
          • 创建图片编辑
        • 谷歌官方格式
          • 生成图像
      • seedream
    • 视频生成
      • 如何调用视频模型
      • sora-2
        • chat格式
          • 生成视频
          • 生成视频 Copy
        • 官方格式
          • 生成视频
          • 查询视频
          • 下载视频
          • 编辑视频
      • veo
        • chat 格式
          • 流式请求
          • 流式请求(传图)
        • 视频统一格式
          • 生成视频
          • 查询视频
    • Rerank API
      • Cohere 重排序格式
      • Xinference 重排序格式
      • Jina AI 重排序格式
  • 在客户端中使用
    • cline中使用
    • chatbox中使用大语言模型
  1. 文本生成

文字输入

POST
https://api.token502.com/v1beta/models/gemini-2.5-flash:generateContent
使用 Gemini API 生成文本的最简单方法是向模型提供单个纯文本输入,如以下示例所示:

请求参数

Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
Body 参数application/json

示例
{
    "contents": [
        {
            "parts": [
                {
                    "text": "How does AI work?"
                }
            ]
        }
    ]
}

返回响应

🟢200成功
application/json
Body

示例
{
    "candidates": [
        {
            "content": {
                "role": "model",
                "parts": [
                    {
                        "text": "That's a fantastic question, and at its core, AI isn't magic, but a sophisticated combination of data, algorithms, and powerful computation.\n\nImagine you want to teach a child to identify a cat.\n\n1.  **You show them many pictures of cats:** \"This is a cat, and this is a cat, and this too.\" (And maybe some pictures of dogs, \"This is *not* a cat.\")\n2.  **The child starts to pick up on features:** \"Cats have pointy ears, whiskers, tails, and usually small noses.\"\n3.  **They try to identify a new animal:** \"Is this a cat?\" You provide feedback, \"Yes, that's right!\" or \"No, that's a dog, look at its snout.\"\n4.  **With enough examples and feedback, the child becomes very good at identifying cats.**\n\nAI works in a very similar way, but on a massive scale and with mathematical models instead of a human brain.\n\nHere's a breakdown of the core components:\n\n---\n\n### The Core Pillars of AI\n\n1.  **Data:**\n    *   **The Fuel:** AI systems learn from data, just like a child learns from experiences. This data can be anything: images, text, audio recordings, numbers, sensor readings, etc.\n    *   **Quality & Quantity:** The performance of an AI heavily depends on the amount, quality, and relevance of the data it's trained on. More diverse and accurate data generally leads to better AI.\n    *   **Labeled vs. Unlabeled:**\n        *   **Labeled Data (Supervised Learning):** Data that has been pre-categorized or tagged. E.g., pictures of cats explicitly marked \"cat.\" This is crucial for tasks like image recognition or spam detection.\n        *   **Unlabeled Data (Unsupervised Learning):** Data without explicit tags. The AI tries to find patterns or structures within it, like grouping similar customers together based on purchasing habits.\n\n2.  **Algorithms (The Learning Rules):**\n    *   **The Brain:** These are the mathematical models and statistical techniques that AI systems use to learn from data, identify patterns, make predictions, or take decisions.\n    *   **Parameters:** Algorithms have \"knobs\" or parameters that get adjusted during the learning process to optimize their performance.\n    *   **Common Algorithm Types:**\n        *   **Machine Learning (ML):** This is the broadest category. ML algorithms range from simple linear regressions to complex decision trees, support vector machines, and ensemble methods. They are designed to find relationships in data without being explicitly programmed for every possible scenario.\n        *   **Deep Learning (DL):** A subfield of ML inspired by the structure and function of the human brain. It uses multi-layered \"neural networks\" that can automatically learn complex features from vast amounts of data. Deep learning is behind most breakthroughs in image recognition, natural language processing, and speech recognition.\n        *   **Reinforcement Learning (RL):** This approach involves an \"agent\" learning to make decisions by trial and error in an environment, receiving rewards for good actions and penalties for bad ones. It's used in game playing (like AlphaGo) and robotics.\n\n3.  **Computation (The Processing Power):**\n    *   **The Engine:** Training AI models, especially deep learning ones, requires immense computational power. This is why advancements in GPUs (Graphics Processing Units) have been so critical to AI's recent boom, as they can perform many calculations simultaneously.\n    *   **Cloud Computing:** Cloud platforms (AWS, Google Cloud, Azure) provide scalable computing resources, making AI development accessible to more researchers and companies.\n\n---\n\n### How AI Learns (The Process)\n\nLet's use a common example: **Image Classification (e.g., distinguishing cats from dogs).**\n\n1.  **Data Collection:** Gather a massive dataset of images, some of cats, some of dogs. Each image is **labeled** accordingly.\n2.  **Model Selection:** Choose an appropriate algorithm (e.g., a Convolutional Neural Network, a type of Deep Learning model particularly good for images).\n3.  **Training Phase:**\n    *   **Feed Data:** The algorithm is fed the labeled images one by one (or in small batches).\n    *   **Make a Prediction:** Initially, it makes random guesses (\"Is this a cat or a dog?\").\n    *   **Calculate Error (Loss):** It compares its prediction to the correct label. If it predicted \"dog\" but the image was a \"cat,\" there's an error.\n    *   **Adjust Parameters:** Based on this error, the algorithm mathematically adjusts its internal \"knobs\" (parameters or weights in a neural network) to try and make a more accurate prediction next time. This process is called **optimization**.\n    *   **Iteration:** This entire process (predict, compare, adjust) repeats millions or billions of times across the entire dataset. The model gradually gets better at recognizing the features that distinguish cats from dogs.\n4.  **Validation/Testing:**\n    *   A separate, unseen set of labeled images (the \"validation\" or \"test\" set) is used to check how well the model generalizes to new data. This prevents the model from just memorizing the training data.\n5.  **Inference Phase (Making Predictions in the Real World):**\n    *   Once trained and validated, the model is ready. You can give it a brand new, unlabeled image it has never seen before.\n    *   It will run the image through its learned patterns and output its prediction (e.g., \"95% chance this is a cat, 5% chance it's a dog\").\n\n---\n\n### Types of AI and Their Applications\n\n*   **Narrow AI (or Weak AI):** This is what nearly all AI today is. It's designed and trained for a specific task.\n    *   **Examples:** Image recognition, natural language processing (chatbots, translation), recommendation systems (Netflix, Amazon), self-driving cars, medical diagnosis.\n*   **General AI (or Strong AI / AGI):** Hypothetical AI that could understand, learn, and apply knowledge across a wide range of tasks at a human-like level. This does not exist yet.\n\n---\n\n### In Summary:\n\nAI works by **teaching computers to learn patterns and make decisions from data** using sophisticated algorithms and powerful computing. It's an iterative process of feeding data, making predictions, calculating errors, and adjusting parameters until the system can perform its designated task with high accuracy."
                    }
                ]
            },
            "finishReason": "STOP",
            "index": 0,
            "safetyRatings": []
        }
    ],
    "usageMetadata": {
        "promptTokenCount": 6,
        "candidatesTokenCount": 2515,
        "totalTokenCount": 2521,
        "thoughtsTokenCount": 0,
        "promptTokensDetails": null
    }
}
修改于 2025-10-20 02:28:21
上一页
使用 Gemini 生成图片 Copy
下一页
多轮对话
Built with