LangChain手册(JS/TS版)01:设置和安装
LangChain is written in TypeScript and can be used in:LangChain 是用 TypeScript 编写的,可用于:
- Node.js (ESM and CommonJS) – 18.x, 19.x, 20.xNode.js (ESM 和 CommonJS) – 18.x, 19.x, 20.x
- Cloudflare Workers Cloudflare Workers
- Vercel / Next.js (Browser, Serverless and Edge functions)Vercel / Next.js(浏览器、无服务器和边缘功能)
- Supabase Edge Functions 超基边缘函数
- Browser
- Deno
If you want to get started quickly on using LangChain in Node.js, clone this repository and follow the README instructions for a boilerplate project with those dependencies set up.如果您想快速开始使用 Node.js中的 LangChain,请克隆此存储库并按照设置了这些依赖项的样板项目的自述文件说明进行操作。
If you prefer to set things up yourself, or you want to run LangChain in other environments, read on for instructions.如果您希望自己设置,或者想在其他环境中运行 LangChain,请继续阅读以获取说明。
To get started, install LangChain with the following command:要开始使用,请使用以下命令安装 LangChain:
- npm
npm install -S langchain
- Yarn
yarn add langchain
- pnpm
LangChain is written in TypeScript and provides type definitions for all of its public APIs.LangChain 是用 TypeScript 编写的,并为其所有公共 API 提供类型定义。
LangChain provides an ESM build targeting Node.js environments. You can import it using the following syntax:LangChain提供了一个针对Node.js环境的ESM构建。您可以使用以下语法导入它:
If you are using TypeScript in an ESM project we suggest updating your tsconfig.json to include the following:如果您在 ESM 项目中使用 TypeScript,我们建议您更新 tsconfig.json 以包含以下内容:
tsconfig.json
LangChain provides a CommonJS build targeting Node.js environments. You can import it using the following syntax:LangChain提供了一个针对Node.js环境的CommonJS构建。您可以使用以下语法导入它:
LangChain can be used in Cloudflare Workers. You can import it using the following syntax:LangChain 可用于 Cloudflare Workers。您可以使用以下语法导入它:
LangChain can be used in Vercel / Next.js. We support using LangChain in frontend components, in Serverless functions and in Edge functions. You can import it using the following syntax:LangChain 可以在 Vercel / Next.js 中使用。我们支持在前端组件、无服务器函数和边缘函数中使用 LangChain。您可以使用以下语法导入它:
LangChain can be used in Deno / Supabase Edge Functions. You can import it using the following syntax:LangChain 可用于 Deno / Supabase Edge Functions。您可以使用以下语法导入它:
We recommend looking at our Supabase Template for an example of how to use LangChain in Supabase Edge Functions.我们建议查看我们的Supabase模板,以获取如何在Supabase Edge Functions中使用LangChain的示例。
LangChain can be used in the browser. In our CI we test bundling LangChain with Webpack and Vite, but other bundlers should work too. You can import it using the following syntax:LangChain可以在浏览器中使用。在我们的CI中,我们测试了将LangChain与Webpack和Vite捆绑在一起,但其他捆绑器也应该可以工作。您可以使用以下语法导入它:
If you are updating from a version of LangChain prior to 0.0.52, you will need to update your imports to use the new path structure.如果要从 0.0.52 之前的 LangChain 版本进行更新,则需要更新导入以使用新的路径结构。
For example, if you were previously doing例如,如果您以前在做
you will now need to do你现在需要做
This applies to all imports from the following 6 modules, which have been split into submodules for each integration. The combined modules are deprecated, do not work outside of Node.js, and will be removed in a future version.这适用于从以下 6 个模块导入的所有模块,这些模块已为每个集成拆分为子模块。组合模块已弃用,不能在 Node.js 之外工作,并将在未来的版本中删除。
- If you were using langchain/llms, see LLMs for updated import paths.如果使用 langchain/llms ,请参阅 LLM 以获取更新的导入路径。
- If you were using langchain/chat_models, see Chat Models for updated import paths.如果使用 langchain/chat_models ,请参阅聊天模型以获取更新的导入路径。
- If you were using langchain/embeddings, see Embeddings for updated import paths.如果使用 langchain/embeddings ,请参阅嵌入以获取更新的导入路径。
- If you were using langchain/vectorstores, see Vector Stores for updated import paths.如果使用 langchain/vectorstores ,请参阅矢量存储以获取更新的导入路径。
- If you were using langchain/document_loaders, see Document Loaders for updated import paths.如果使用 langchain/document_loaders ,请参阅文档加载程序以获取更新的导入路径。
- If you were using langchain/retrievers, see Retrievers for updated import paths.如果使用 langchain/retrievers ,请参阅检索器以获取更新的导入路径。
Other modules are not affected by this change, and you can continue to import them from the same path.其他模块不受此更改的影响,您可以继续从同一路径导入它们。
Additionally, there are some breaking changes that were needed to support new environments:此外,还需要一些重大更改来支持新环境:
- import { Calculator } from \”langchain/tools\”; now moved to import { Calculator } from \”langchain/tools\”; 现在移至import { Calculator } from \”langchain/tools/calculator\”;
- import { loadLLM } from \”langchain/llms\”; now moved to import { loadLLM } from \”langchain/llms\”; 现在移至import { loadLLM } from \”langchain/llms/load\”;
- import { loadAgent } from \”langchain/agents\”; now moved to import { loadAgent } from \”langchain/agents\”; 现在移至import { loadAgent } from \”langchain/agents/load\”;
- import { loadPrompt } from \”langchain/prompts\”; now moved to import { loadPrompt } from \”langchain/prompts\”; 现在移至import { loadPrompt } from \”langchain/prompts/load\”;
- import { loadChain } from \”langchain/chains\”; now moved to import { loadChain } from \”langchain/chains\”; 现在移至import { loadChain } from \”langchain/chains/load\”;
We do not support Node.js 16, but if you still want to run LangChain on Node.js 16, you will need to follow the instructions in this section. We do not guarantee that these instructions will continue to work in the future.我们不支持 Node.js 16,但如果您仍然想在 Node.js 16 上运行 LangChain,则需要按照本节中的说明进行操作。我们不保证这些说明将来会继续有效。
You will have to make fetch available globally, either:您必须使 fetch 全局可用,其中之一:
- run your application with NODE_OPTIONS=\’–experimental-fetch\’ node …, or以 NODE_OPTIONS=\’–experimental-fetch\’ node … 运行应用程序,或
- install node-fetch and follow the instructions here安装 node-fetch 并按照此处的说明进行操作
Additionally you\’ll have to polyfill unstructuredClone, eg. by installing core-js and following the instructions here.此外,您必须填充 unstructuredClone ,例如。通过安装 core-js 并按照此处的说明进行操作。
If you are running this on Node.js 18+, you do not need to do anything.如果你在 Node.js 18+ 上运行它,你不需要做任何事情。
一眼就能看懂的 Android 性能调优手册,你确定不来一份吗?
很多人面试之前,可能没有在互联网公司工作过或者说工作过但年头较短,不知道互联网公司技术面试都会问哪些问题? 再加上可能自己准备也不充分,去面试没几个回合就被面试官几个问题打蒙了,最后以惨败收场
相信大家在金九银十这个面试季中也会遇到类似的难题;现在面试官的问题都是根据你做过的项目进行深入探讨,如若对性能优化没有深入了解的话,那么你通过面试的机会就会显著下降
以目前的形式来看大厂面试中,性能优化的问题是肯定不会缺席,现今各大厂都尤为关注开发者在性能优化部分的能力边界;究其根本原因就是因为一款产品的从开发到面世,凝聚了无数的心血,但如果最后因为卡顿、闪退等问题影响用户体验,导致用户流失,那么所有的努力都将付诸东流
所以内存优化、UI 卡顿优化、App 监控崩溃等等性能调优相关的技术要点,也逐渐成为了中高级开发者的必备技能;所以大厂面试官,会对你抽丝剥茧到极致,直到探到你的能力边界为止
综上所述,针对性能优化的这些方面的问题,特向大家分享一份 Android 性能调优手册
手册内容围绕:启动优化、渲染优化、内存优化、网络优化、卡顿检测与优化、耗电优化、安装包体积优化、安全问题等方面进行展开并都融入进实践项目中来进行详细讲解,有需要这份手册的朋友:可以私信发送 \”进阶\” 即可 直达获取,觉得手册内容有用的话,可以帮忙转发分享一下,点个赞
手册内容展示如下:
- 为什么要做 App 启动优化?
- 分析优化方向
- 相关数据测量
- 优化技巧
- App 启动方式
- App 启动流程简述
- 优化思路
- 优化方案
- 选择合适的布局类型
- 尽可能少用 wrap_content
- 用 SurfaceView 或 TextureView 代替普通 View
- 使用 RenderJavascript
- 使用 OpenGL 绘图
- 布局调优工具
- 卡顿分析
- 刷新率
- PerfDog
- CPU Profile
- 布局优化
- 过度绘制
- 解决过度绘制
- 层级优化
- 使用 merge
- ViewStub
- 不要在 onDraw 里创建对象
- 异步加载布局
- 崩溃的收集
- ANR
- 应用退出
- 崩溃处理
- 崩溃现场
- 崩溃分析
- 系统崩溃
- 网络指标
- 用户体验
- 网络监控
- Network Monitor
- Charles 抓包工具
- 优化 DNS 解析
- 连接池复用
- 数据压缩
- 弱网优化
- 网络安全
- Android 存储方式
- SharedPrefence
- 多进程问题 -> mmkv
- 已经有 xml/json,为什么要用 protobuf
- 项目中使用 protobuf
- 语言规范
- 字段约束
- 编码协议
- 瘦身原因
- APK 组成
- 代码瘦身
- 代码混淆
- 三方库处理
- 移除无用代码
- 资源瘦身
- 冗余资源
- 图片处理
- 资源混淆
- SO 瘦身
- SO 移除
- 动态加载 SO
改变人生,没有什么捷径可言,这条路需要自己亲自去走一走,只有深入思考,不断反思总结,保持学习的热情,一步一步构建自己完整的知识体系,才是最终的制胜之道,也是程序员应该承担的使命
Android 架构师之路还很漫长,与大家一同共勉
本文作者及来源:Renderbus瑞云渲染农场https://www.renderbus.com
文章为作者独立观点不代本网立场,未经允许不得转载。