惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
D
Docker
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
罗磊的独立博客
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
博客园 - 司徒正美
T
Tailwind CSS Blog
C
Check Point Blog
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
L
LangChain Blog
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
腾讯CDC
Last Week in AI
Last Week in AI
Jina AI
Jina AI
博客园 - Franky
量子位

卡卡罗特

流行的Agent代码编辑器 eino实现Agent eino整合RAG eino整合Tools go整合向量数据库ChromaDB langchainjs langchain实现Agent ollama调用各大模型 spring-ai 自定义一个MCP openCV初体验 01-Bing每日一图接口 02-腾讯API高清QQ头像https调用接口 01-获取指定网站的所有的链接 context.Context是什么? RWMutex读写锁 SyncMap的使用 defer的使用 go字符串工具类 go生成UUID go正则表达式 最后代码 | 卡卡罗特 swagger文档 | 卡卡罗特 react脚手架开发 | 卡卡罗特 python的对象增强 | 卡卡罗特 langchain实现Agent | 卡卡罗特 03.python列表集合元组字典 | 卡卡罗特 python依赖打包 | 卡卡罗特 python的异步 | 卡卡罗特 python的生成器 | 卡卡罗特
langchainjs | 卡卡罗特
2026-04-28 · via 卡卡罗特

github:https://github.com/langchain-ai/langchainjs

js调用ollama ​

所需要的依赖

json

{
    "@langchain/community": "^0.3.31",
    "@langchain/core": "^0.3.40",
    "express": "^4.21.2",
    "axios": "^1.7.9"
}

测试代码 test.js

js

// ----------------------------
// 文件:app.js
// 运行:node app.js
// 访问:POST http://localhost:3000/ask 发送 JSON { "question": "你的问题" }
// ----------------------------
import express from 'express';

import { Ollama } from '@langchain/community/llms/ollama';

// 1. 初始化 Express 和模型
const app = express();
app.use(express.json()); // 允许解析 JSON 请求体

// 连接本地 Ollama 模型(确保服务已启动)
const localModel = new Ollama({
    baseUrl: 'http://127.0.0.1:11434', // Ollama 默认端口
    model: 'deepseek-r1:latest', // 替换为你的模型名称(如 'qwen:7b')
});

// 2. 创建问答接口
app.get('/ask', async (req, res) => {
    try {
        const { question } = req.query;
        // 直接调用模型生成答案
        const answer = await localModel.invoke(question);

        res.json({
            success: true,
            question,
            answer
        });
    } catch (error) {
        res.status(500).json({
            success: false,
            error: error.message
        });
    }
});
// app.post('/ask', async (req, res) => {
//     try {
//         const { question } = req.body;
//         // 直接调用模型生成答案
//         const answer = await localModel.invoke(question);
//
//         res.json({
//             success: true,
//             question,
//             answer
//         });
//     } catch (error) {
//         res.status(500).json({
//             success: false,
//             error: error.message
//         });
//     }
// });

// 3. 启动服务
app.listen(3000, () => {
    console.log('服务已启动:http://localhost:3000');
});