Skip to content

Gemini

Authentication

参考接入 BytePower

Gemini Chat

接口功能: 官方所有 chat 接口

Method & Path

  • POST {domain}/bp/ai/gemini/chat
  • POST {domain}/bp/server/user/{user_id}/ai/gemini/chat

Request

  • content-type: "application/json"

  • content-type: "application/json"

ParametersTypeRequiredDesc
strategystringtruestrategy
chat_idstringfalseserver save history
dataobjecttrueother Parameters

data 填写 gemini 官方参数,地址: https://ai.google.dev/api/rest/v1beta/models/generateContent?hl=zh-cn

官方参数中的 model 由 console 指定,用户端传入也会被 console 值覆盖(因为模型价格不一致)

json
{
  "strategy": "gemini",
  "chat_id": "CtEKQGZB35S6KEQXBU",
  "data": {
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "hi"
          }
        ]
      }
    ]
  }
}

Response

  • HTTP 状态码:200
json
{
  "asset": [],
  "chat_id": "CtEKQGZB35S6KEQXBU",
  "current_count": 41,
  "current_total_count": 41,
  "data": {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "Hello there! How can I assist you today?"
            }
          ]
        },
        "finishReason": "STOP",
        "index": 0,
        "safetyRatings": [
          {
            "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
            "probability": "NEGLIGIBLE"
          },
          {
            "category": "HARM_CATEGORY_HATE_SPEECH",
            "probability": "NEGLIGIBLE"
          },
          {
            "category": "HARM_CATEGORY_HARASSMENT",
            "probability": "NEGLIGIBLE"
          },
          {
            "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
            "probability": "NEGLIGIBLE"
          }
        ]
      }
    ],
    "promptFeedback": {
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    },
    "chat_id": ""
  }
}

Gemini Chat Stream

接口功能: chat stream

Method & Path

  • POST {domain}/bp/ai/gemini/chat/stream
  • POST {domain}/bp/server/user/{user_id}/ai/gemini/chat/stream

Request

  • content-type: "application/json"

  • content-type: "application/json"

ParametersTypeRequiredDesc
strategystringtruestrategy
chat_idstringfalseserver save history
dataobjecttrueother Parameters

data 填写 gemini 官方参数,地址: https://ai.google.dev/api/rest/v1beta/models/streamGenerateContent?hl=zh-cn

官方参数中的 model 由 console 指定,用户端传入也会被 console 值覆盖(因为模型价格不一致)

json
{
  "strategy": "gemini",
  "chat_id": "CtEKQGZB35S6KEQXBU",
  "data": {
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "hi"
          }
        ]
      }
    ]
  }
}

Response

  • HTTP 状态码:200
json
event: ai_chat_msg
data: {"candidates":[{"content":{"role":"model","parts":[{"text":"Hello there! How can I assist you today?"}]},"finishReason":"STOP","index":0,"safetyRatings":[{"category":"HARM_CATEGORY_SEXUALLY_EXPLICIT","probability":"NEGLIGIBLE"},{"category":"HARM_CATEGORY_HATE_SPEECH","probability":"NEGLIGIBLE"},{"category":"HARM_CATEGORY_HARASSMENT","probability":"NEGLIGIBLE"},{"category":"HARM_CATEGORY_DANGEROUS_CONTENT","probability":"NEGLIGIBLE"}]}],"promptFeedback":{"safetyRatings":[{"category":"HARM_CATEGORY_SEXUALLY_EXPLICIT","probability":"NEGLIGIBLE"},{"category":"HARM_CATEGORY_HATE_SPEECH","probability":"NEGLIGIBLE"},{"category":"HARM_CATEGORY_HARASSMENT","probability":"NEGLIGIBLE"},{"category":"HARM_CATEGORY_DANGEROUS_CONTENT","probability":"NEGLIGIBLE"}]},"chat_id":"CtEK2PHHHA4BG3TE2M"}

京ICP备19011570号-2