这是一个基于模型上下文协议(Model Context Protocol)构建的项目,主要用于实现与Perplexity的集成。借助该项目,我们能够利用Perplexity强大的搜索引擎和大语言模型(LLM),为用户提供更智能、更高效的搜索增强问答功能。
npm install mcp-ts-template @perplexity/api
创建一个config.ts
文件,并添加以下内容:
export const config = {
api_key: 'your-perplexity-api-key',
search_context_size: 5,
// 其他自定义配置
};
运行命令:
npm run dev
项目的整体架构遵循清晰的分层原则:
┌──────────────┐
│ Client │
└──────┬───────┘
│
┌──────▼───────┐
│ Handler │
└──────┬───────┘
│
┌──────▼───────┐
│ Server │
└──────┬───────┘
│
┌──────▼───────┐
│ Services │
└──────┬───────┘
│
┌──────▼───────┐
│ Config │
└──────┬───────┘
│
┌──────▼───────┐
│ Database │
└──────────────┘
该工具通过Perplexity API执行搜索增强查询,主要用于回答基于网络搜索结果的问题。
参数名称 | 类型 | 是否必填 | 描述 |
---|---|---|---|
query |
string | 是 | 用户的原始搜索查询或问题 |
return_related_questions |
boolean | 否 | 设置为true 时,Perplexity模型会一并返回相关问题(默认值:false ) |
search_recency_filter |
string | 否 | 控制搜索结果的时间范围过滤器(例如:'hour' , 'day' , 'week' , 'month' , 'year' ) |
search_domain_filter |
string[] | 否 | 指定要过滤的域名列表 |
const result = await perplexity_search({
query: "什么是人工智能?",
return_related_questions: true,
search_recency_filter: 'week',
search_domain_filter: ['example.com']
});
src/
: 包含核心业务逻辑和模块。config/
: 存放应用程序的配置文件。types/
: 定义自定义类型和接口。src/components
目录下新建一个组件文件。npm run build
生成构建文件。本项目遵循MIT License,允许自由使用、修改和分发,但需保留版权声明。