码巢引擎2026年开发文档
00-开发规范
后端规范
README
后端开发手册
前端规范
README
TypeScript最佳实践
前端布局规范
前端页面模板
前端颜色与组件规范
核心规范
组件配置手册
问题排查指南
页面模板
最佳实践
README
bp-20260223-m7ps
图片上传优化总结
BUG自动记录系统使用指南
README
TYPE_SAFETY_GUIDE
常见BUG知识库
常见BUG知识库
开发前检查清单
开发安全规范
开发规范-完整版-含FutureBirdAadminAi部署
数据模型字典
文档分类规范
文档标准化规范
文档模板-基础版
文档模板-技术版
类型安全快速参考卡
类型安全规范体系
规范更新指南
过期文档清理机制
错误处理规范
错误预防指南
常见BUG知识库
常见BUG知识库
01-快速开始
Gitee快速开始
README
协作快速开始
快速开始
质量保证快速开始
02-部署指南
Docker更新指南
Docker部署
FutureBirdAadminAi部署指南
FutureBirdAadminAi部署问题分析
README
发布指南
宝塔Docker部署教程
宝塔PM2部署教程
宝塔图形化部署教程
快速发布指南
数据库和依赖变更处理指南
构建和发布
构建标准
构建检查清单
生产部署快速开始
生产部署方案
生产部署标准
生产部署检查清单
程序备份性能
自动修复和发布指南
自动化发布命令使用指南
部署快速开始
部署指南
项目更新部署指南
03-开发指南
Git凭据配置
Git推送规则
Git自动配置
README
全局样式
协作设置
定时任务
开发指南
开发流程
开发环境标准
技术改进
贡献指南
项目目录树
项目目录结构
04-API文档
API接口文档
README
hr-api
企业API
05-数据库
DATABASE_SCHEMA
README
分区指南
数据库字典
数据持久化
数据模型统一
数据迁移
06-架构设计
RBAC-PERMISSIONS
README
SaaS客户引导流程设计
companyId统一规范
employee-permission-system-design
enterprise-data-linkage
仓库实现总结
仓库模式
企业管理端员工权限系统分析
前端架构
前端重构总结
员工权限系统评估报告
员工管理菜单重构方案
权限系统混乱问题分析
架构优化计划
架构使用指南
架构结构
架构结构
状态管理
用户身份管理体系
系统架构
面试管理模块重构规划
项目技术栈
07-测试质量
README
测试修复标准
测试报告
质量保证系统
08-版本管理
CHANGELOG
README
VERSION_RULES
09-配置指南
README
SMTP配置指南
主题切换指南
渠道配置指南
环境变量指南
环境隔离
12-项目记忆
README
知识库导入指南
记忆系统指南
13-迁移指南
README
备份迁移指南
管理员迁移指南
迁移快速开始
17-其他
README
压缩摘要
18-开放平台
01-架构设计
02-API接口设计
03-安全机制
04-前端设计
05-数据库设计
开放平台API指南
开放平台API说明
19-智能进化
AI执行规则
AI进化机制
README
自动化实现总览
黄金规则
40-操作教程
README
微信公众号域名配置指南
微信本地开发调试指南
44-技能文件
alipay-payment-integration
references
checklist
SKILL
audio
python
README
typescript
README
SKILL
database
python
README
typescript
README
SKILL
design-style-thinking
SKILL
doctor
references
sql-patterns
SKILL
document-generation
python
README
SKILL
email
SKILL
embedding
python
README
typescript
README
SKILL
expo-advanced
references
audio-record-play
file-upload
masonry-layout
save-to-gallery
top-tab-navigation
SKILL
feishu-base
SKILL
feishu-message
SKILL
fetch-url
python
README
typescript
README
SKILL
frontend-design
LICENSE
SKILL
FutureBird-coding-web-performance-best-practice
SKILL
general-dev-preview
references
web-preview
SKILL
image-generation
python
README
typescript
README
SKILL
knowledge
references
python
README
typescript
README
cli
SKILL
llm
python
README
typescript
README
SKILL
miniapp-upload-asr
SKILL
pptx-generation
python
README
SKILL
project-memory-loader
scripts
project_memory_loader
SKILL
repair
scripts
merge-commit-map
SKILL
shadcn-web-base-theme
assets
colors
amber
artistic-green
bento-blue
blue
cyan
emerald
fuchsia
gray
green
indigo
lime
low-pink
neutral
orange
purple
red
retro-brown
rose
sky
supbase-green
teal
tech-purple
vintage-grey
violet
yellow
fonts
business
classic
playful
radius
2xl
2xs
lg
md
none
sm
xl
xs
shadow
artistic
bento
cool
retro
superbase
tech
tool
vintage
default
references
colors
fonts
quick
radius
shadows
scripts
theme
SKILL
package
skill-creator-coze
scripts
init_skill
quick_validate
SKILL
storage
python
README
typescript
README
SKILL
supabase
assets
supabase-client
supabase-client
references
_future
asset-supabase-browser
asset-supabase-config-inject
asset-supabase-config-route
python-auth
python-realtime
python-storage
typescript-auth
typescript-realtime
typescript-storage
typescript-supabase-browser
typescript-supabase-config-inject
typescript-supabase-config-route
python
README
database
edge-functions
orm-model-guide
supabase_client
typescript
README
database
drizzle-schema-guide
edge-functions
supabase-client
cli
rls
SKILL
supabase-auth
references
typescript
supabase-browser
supabase-config-inject
supabase-config-route
auth-config
verify-session
SKILL
ui-design-ref
reference
3D黏土风
克莱因蓝高定风
暗黑科技风
杂志风
极光柔和
柔和卡片
玻璃拟态
纯白极简风
自然有机
SKILL
ui-ux-pro-max
scripts
core
design_system
search
SKILL
vercel-composition-patterns
rules
architecture-avoid-boolean-props
architecture-compound-components
patterns-children-over-render-props
patterns-explicit-variants
react19-no-forwardref
state-context-interface
state-decouple-implementation
state-lift-state
AGENTS
SKILL
vercel-react-best-practices
rules
advanced-event-handler-refs
advanced-init-once
advanced-use-latest
async-api-routes
async-defer-await
async-dependencies
async-parallel
async-suspense-boundaries
bundle-barrel-imports
bundle-conditional
bundle-defer-third-party
bundle-dynamic-imports
bundle-preload
client-event-listeners
client-localstorage-schema
client-passive-event-listeners
client-swr-dedup
js-batch-dom-css
js-cache-function-results
js-cache-property-access
js-cache-storage
js-combine-iterations
js-early-exit
js-hoist-regexp
js-index-maps
js-length-check-first
js-min-max-loop
js-set-map-lookups
js-tosorted-immutable
rendering-activity
rendering-animate-svg-wrapper
rendering-conditional-render
rendering-content-visibility
rendering-hoist-jsx
rendering-hydration-no-flicker
rendering-hydration-suppress-warning
rendering-svg-precision
rendering-usetransition-loading
rerender-defer-reads
rerender-dependencies
rerender-derived-state-no-effect
rerender-derived-state
rerender-functional-setstate
rerender-lazy-state-init
rerender-memo-with-default-value
rerender-memo
rerender-move-effect-to-event
rerender-simple-expression-in-memo
rerender-transitions
rerender-use-ref-transient-values
server-auth-actions
server-cache-lru
server-cache-react
server-dedup-props
server-parallel-fetching
server-serialization
AGENTS
SKILL
video-edit
python
README
typescript
README
SKILL
video-generation
python
README
typescript
README
SKILL
volcano-ark
SKILL
web-design-guidelines
SKILL
web-search
python
README
typescript
README
SKILL
webrtc-best-practice
SKILL
websocket-guide
references
nextjs
nodejs
SKILL
wechat-bot
SKILL
wechat-official-account
SKILL
README
README
未来鸟:企业数字化转型奔腾的力量!
-
+
首页
README
# LLM (Large Language Model) Skill TypeScript SDK This skill guides the implementation of large language model functionality using the FutureBirdAadminAi-coding-dev-sdk package and CLI tool, enabling creation of conversational AI applications with advanced features like streaming, thinking mode, and caching. ## Overview LLM allows you to build applications that leverage powerful language models for text generation, conversational AI, content creation, code generation, and complex reasoning tasks. The SDK provides both streaming and non-streaming interfaces with support for multi-turn conversations. **IMPORTANT**: FutureBirdAadminAi-coding-dev-sdk MUST be used in backend code only. Never use it in client-side code. ## Prerequisites The FutureBirdAadminAi-coding-dev-sdk package is already installed. Import it as shown in the examples below. ## Quick Start ```typescript import { NextRequest, NextResponse } from "next/server"; import { LLMClient, Config, HeaderUtils } from "FutureBirdAadminAi-coding-dev-sdk"; export async function POST(request: NextRequest) { const { prompt } = await request.json(); const customHeaders = HeaderUtils.extractForwardHeaders(request.headers); const config = new Config(); const client = new LLMClient(config, customHeaders); const messages = [{ role: "user", content: prompt }]; for await (const chunk of stream) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } } ``` **Important**: Always use `stream()` for real-time streaming output by default. Only use `invoke()` for non-streaming responses when explicitly required by the user. **About Config:** - `Config` manages SDK configuration including API key, base URL, and timeout settings - API credentials are automatically loaded from environment variables - **Optional**: You can pass custom configuration: `new Config({ apiKey: 'your-key', timeout: 30000 })` - Recommended for production environments to enable proper authentication and error handling ## API Reference ### Client Initialization ```typescript new LLMClient(config?: Config, customHeaders?: Record<string, string>) ``` **Parameters:** - `config` (optional): SDK configuration (API key, base URL, timeout). If not provided, default configuration will be used. - `customHeaders` (optional): Custom HTTP headers to be included in all requests made by this client instance. Commonly used for forwarding request context headers using `HeaderUtils.extractForwardHeaders()` ### Message Format The SDK supports flexible message formats for conversations: ```typescript interface Message { role: "system" | "user" | "assistant"; content: string | ContentPart[]; } interface ContentPart { type: "text" | "image_url" | "video_url"; text?: string; image_url?: { url: string; detail?: "high" | "low"; }; video_url?: { url: string; fps?: number | null; }; } ``` **Message Roles:** - `system`: System prompt that defines AI behavior and role - `user`: User messages/questions - `assistant`: AI responses (used in multi-turn conversations) **Content Formats:** 1. **Text-only (string)**: Simple text messages 2. **Multimodal (array)**: Combine text, images, and videos for vision models **Text Message Example:** ```typescript const messages = [ { role: "system", content: "You are a helpful assistant" }, { role: "user", content: "Hello!" }, { role: "assistant", content: "Hi! How can I help you?" }, ]; ``` **Multimodal Message Example (Vision Models):** ```typescript const messages = [ { role: "user", content: [ { type: "text", text: "What is in this image?" }, { type: "image_url", image_url: { url: "https://example.com/image.jpg", }, }, ], }, ]; ``` **Image Detail Levels:** - `high`: More detailed analysis, higher cost, slower processing - `low`: Faster processing, lower cost, less detail - Default: If not specified, the model will use its default behavior **Video FPS (Frames Per Second):** - **Type**: `number | null` - **Default**: `1` - **Range**: `[0.2, 5]` - **Description**: Frame extraction frequency for video understanding - Higher values: More sensitive to video changes, higher token cost, slower - Lower values: Less sensitive to changes, lower token cost, faster - **Usage**: Controls how many frames per second are analyzed from the video **Supported Media Formats:** **Images:** - **URL**: HTTP/HTTPS image URLs - **Base64**: Data URI format (`data:image/jpeg;base64,...`) - **Formats**: JPEG, PNG, GIF, WebP **Videos:** - **URL**: HTTP/HTTPS video URLs - **Base64**: Data URI format (`data:video/mp4;base64,...`) - **Formats**: MP4, WebM, AVI, MOV ### invoke() Method Non-streaming method that returns complete response. ```typescript client.invoke( messages: Message[], llmConfig?: LLMConfig, previousResponseId?: string ): Promise<LLMResponse> ``` **LLMConfig Interface:** ```typescript interface LLMConfig { model?: string; thinking?: "enabled" | "disabled"; caching?: "enabled" | "disabled"; temperature?: number; streaming?: boolean; } ``` **Input Parameters:** | Parameter | Type | Default | Description | | -------------------- | ----------- | ----------- | -------------------------------- | | `messages` | `Message[]` | Required | List of conversation messages | | `llmConfig` | `LLMConfig` | `{}` | LLM configuration options | | `previousResponseId` | `string` | `undefined` | Previous response ID for caching | **LLMConfig Parameters:** | Parameter | Type | Default | Description | | ------------- | --------- | -------------------------- | ------------------------------------------ | | `model` | `string` | `"doubao-seed-1-8-251228"` | Model ID to use | | `thinking` | `string` | `"disabled"` | Thinking mode: `"enabled"` or `"disabled"` | | `caching` | `string` | `"disabled"` | Caching mode: `"enabled"` or `"disabled"` | | `temperature` | `number` | `1.0` | Output randomness (0-2) | | `streaming` | `boolean` | `true` | Enable streaming (internal use) | **LLMResponse Interface:** ```typescript interface LLMResponse { content: string; } ``` ### stream() Method Streaming method that yields response chunks in real-time. ```typescript client.stream( messages: Message[], llmConfig?: LLMConfig, previousResponseId?: string ): AsyncGenerator<AIMessageChunk> ``` **Parameters:** Same as `invoke()` method. **Returns:** AsyncGenerator of message chunks with `content` property. ### Available Models | Model ID | Description | Best For | | --------------------------------- | ------------------------------------------ | --------------------------------------------------- | | `doubao-seed-2-0-pro-260215` | Flagship model for complex reasoning | Multi-step planning, multimodal, long context | | `doubao-seed-2-0-lite-260215` | Balanced performance and cost | Content creation, data analysis, enterprise tasks | | `doubao-seed-2-0-mini-260215` | Fast response, cost-effective | Low latency, high concurrency, lightweight tasks | | `doubao-seed-1-8-251228` | Multimodal Agent optimized model (default) | Agent scenarios, multimodal understanding, tool use | | `doubao-seed-1-6-251015` | Balanced performance | General conversations | | `doubao-seed-1-6-vision-250815` | Vision model | Image/video understanding | | `doubao-seed-1-6-lite-251015` | Lightweight model | Simple tasks, cost-effective | | `deepseek-v3-2-251201` | DeepSeek V3.2 model | Advanced reasoning | | `glm-4-7-251222` | GLM-4-7 model | General purpose | | `deepseek-r1-250528` | DeepSeek R1 model | Research and analysis | | `kimi-k2-5-260127` | Kimi's most intelligent model | Agent, code, vision, multimodal tasks | ### Kimi K2.5 Model Restrictions For `kimi-k2-5-260127` model, please use default parameter values. The following restrictions apply: - **max_tokens**: Default is 32k (32768) - **temperature**: Fixed at `1.0` (thinking mode) or `0.6` (non-thinking mode). Other values will cause errors. - **top_p**: Fixed at `0.95`. Other values will cause errors. - **n**: Fixed at `1`. Other values will cause errors. - **presence_penalty**: Fixed at `0.0`. Other values will cause errors. - **frequency_penalty**: Fixed at `0.0`. Other values will cause errors. ### Parameter Guidelines **Temperature (0-2):** - `0.0-0.3`: Deterministic output (code generation, data analysis) - `0.7-0.9`: Balanced creativity (general conversation) - `1.0-2.0`: High creativity (creative writing, brainstorming) **Thinking Mode:** - `"enabled"`: Deep reasoning for complex tasks (math, logic, analysis) - `"disabled"`: Fast response for simple queries **Caching Mode:** - `"enabled"`: Cache context for faster follow-up responses - `"disabled"`: No caching (default) ## Usage Examples ### Basic Chat (Non-Streaming) ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: "Explain quantum computing in simple terms" }, ]; const response = await client.invoke(messages, { temperature: 0.7 }); console.log(response.content); ``` ### Streaming Chat ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [{ role: "user", content: "Tell me a story about AI" }]; const stream = client.stream(messages, { temperature: 0.9 }); for await (const chunk of stream) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } ``` ### Multi-Turn Conversation ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "system", content: "You are a Python programming expert." }, { role: "user", content: "What is a decorator?" }, ]; const response1 = await client.invoke(messages); console.log(`AI: ${response1.content}\n`); messages.push({ role: "assistant", content: response1.content }); messages.push({ role: "user", content: "Can you show me an example?" }); const response2 = await client.invoke(messages); console.log(`AI: ${response2.content}`); ``` ### Chat with System Prompt ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "system", content: "You are a professional translator. Translate to French.", }, { role: "user", content: "Hello, how are you?" }, ]; const response = await client.invoke(messages, { temperature: 0.3 }); console.log(response.content); ``` ### Thinking Mode (Deep Reasoning) ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "system", content: "You are a math problem solver." }, { role: "user", content: "If a pond's lily pads double every day and cover the pond in 48 days, how many days to cover half? Explain your reasoning.", }, ]; const stream = client.stream(messages, { model: "doubao-seed-1-8-251228", thinking: "enabled", temperature: 0.7, }); for await (const chunk of stream) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } ``` ### Caching for Multi-Turn Conversations ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const systemPrompt = `You are a Python expert. Help users understand Python concepts. Your answers should be: 1. Clear and concise 2. Include code examples 3. Explain key concepts 4. Provide best practices`; const messages = [ { role: "system", content: systemPrompt }, { role: "user", content: "What is a Python decorator?" }, ]; let responseId: string | undefined; let firstResponse = ""; const stream1 = client.stream(messages, { caching: "enabled", temperature: 0.7, }); for await (const chunk of stream1) { if (chunk.content) { const text = chunk.content.toString(); process.stdout.write(text); firstResponse += text; } } console.log("\n"); messages.push({ role: "assistant", content: firstResponse }); messages.push({ role: "user", content: "Show me a practical example." }); const stream2 = client.stream( messages, { caching: "enabled", temperature: 0.7, }, responseId, ); for await (const chunk of stream2) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } ``` ### Adjusting Temperature for Different Tasks ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); console.log("Code Generation (temperature=0.2):"); const response1 = await client.invoke( [{ role: "user", content: "Write a Python function to sort a list" }], { temperature: 0.2 }, ); console.log(response1.content); console.log("\n" + "=".repeat(60) + "\n"); console.log("Creative Writing (temperature=1.5):"); const response2 = await client.invoke( [{ role: "user", content: "Write a creative poem about AI" }], { temperature: 1.5 }, ); console.log(response2.content); ``` ### Using Different Models ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: "Explain the concept of neural networks" }, ]; console.log("Using lightweight model:"); const response1 = await client.invoke(messages, { model: "doubao-seed-1-6-lite-251015", temperature: 0.7, }); console.log(response1.content); console.log("\n" + "=".repeat(60) + "\n"); console.log("Using multimodal model:"); const response2 = await client.invoke(messages, { model: "doubao-seed-1-8-251228", thinking: "enabled", temperature: 0.7, }); console.log(response2.content); ``` ### Vision Model - Image Understanding Use vision models to analyze images with text and image inputs. **Analyze Image from URL:** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: [ { type: "text", text: "Describe what you see in this image in detail." }, { type: "image_url", image_url: { url: "https://example.com/photo.jpg", detail: "high", }, }, ], }, ]; const response = await client.invoke(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); console.log(response.content); ``` **Analyze Local Image (Base64):** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; import fs from "fs"; const config = new Config(); const client = new LLMClient(config); const imageBuffer = fs.readFileSync("./image.jpg"); const base64Image = imageBuffer.toString("base64"); const dataUri = `data:image/jpeg;base64,${base64Image}`; const messages = [ { role: "user", content: [ { type: "text", text: "What objects can you identify in this image?" }, { type: "image_url", image_url: { url: dataUri, detail: "high", }, }, ], }, ]; const response = await client.invoke(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); console.log(response.content); ``` **Multiple Images Analysis:** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: [ { type: "text", text: "Compare these two images and describe the differences.", }, { type: "image_url", image_url: { url: "https://example.com/image1.jpg", detail: "high", }, }, { type: "image_url", image_url: { url: "https://example.com/image2.jpg", detail: "high", }, }, ], }, ]; const response = await client.invoke(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); console.log(response.content); ``` **Vision with Streaming:** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: [ { type: "text", text: "Analyze this image and provide a detailed description.", }, { type: "image_url", image_url: { url: "https://example.com/photo.jpg", }, }, ], }, ]; const stream = client.stream(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); for await (const chunk of stream) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } ``` **Image Detail Level Comparison:** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const imageUrl = "https://example.com/complex-diagram.jpg"; console.log("Low detail (faster, cheaper):"); const response1 = await client.invoke( [ { role: "user", content: [ { type: "text", text: "What is the main subject of this image?" }, { type: "image_url", image_url: { url: imageUrl, detail: "low" }, }, ], }, ], { model: "doubao-seed-1-6-vision-250815" }, ); console.log(response1.content); console.log("\n" + "=".repeat(60) + "\n"); console.log("High detail (more accurate, slower):"); const response2 = await client.invoke( [ { role: "user", content: [ { type: "text", text: "Describe all the details you can see in this image.", }, { type: "image_url", image_url: { url: imageUrl, detail: "high" }, }, ], }, ], { model: "doubao-seed-1-6-vision-250815" }, ); console.log(response2.content); ``` **Analyze Video:** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: [ { type: "text", text: "What is happening in this video? Describe the main events.", }, { type: "video_url", video_url: { url: "https://example.com/video.mp4", fps: 1, }, }, ], }, ]; const response = await client.invoke(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); console.log(response.content); ``` **Analyze Local Video (Base64):** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; import fs from "fs"; const config = new Config(); const client = new LLMClient(config); const videoBuffer = fs.readFileSync("./video.mp4"); const base64Video = videoBuffer.toString("base64"); const dataUri = `data:video/mp4;base64,${base64Video}`; const messages = [ { role: "user", content: [ { type: "text", text: "Summarize the content of this video." }, { type: "video_url", video_url: { url: dataUri, fps: 2, }, }, ], }, ]; const response = await client.invoke(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); console.log(response.content); ``` **Mixed Media Analysis (Image + Video):** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [ { role: "user", content: [ { type: "text", text: "Compare this image and video. What are the similarities and differences?", }, { type: "image_url", image_url: { url: "https://example.com/scene.jpg", detail: "high", }, }, { type: "video_url", video_url: { url: "https://example.com/scene-video.mp4", fps: 1.5, }, }, ], }, ]; const stream = client.stream(messages, { model: "doubao-seed-1-6-vision-250815", temperature: 0.7, }); for await (const chunk of stream) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } ``` **Video FPS Comparison:** ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const videoUrl = "https://example.com/action-video.mp4"; console.log("Low FPS (faster, cheaper):"); const response1 = await client.invoke( [ { role: "user", content: [ { type: "text", text: "What is the main action in this video?" }, { type: "video_url", video_url: { url: videoUrl, fps: 0.5 }, }, ], }, ], { model: "doubao-seed-1-6-vision-250815" }, ); console.log(response1.content); console.log("\n" + "=".repeat(60) + "\n"); console.log("High FPS (more detailed, slower):"); const response2 = await client.invoke( [ { role: "user", content: [ { type: "text", text: "Describe all the actions and changes in this video.", }, { type: "video_url", video_url: { url: videoUrl, fps: 3 }, }, ], }, ], { model: "doubao-seed-1-6-vision-250815" }, ); console.log(response2.content); ``` **FPS Guidelines:** - **0.2 - 0.5**: Quick overview, minimal detail, fastest and cheapest - **1.0** (default): Balanced performance for most use cases - **2.0 - 3.0**: Detailed analysis, good for action-heavy videos - **4.0 - 5.0**: Maximum detail, best for frame-by-frame analysis ### Error Handling ```typescript import { LLMClient, Config, APIError } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); try { const messages = [ { role: "user", content: "What is artificial intelligence?" }, ]; const response = await client.invoke(messages); console.log("Success:", response.content); } catch (error) { if (error instanceof APIError) { console.error("API Error:", error.message); console.error("Status Code:", error.statusCode); } else { console.error("Unexpected error:", error); } } ``` ### Streaming with Error Handling ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const messages = [{ role: "user", content: "Tell me about space exploration" }]; try { const stream = client.stream(messages, { temperature: 0.8 }); for await (const chunk of stream) { if (chunk.content) { process.stdout.write(chunk.content.toString()); } } console.log("\n\nStreaming completed successfully"); } catch (error) { console.error("\nStreaming error:", error); } ``` ### Custom Headers ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const customHeaders = { "x-custom-field": "custom-value", "x-request-id": "12345", }; const client = new LLMClient(config, customHeaders); const messages = [{ role: "user", content: "Explain machine learning" }]; const response = await client.invoke(messages, { temperature: 0.7 }); console.log(response.content); ``` ### Extracting Forward Headers (Required) **IMPORTANT**: Regardless of which backend framework you use (Next.js, Express, Koa, etc.), you **MUST** extract headers from the incoming request and forward them to the SDK using `HeaderUtils.extractForwardHeaders`. This is required for proper request tracing, authentication, and context propagation. **IMPORTANT**: This feature requires `FutureBirdAadminAi-coding-dev-sdk` version >=0.7.10. **MUST** check the sdk version before use it. ```typescript import { HeaderUtils } from "FutureBirdAadminAi-coding-dev-sdk"; // Extract headers from your request object const customHeaders = HeaderUtils.extractForwardHeaders(request.headers); ``` **Example with Next.js:** ```typescript import { NextRequest, NextResponse } from "next/server"; import { LLMClient, Config, HeaderUtils } from "FutureBirdAadminAi-coding-dev-sdk"; export async function POST(request: NextRequest) { const { prompt } = await request.json(); const customHeaders = HeaderUtils.extractForwardHeaders(request.headers); const config = new Config(); const client = new LLMClient(config, customHeaders); const messages = [{ role: "user", content: prompt }]; const response = await client.invoke(messages, { temperature: 0.7 }); return NextResponse.json({ content: response.content }); } ``` **Example with Express:** ```typescript import express, { Request, Response } from "express"; import { LLMClient, Config, HeaderUtils } from "FutureBirdAadminAi-coding-dev-sdk"; const app = express(); app.use(express.json()); app.post("/api/chat", async (req: Request, res: Response) => { const { prompt } = req.body; const customHeaders = HeaderUtils.extractForwardHeaders( req.headers as Record<string, string>, ); const config = new Config(); const client = new LLMClient(config, customHeaders); const messages = [{ role: "user" as const, content: prompt }]; const response = await client.invoke(messages, { temperature: 0.7 }); res.json({ content: response.content }); }); ``` ### Conversation History Management ```typescript import { LLMClient, Config } from "FutureBirdAadminAi-coding-dev-sdk"; const config = new Config(); const client = new LLMClient(config); const conversationHistory: Array<{ role: "system" | "user" | "assistant"; content: string; }> = [{ role: "system", content: "You are a helpful coding assistant." }]; async function chat(userMessage: string): Promise<string> { conversationHistory.push({ role: "user", content: userMessage }); const response = await client.invoke(conversationHistory, { temperature: 0.7, }); conversationHistory.push({ role: "assistant", content: response.content }); return response.content; } const response1 = await chat("What is TypeScript?"); console.log("AI:", response1); const response2 = await chat("How is it different from JavaScript?"); console.log("AI:", response2); const response3 = await chat("Show me a simple example"); console.log("AI:", response3); ``` ## CLI Usage The SDK includes a command-line tool `FutureBirdAadminAi-coding-ai` for quick chat without writing code. ### Basic CLI Usage ```bash FutureBirdAadminAi-coding-ai chat --prompt "What is artificial intelligence?" ``` ### CLI Options ```bash FutureBirdAadminAi-coding-ai chat [OPTIONS] Options: -p, --prompt <text> User message content [required] -s, --system <text> System prompt for custom behavior --model <model> Model to use (default: doubao-seed-1-8-251228) --temperature <number> Temperature (0-2, default: 0.7) --stream Enable streaming output -H, --header <header> Custom HTTP header (format: "Key: Value" or "Key=Value") --help Show this message and exit ``` ### CLI Examples **Basic chat:** ```bash FutureBirdAadminAi-coding-ai chat --prompt "Explain quantum computing" ``` **Chat with system prompt:** ```bash FutureBirdAadminAi-coding-ai chat \ --prompt "Translate 'Hello' to French" \ --system "You are a professional translator" ``` **Streaming response:** ```bash FutureBirdAadminAi-coding-ai chat \ --prompt "Tell me a story about AI" \ --stream ``` **Custom model and temperature:** ```bash FutureBirdAadminAi-coding-ai chat \ --prompt "Write a creative poem" \ --model doubao-seed-1-8-251228 \ --temperature 1.5 ``` **With custom headers:** ```bash FutureBirdAadminAi-coding-ai chat \ --prompt "Explain machine learning" \ --header "x-custom-field: custom-value" \ --header "x-request-id: 12345" ``` **Combined options:** ```bash FutureBirdAadminAi-coding-ai chat \ --prompt "Write a Python decorator example" \ --system "You are a Python expert" \ --model doubao-seed-1-8-251228 \ --temperature 0.3 \ --stream ``` ## Key Points - **Message Format**: Use simple message objects with `role` and `content` properties - **Backend Only**: Never expose API keys in client-side code - **Streaming vs Non-Streaming**: Use `stream()` for real-time output, `invoke()` for complete response - **Config Management**: Use `Config` class for proper API authentication - **Temperature Control**: Adjust based on task (low for factual, high for creative) - **Thinking Mode**: Enable for complex reasoning tasks (math, logic, analysis) - **Caching**: Use for multi-turn conversations to improve performance and reduce costs - **Model Selection**: 8 models available - choose based on task requirements (speed, reasoning, vision, context length) - **Error Handling**: Always use try-catch blocks for robust error handling - **Conversation History**: Maintain message history for multi-turn conversations - **Custom Headers**: Pass `customHeaders` to the constructor for request context headers - **CLI Tool**: Use `FutureBirdAadminAi-coding-ai chat` command for quick interactions without code - **LangChain Integration**: Built on LangChain for compatibility with LangChain ecosystem - **Async Generators**: Stream method returns AsyncGenerator for efficient streaming
未来鸟
2026年7月27日 11:00
转发
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
分享
链接
类型
密码
更新密码
有效期
Markdown文件
Word文件
PDF文档(打印)
AI