From bf1ad79077fd747bab1569fec5a13c8d08a0dfd2 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Wed, 22 Feb 2023 22:19:04 -0800 Subject: [PATCH] =?UTF-8?q?update=20doc=20to=20suggest=20fewer=20more=20wa?= =?UTF-8?q?y=20of=20setting=20up=20the=20Api=20Key=20in=20the=E2=80=A6=20(?= =?UTF-8?q?#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update doc to suggest fewer more way of setting up the Api Key in the getting started section (#103) * cr --------- Co-authored-by: Thoonsen Maxime --- docs/docs/getting-started.md | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/docs/getting-started.md b/docs/docs/getting-started.md index 68dafd4b977c..c7983552cd64 100644 --- a/docs/docs/getting-started.md +++ b/docs/docs/getting-started.md @@ -10,7 +10,7 @@ To get started, install LangChain with the following command: npm i langchain ``` -## Environment Setup +## Picking up a LLM Using LangChain will usually require integrations with one or more model providers, data stores, apis, etc. @@ -20,15 +20,9 @@ For this example, we will be using OpenAI's APIs, so we will first need to insta npm i openai ``` -We will then need to set the environment variable for the OpenAI key. We can do this by setting the value in a `.env` file. - -``` -OPENAI_API_KEY="..." -``` - ## Building a Language Model Application -Now that we have installed LangChain and set up our environment, we can start building our language model application. +Now that we have installed LangChain, we can start building our language model application. LangChain provides many modules that can be used to build language model applications. Modules can be combined to create more complex applications, or be used individually for simple applications. @@ -42,13 +36,27 @@ In order to do this, we first need to import the LLM wrapper. import { OpenAI } from "langchain"; ``` -We can then initialize the wrapper with any arguments. In this example, we probably want the outputs to be MORE random, so we'll initialize it with a HIGH temperature. +We will then need to set the environment variable for the OpenAI key. Three options here: + +1. We can do this by setting the value in a `.env` file and use the [dotenv](https://github.com/motdotla/dotenv) package to read it. + +``` +OPENAI_API_KEY="..." +``` + +2. Or we can export the environment variable with the following command in your shell: + +```bash +export OPENAI_API_KEY=sk-.... +``` + +3. Or we can do it when initializing the wrapper along with other arguments. In this example, we probably want the outputs to be MORE random, so we'll initialize it with a HIGH temperature. ```typescript -const model = new OpenAI({ temperature: 0.9 }); +const model = new OpenAI({ openAIApiKey: "sk-...", temperature: 0.9 }); ``` -We can now call it on some input! +Once we have initialized the wrapper, we can now call it on some input! ```typescript const res = await model.call(