feat: 为 rhythm 支持 AIClient 的功能。#185
Conversation
|
似乎没有用到大模型的地方,而且另起一个仓库不是更好? |
上层我这边來对接实现(涉及到商务问题) |
|
AIClient 使用说明文档 概述 AIClient 是一个轻量级的 AI 模型调用客户端,支持 OpenAI 兼容格式的 API,包括流式响应(SSE)和普通响应。 架构设计 AIClient # 核心客户端,负责发送请求和解析响应 核心类说明
// 创建客户端 // 发送请求,返回 Stream
提供者负责构建 HTTP 请求,支持以下配置: 消息类型 (Message):
内容类型 (Content):
配置选项 (Options):
模型需要实现能力标记:
使用示例 基础文本对话 import org.b3log.symphony.ai.; // 1. 创建 HttpClient // 2. 定义模型 // 3. 构建消息 // 4. 创建 Provider OpenAIProvider provider = new OpenAIProvider( // 5. 发送请求并处理响应 带图片的多模态对话 // 构建包含图片的消息 List messages = Message.of( // 使用支持图像的模型 非流式请求 OpenAIProvider provider = new OpenAIProvider( // 非流式只返回一个 JSONObject 已支持的模型
扩展自定义模型 public class CustomModel implements Model, Model.Supported.Text { 异常处理 try { 响应格式 流式响应返回的 JSONObject 遵循 OpenAI 格式: { |
添加 AIClient 的 api 支持,尽可能的按照厂商的 api 以实现类型安全的 eDSL 请求结构构建,避免得到错误的响应。
exampleoutput{"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"role":"assistant","content":""},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"我是"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"通"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"义"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"千"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"问"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":","},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"由"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"阿里巴巴"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"集团"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"旗下的"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"通"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"义"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"实验室"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"研发"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"的"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"超"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"大规模"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"语言"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"模型"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"} {"created":1767463697,"usage":null,"model":"qwen3-vl-plus","id":"chatcmpl-b202002d-5645-95b5-bbea-10843569f883","choices":[{"finish_reason":null,"delta":{"content":"。"},"index":0,"logprobs":null}],"system_fingerprint":null,"object":"chat.completion.chunk"}