当前位置: 首页 > news >正文

langchain4j+local-ai小试牛刀

本文主要研究一下如何本地运行local-ai并通过langchain4j集成调用。

步骤

curl安装

curl https://localai.io/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21509    0 21509    0     0  45959      0 --:--:-- --:--:-- --:--:-- 45861
  Downloading local-ai...
######################################################################## 100.0%
  Installing local-ai to /usr/local/bin...
  Creating local-ai user...
  Adding current user to local-ai group...
  Creating local-ai systemd service...
  The LocalAI API is now available at 127.0.0.1:8080.
  Install complete. Run "local-ai" from the command line.
[WARN]  No NVIDIA/AMD GPU detected. LocalAI will run in CPU-only mode.

运行

local-ai
9:49AM INF env file found, loading environment variables from file envFile=/etc/localai.env
9:49AM INF Setting logging to info
9:49AM INF Starting LocalAI using 16 threads, with models path: /usr/share/local-ai/models
9:49AM INF LocalAI version: v2.26.0 (09941c0bfb9119bb01a04b2a0a16897ecf2cd087)
9:49AM INF Preloading models from /usr/share/local-ai/models
9:49AM INF core/startup process completed!
9:49AM INF LocalAI API is listening! Please connect to the endpoint for API documentation. endpoint=http://0.0.0.0:8080

访问http://localhost:8080
在这里插入图片描述

安装model

访问http://localhost:8080/browse 浏览模型并选择安装
或者使用命令行,这里选择一个小模型

local-ai models install llama-3.2-1b-instruct:q4_k_m

https://hf-mirror.com/hugging-quants/Llama-3.2-1B-Instruct-Q4_K_M-GGUF

pom.xml

        <dependency>
            <groupId>dev.langchain4j</groupId>
            <artifactId>langchain4j-local-ai</artifactId>
            <version>1.0.0-beta1</version>
        </dependency>

controller

@RequestMapping("/local-ai")
@RestController
@Slf4j
public class LocalAiController {

    ChatLanguageModel model = LocalAiChatModel.builder()
            .baseUrl("http://localhost:8080/v1")
            .modelName("llama-3.2-1b-instruct:q4_k_m")
//            .maxTokens(3)
            .logRequests(true)
            .logResponses(true)
            .build();

    /**
     * curl -i http://localhost:8080/local-ai/chat?prompt=who are you
     * @param prompt
     * @return
     */
    @GetMapping("/chat")
    public String chat(@RequestParam("prompt") String prompt) {
        return model.chat(prompt);
    }

}

请求

http://localhost:8080/local-ai/chat?prompt=who%20are%20you
返回

I'm an AI assistant, which means I'm a computer program designed to understand and respond to human language. I'm here to help with a wide range of topics, answer questions, provide information, and even chat with you in a friendly and helpful way. I'm a large language model, which means I've been trained on a massive database of text from the internet, books, and other sources, which allows me to generate responses that are often surprisingly accurate and insightful. Some common ways I can assist you include: * Answering questions on a particular topic * Providing definitions and explanations * Offering suggestions and ideas * Summarizing long pieces of text * Translating languages (I can translate text from one language to another) * Offering writing and proofreading services * Generating text on a given topic or topic I'm always learning and improving, so please bear with me if I make any mistakes or don't quite understand the question. I'm here to help, so feel free to ask me anything that's on your mind!

小结

LocalAI是OpenAI 的免费开源替代产品,提供了与 OpenAI 兼容的直接替代 REST API,可以在本地直接运行大语言模型LLM、生成图像、音频等。它提供了docker安装及脚本安装。langchain4j提供了langchain4j-local-ai用于集成local-ai.

doc

  • langchain4j local-ai
  • localai.io

相关文章:

  • 辛格迪客户案例 | 鼎康生物电子合约系统(eSign)项目
  • 基于Kerberos认证对接华为云Elasticsearch
  • 【时序预测】在线学习:算法选择(从线性模型到深度学习解析)
  • (南京观海微电子)——倍压设计与应用
  • Python----数据分析(Numpy:安装,数组创建,切片和索引,数组的属性,数据类型,数组形状,数组的运算,基本函数)
  • 【大模型】fp32 和 fp16 的区别,混合精度的原理。
  • 中科大计算机网络原理 1.5 Internt结构和ISP
  • OSI七层模型:从入门到精通的全面解析
  • ES from size聚合查询10000聚合查询,是每个分片先聚合,再统计。还是所有节点查询1万条后,再聚合
  • Linux服务器防火墙白名单访问策略的配置示例
  • 电子电气架构 --- 汽车行业技术变革
  • 2023-Moectf-wp
  • EtherCAT总线学习笔记
  • 【Python】基础语法三
  • 微服务学习(2):实现SpringAMQP对RabbitMQ的消息收发
  • 普通人高效使用DeepSeek指南?
  • 复现NC图表:二分图 (bipartite plot) 网络绘制(三种方法)-应用于细胞互作受配体展示-调控网络展示等等
  • Windows安装sql server2017
  • GitCode 助力 JeeSite:开启企业级快速开发新篇章
  • week 3 - More on Collections - Lecture 3
  • 中国安能建设总公司网站/青岛seo优化
  • 长沙做网站团队/广州百度seo代理
  • 建设家具网站/百度文库个人登录入口
  • 中国建设手机银行网站/广州网站优化外包
  • 色情网站是怎么建设的/seo关键词排名在线查询
  • 杭州滨江区疫情最新消息/seo电商运营是什么意思