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

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
AWS News Blog
AWS News Blog
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
Attack and Defense Labs
Attack and Defense Labs
Jina AI
Jina AI
The Last Watchdog
The Last Watchdog
W
WeLiveSecurity
H
Help Net Security
V
Visual Studio Blog
宝玉的分享
宝玉的分享
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
Latest news
Latest news
T
Tor Project blog
I
Intezer
美团技术团队
GbyAI
GbyAI
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
Y
Y Combinator Blog
博客园 - 司徒正美
T
Tenable Blog
O
OpenAI News
N
News and Events Feed by Topic
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threatpost
Google Online Security Blog
Google Online Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
Help Net Security
Help Net Security

卡卡罗特

最后代码 | 卡卡罗特 swagger文档 | 卡卡罗特 react脚手架开发 | 卡卡罗特 python的对象增强 | 卡卡罗特 langchain实现Agent | 卡卡罗特 03.python列表集合元组字典 | 卡卡罗特 python依赖打包 | 卡卡罗特 python的异步 | 卡卡罗特 python的生成器 | 卡卡罗特 eino整合Tools | 卡卡罗特 eino实现Agent | 卡卡罗特 eino整合RAG | 卡卡罗特 docker打包go服务 | 卡卡罗特 01-docker入门 | 卡卡罗特 docker-compose | 卡卡罗特 dockerfile | 卡卡罗特 linux安装docker | 卡卡罗特 hertz中间件 | 卡卡罗特 go整合向量数据库ChromaDB | 卡卡罗特 ollama调用各大模型 | 卡卡罗特 spring-ai | 卡卡罗特 自定义一个MCP | 卡卡罗特 context.Context是什么? | 卡卡罗特 01-获取指定网站的所有的链接 | 卡卡罗特 01-Bing每日一图接口 | 卡卡罗特 02-腾讯API高清QQ头像https调用接口 | 卡卡罗特 openCV初体验 | 卡卡罗特 go字符串工具类 | 卡卡罗特 RWMutex读写锁 | 卡卡罗特 SyncMap的使用 | 卡卡罗特 defer的使用 | 卡卡罗特
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');
});