Skip to content

Commit

Permalink
Merge pull request langchain-ai#676 from hwchase17/nc/api-key-docs
Browse files Browse the repository at this point in the history
Update docs for passing `apiKey` arg in non-Node envs
  • Loading branch information
nfcampos authored Apr 9, 2023
2 parents 55973e9 + fc27ee8 commit d37366b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
12 changes: 8 additions & 4 deletions docs/docs/modules/models/chat/integrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ LangChain offers a number of Chat Models implementations that integrate with var
```typescript
import { ChatOpenAI } from "langchain/chat_models";

// Expects an OpenAI API key to be set in the env variable OPENAI_API_KEY
const model = new ChatOpenAI({ temperature: 0.9 });
const model = new ChatOpenAI({
temperature: 0.9,
openAIApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.OPENAI_API_KEY
});
```

## `Anthropic`

```typescript
import { ChatAnthropic } from "langchain/chat_models";

// Expects an Anthropic API key to be set in the env variable ANTHROPIC_API_KEY
const model = new ChatAnthropic({ temperature: 0.9 });
const model = new ChatAnthropic({
temperature: 0.9,
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.ANTHROPIC_API_KEY
});
```
8 changes: 6 additions & 2 deletions docs/docs/modules/models/embeddings/integrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ The `OpenAIEmbeddings` class uses the OpenAI API to generate embeddings for a gi
```typescript
import { OpenAIEmbeddings } from "langchain/embeddings";

const embeddings = new OpenAIEmbeddings();
const embeddings = new OpenAIEmbeddings({
openAIApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.OPENAI_API_KEY
});
```

## `CohereEmbeddings`
Expand All @@ -26,5 +28,7 @@ npm install cohere-ai
```typescript
import { CohereEmbeddings } from "langchain/embeddings";

const embeddings = new CohereEmbeddings();
const embeddings = new CohereEmbeddings({
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.COHERE_API_KEY
});
```
22 changes: 18 additions & 4 deletions docs/docs/modules/models/llms/integrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ LangChain offers a number of LLM implementations that integrate with various mod
```typescript
import { OpenAI } from "langchain/llms";

const model = new OpenAI({ temperature: 0.9 });
const model = new OpenAI({
temperature: 0.9,
openAIApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.OPENAI_API_KEY
});
const res = await model.call(
"What would be a good company name a company that makes colorful socks?"
);
Expand All @@ -28,7 +31,10 @@ npm install @huggingface/inference
```typescript
import { HuggingFaceInference } from "langchain/llms";

const model = new HuggingFaceInference({ model: "gpt2" });
const model = new HuggingFaceInference({
model: "gpt2",
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.HUGGINGFACEHUB_API_KEY
});
const res = await model.call("1 + 1 =");
console.log({ res });
```
Expand All @@ -42,7 +48,10 @@ npm install cohere-ai
```typescript
import { Cohere } from "langchain/llms";

const model = new Cohere({ maxTokens: 20 });
const model = new Cohere({
maxTokens: 20,
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.COHERE_API_KEY
});
const res = await model.call(
"What would be a good company name a company that makes colorful socks?"
);
Expand All @@ -61,6 +70,7 @@ import { Replicate } from "langchain/llms";
const model = new Replicate({
model:
"daanelson/flan-t5:04e422a9b85baed86a4f24981d7f9953e20c5fd82f6103b74ebc431588e1cec8",
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.REPLICATE_API_KEY
});
const res = await modelA.call(
"What would be a good company name a company that makes colorful socks?"
Expand All @@ -78,7 +88,11 @@ LangChain integrates with PromptLayer for logging and debugging prompts and resp
2. Create an API token and pass it either as `promptLayerApiKey` argument in the `PromptLayerOpenAI` constructor or in the `PROMPTLAYER_API_KEY` environment variable.

```typescript
const model = new PromptLayerOpenAI({ temperature: 0.9 });
const model = new PromptLayerOpenAI({
temperature: 0.9,
openAIApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.OPENAI_API_KEY
promptLayerApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.PROMPTLAYER_API_KEY
});
const res = await model.call(
"What would be a good company name a company that makes colorful socks?"
);
Expand Down

0 comments on commit d37366b

Please sign in to comment.