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
parametersobjectfalse用于渲染服务端配置的 system prompt 中的变量
chat_idstringfalseserver save history
dataobjecttrueother Parameters

System Prompt 的优先级和处理规则如下:

  1. data参数优先:如果 data 参数中包含 system prompt 相关配置,则以 data 中的配置为准

  2. 模板渲染:如果 data 中无 system prompt 相关配置,则使用控制台配置的 System Prompt,并通过 parameters 进行模板变量渲染

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

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

json
{
  "strategy": "gemini",
  "chat_id": "CtEKQGZB35S6KEQXBU",
  "parameters": {
    "example_string": "example_value",
    "example_object": {
      "key": "value",
      "key2": "value2"
    }
  },
  "data": {
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "hi"
          }
        ]
      }
    ]
  }
}
  • 说明 parameters 用于在 BytePower 定义了 System Prompt 的 strategy,例如:
现在你扮演 {{ .example_string }}, 告诉我如何使用 {{ .example_object.key }} 完成 {{ .example_object.key2 }}。

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