Fireworks 
Authentication 
Fireworks Chat 
接口功能:Fireworks Chat
Method & Path 
-  
POST {domain}/bp/ai/fireworks/chat -  
POST {domain}/bp/server/user/{user_id}/ai/fireworks/chat 
Request 
- content-type: "application/json"
 
| Parameters | Type | Required | Desc | 
|---|---|---|---|
| strategy | string | true | strategy | 
| response_format | string | false | 返回格式,如果需要返回 json 则为 json_object | 
| parameters | object | false | 用于渲染服务端配置的 system prompt 中的变量 | 
| chat_id | string | false | 如果在 console 配置保存历史记录则请求服务端会返回,后续可带上 | 
| messages | []object | true | 详细格式如下 | 
| tools | object | false | 函数调用 | 
json
{
  "parameters": {
    "prompt": "you are a helpful bot"
  },
  "messages": [
    {
      "content": "hi",
      "role": "user"
    }
  ]
}- 说明 parameters 用于在 BytePower 定义了 System Prompt 的 strategy,例如:
 
现在你扮演 {{ .example_string }}, 告诉我如何使用 {{ .example_object.key }} 完成 {{ .example_object.key2 }}。Response 
- HTTP 状态码:200
 
json
{
  "asset": [
    {
      "last_recovery_time": "2024-07-05T00:00:00Z",
      "name": "ai_credit",
      "quantity": 50,
      "recoverable": true,
      "recovery_period": 1,
      "recovery_quantity": 50,
      "type": "consumable",
      "valid_seconds": 0
    }
  ],
  "chat_id": "CtESPJTMUWJ2R6RDSW",
  "current_count": 7,
  "current_total_count": 56,
  // 以上为 BP 返回数据
  // 以下为 fireworks 平台返回数据
  "id": "e415023d-4f3a-4155-8fbf-5f82afb228ff",
  "object": "chat.completion",
  "created": 1722505362,
  "model": "accounts/fireworks/models/llama-v3p1-405b-instruct",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! It's nice to meet you. Is there something I can help you with or would you like to chat?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "total_tokens": 37,
    "completion_tokens": 25
  }
}- HTTP 状态码:4xx
 
json
{
  "error": {
    "error_type": "invalid_parameter",
    "message": "xxxxx"
  }
}error_type:
- item_not_found(找不到条目)
 - config_invalid (console 配置问题)
 
Fireworks Chat Stream 
接口功能:Fireworks Chat Stream
Method & Path 
-  
POST {domain}/bp/ai/fireworks/chat/stream -  
POST {domain}/bp/server/user/{user_id}/ai/fireworks/chat/stream 
Request 
- content-type: "application/json"
 
| Parameters | Type | Required | Desc | 
|---|---|---|---|
| strategy | string | true | strategy | 
| response_format | string | false | 返回格式,如果需要返回 json 则为 json_object | 
| parameters | object | false | 用于渲染服务端配置的 system prompt 中的变量 | 
| chat_id | string | false | 如果在 console 配置保存历史记录则请求服务端会返回,后续可带上 | 
| messages | []object | true | 详细格式如下 | 
| tools | object | false | 函数调用 | 
json
{
  "parameters": {
    "prompt": "you are a helpful bot"
  },
  "messages": [
    {
      "content": "hi",
      "role": "user"
    }
  ]
}- 说明 parameters 用于在 BytePower 定义了 System Prompt 的 strategy,例如:
 
现在你扮演 {{ .example_string }}, 告诉我如何使用 {{ .example_object.key }} 完成 {{ .example_object.key2 }}。Response 
- HTTP 状态码:200
 
json
data: {"id":"d8acab24-95a8-4de9-bfa2-4485233b7e47","object":"chat.completion.chunk","created":1723016524,"model":"accounts/fireworks/models/llama-v3p1-405b-instruct","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null,"content_filter_results":{"hate":{"filtered":false},"self_harm":{"filtered":false},"sexual":{"filtered":false},"violence":{"filtered":false}}}],"system_fingerprint":""}
 
data: {"id":"d8acab24-95a8-4de9-bfa2-4485233b7e47","object":"chat.completion.chunk","created":1723016524,"model":"accounts/fireworks/models/llama-v3p1-405b-instruct","choices":[{"index":0,"delta":{"content":"Hi!"},"finish_reason":null,"content_filter_results":{"hate":{"filtered":false},"self_harm":{"filtered":false},"sexual":{"filtered":false},"violence":{"filtered":false}}}],"system_fingerprint":""}
 
data: {"id":"d8acab24-95a8-4de9-bfa2-4485233b7e47","object":"chat.completion.chunk","created":1723016524,"model":"accounts/fireworks/models/llama-v3p1-405b-instruct","choices":[{"index":0,"delta":{"content":" How are you"},"finish_reason":null,"content_filter_results":{"hate":{"filtered":false},"self_harm":{"filtered":false},"sexual":{"filtered":false},"violence":{"filtered":false}}}],"system_fingerprint":""}
 
data: {"id":"d8acab24-95a8-4de9-bfa2-4485233b7e47","object":"chat.completion.chunk","created":1723016524,"model":"accounts/fireworks/models/llama-v3p1-405b-instruct","choices":[{"index":0,"delta":{"content":" today? 😊"},"finish_reason":null,"content_filter_results":{"hate":{"filtered":false},"self_harm":{"filtered":false},"sexual":{"filtered":false},"violence":{"filtered":false}}}],"system_fingerprint":""}
 
data: {"id":"d8acab24-95a8-4de9-bfa2-4485233b7e47","object":"chat.completion.chunk","created":1723016524,"model":"accounts/fireworks/models/llama-v3p1-405b-instruct","choices":[{"index":0,"delta":{},"finish_reason":"stop","content_filter_results":{"hate":{"filtered":false},"self_harm":{"filtered":false},"sexual":{"filtered":false},"violence":{"filtered":false}}}],"system_fingerprint":"","usage":{"prompt_tokens":37,"completion_tokens":10,"total_tokens":47}}
 
data: {"chat_id":"CtEVEE5VNSPJD4S4KX"}
 
data: [DONE]说明:在官方基础上新增一个 chat_id, 用于 BP 记录聊天记录
- HTTP 状态码:4xx
 
json
{
  "error": {
    "error_type": "invalid_parameter",
    "message": "xxxxx"
  }
}error_type:
- item_not_found(找不到条目)
 - config_invalid (console 配置问题)
 
