From 640c1cb994d53dd9ad41f06a6610f257ea4cc23b Mon Sep 17 00:00:00 2001 From: bracesproul Date: Tue, 9 Apr 2024 11:01:32 -0700 Subject: [PATCH] more updates --- .../docs/integrations/llms/prompt_layer_openai.mdx | 2 +- docs/core_docs/docs/integrations/platforms/microsoft.mdx | 4 ++-- .../docs/integrations/text_embedding/azure_openai.mdx | 4 ++-- examples/src/models/chat/integration_azure_openai.ts | 2 +- .../src/models/chat/integration_azure_openai_base_path.ts | 2 +- examples/src/models/chat/integration_fireworks.ts | 2 +- examples/src/models/chat/integration_togetherai.ts | 2 +- examples/src/models/chat/integration_togetherai_json.ts | 2 +- examples/src/models/chat/integration_togetherai_tools.ts | 2 +- examples/src/models/llm/fireworks.ts | 2 +- langchain/src/chat_models/anthropic.ts | 4 ++-- libs/langchain-anthropic/README.md | 2 +- libs/langchain-azure-openai/src/llms.ts | 3 ++- libs/langchain-azure-openai/src/types.ts | 6 +++++- libs/langchain-community/src/chat_models/fireworks.ts | 6 +++--- libs/langchain-community/src/chat_models/togetherai.ts | 4 ++-- libs/langchain-community/src/llms/togetherai.ts | 2 +- 17 files changed, 28 insertions(+), 23 deletions(-) diff --git a/docs/core_docs/docs/integrations/llms/prompt_layer_openai.mdx b/docs/core_docs/docs/integrations/llms/prompt_layer_openai.mdx index 3b92a7a34b74..8fc30e4de86b 100644 --- a/docs/core_docs/docs/integrations/llms/prompt_layer_openai.mdx +++ b/docs/core_docs/docs/integrations/llms/prompt_layer_openai.mdx @@ -27,7 +27,7 @@ import { PromptLayerOpenAI } from "langchain/llms/openai"; const model = new PromptLayerOpenAI({ temperature: 0.9, - apiKey: "YOUR-AOAI-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY + azureOpenAIApiKey: "YOUR-AOAI-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY azureOpenAIApiInstanceName: "YOUR-AOAI-INSTANCE-NAME", // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME azureOpenAIApiDeploymentName: "YOUR-AOAI-DEPLOYMENT-NAME", // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME azureOpenAIApiCompletionsDeploymentName: diff --git a/docs/core_docs/docs/integrations/platforms/microsoft.mdx b/docs/core_docs/docs/integrations/platforms/microsoft.mdx index a6a35452e96b..cb8bbf5980a9 100644 --- a/docs/core_docs/docs/integrations/platforms/microsoft.mdx +++ b/docs/core_docs/docs/integrations/platforms/microsoft.mdx @@ -48,7 +48,7 @@ import { OpenAIEmbeddings } from "@langchain/openai"; ```typescript const embeddings = new OpenAIEmbeddings({ - apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY + azureOpenAIApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY azureOpenAIApiVersion: "YOUR-API-VERSION", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION azureOpenAIApiInstanceName: "{MY_INSTANCE_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME azureOpenAIApiDeploymentName: "{DEPLOYMENT_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME @@ -68,7 +68,7 @@ import { ChatOpenAI } from "@langchain/openai"; ```typescript const model = new ChatOpenAI({ temperature: 0.9, - apiKey: "SOME_SECRET_VALUE", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY + azureOpenAIApiKey: "SOME_SECRET_VALUE", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY azureOpenAIApiVersion: "YOUR-API-VERSION", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION azureOpenAIApiInstanceName: "{MY_INSTANCE_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME azureOpenAIApiDeploymentName: "{DEPLOYMENT_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME diff --git a/docs/core_docs/docs/integrations/text_embedding/azure_openai.mdx b/docs/core_docs/docs/integrations/text_embedding/azure_openai.mdx index 5627b1045657..5fc0ea731c32 100644 --- a/docs/core_docs/docs/integrations/text_embedding/azure_openai.mdx +++ b/docs/core_docs/docs/integrations/text_embedding/azure_openai.mdx @@ -85,7 +85,7 @@ npm install @langchain/openai import { OpenAIEmbeddings } from "@langchain/openai"; const embeddings = new OpenAIEmbeddings({ - apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY + azureOpenAIApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY azureOpenAIApiVersion: "YOUR-API-VERSION", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION azureOpenAIApiInstanceName: "{MY_INSTANCE_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME azureOpenAIApiDeploymentName: "{DEPLOYMENT_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME @@ -103,7 +103,7 @@ For example, here's how you would connect to the domain `https://westeurope.api. import { OpenAIEmbeddings } from "@langchain/openai"; const embeddings = new OpenAIEmbeddings({ - apiKey: "YOUR-API-KEY", + azureOpenAIApiKey: "YOUR-API-KEY", azureOpenAIApiVersion: "YOUR-API-VERSION", azureOpenAIApiDeploymentName: "{DEPLOYMENT_NAME}", azureOpenAIBasePath: diff --git a/examples/src/models/chat/integration_azure_openai.ts b/examples/src/models/chat/integration_azure_openai.ts index e1677b7b2a80..c36e47c41877 100644 --- a/examples/src/models/chat/integration_azure_openai.ts +++ b/examples/src/models/chat/integration_azure_openai.ts @@ -2,7 +2,7 @@ import { ChatOpenAI } from "@langchain/openai"; const model = new ChatOpenAI({ temperature: 0.9, - apiKey: "SOME_SECRET_VALUE", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY + azureOpenAIApiKey: "SOME_SECRET_VALUE", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY azureOpenAIApiVersion: "YOUR-API-VERSION", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION azureOpenAIApiInstanceName: "{MY_INSTANCE_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME azureOpenAIApiDeploymentName: "{DEPLOYMENT_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME diff --git a/examples/src/models/chat/integration_azure_openai_base_path.ts b/examples/src/models/chat/integration_azure_openai_base_path.ts index 2ed7512a3fe1..d5f2648416f0 100644 --- a/examples/src/models/chat/integration_azure_openai_base_path.ts +++ b/examples/src/models/chat/integration_azure_openai_base_path.ts @@ -2,7 +2,7 @@ import { ChatOpenAI } from "@langchain/openai"; const model = new ChatOpenAI({ temperature: 0.9, - apiKey: "SOME_SECRET_VALUE", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY + azureOpenAIApiKey: "SOME_SECRET_VALUE", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY azureOpenAIApiVersion: "YOUR-API-VERSION", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION azureOpenAIApiDeploymentName: "{DEPLOYMENT_NAME}", // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME azureOpenAIBasePath: diff --git a/examples/src/models/chat/integration_fireworks.ts b/examples/src/models/chat/integration_fireworks.ts index 5bab8b0d7f6f..596a5e4b6461 100644 --- a/examples/src/models/chat/integration_fireworks.ts +++ b/examples/src/models/chat/integration_fireworks.ts @@ -3,5 +3,5 @@ import { ChatFireworks } from "@langchain/community/chat_models/fireworks"; const model = new ChatFireworks({ temperature: 0.9, // In Node.js defaults to process.env.FIREWORKS_API_KEY - fireworksApiKey: "YOUR-API-KEY", + apiKey: "YOUR-API-KEY", }); diff --git a/examples/src/models/chat/integration_togetherai.ts b/examples/src/models/chat/integration_togetherai.ts index 2bf3a77bb9dd..6382a2ac7aac 100644 --- a/examples/src/models/chat/integration_togetherai.ts +++ b/examples/src/models/chat/integration_togetherai.ts @@ -4,7 +4,7 @@ import { HumanMessage } from "@langchain/core/messages"; const model = new ChatTogetherAI({ temperature: 0.9, // In Node.js defaults to process.env.TOGETHER_AI_API_KEY - togetherAIApiKey: "YOUR-API-KEY", + apiKey: "YOUR-API-KEY", }); console.log(await model.invoke([new HumanMessage("Hello there!")])); diff --git a/examples/src/models/chat/integration_togetherai_json.ts b/examples/src/models/chat/integration_togetherai_json.ts index 03f4e7fbd6e5..eef1cbb14195 100644 --- a/examples/src/models/chat/integration_togetherai_json.ts +++ b/examples/src/models/chat/integration_togetherai_json.ts @@ -16,7 +16,7 @@ const responseSchema = { }; const modelWithJsonSchema = new ChatTogetherAI({ temperature: 0, - togetherAIApiKey: process.env.TOGETHER_AI_API_KEY, + apiKey: process.env.TOGETHER_AI_API_KEY, model: "mistralai/Mixtral-8x7B-Instruct-v0.1", }).bind({ response_format: { diff --git a/examples/src/models/chat/integration_togetherai_tools.ts b/examples/src/models/chat/integration_togetherai_tools.ts index 91dc2db3f2a3..a7c4f466cd16 100644 --- a/examples/src/models/chat/integration_togetherai_tools.ts +++ b/examples/src/models/chat/integration_togetherai_tools.ts @@ -9,7 +9,7 @@ const calculatorTool = convertToOpenAITool(new Calculator()); const modelWithCalculator = new ChatTogetherAI({ temperature: 0, // This is the default env variable name it will look for if none is passed. - togetherAIApiKey: process.env.TOGETHER_AI_API_KEY, + apiKey: process.env.TOGETHER_AI_API_KEY, // Together JSON mode/tool calling only supports a select number of models model: "mistralai/Mixtral-8x7B-Instruct-v0.1", }).bind({ diff --git a/examples/src/models/llm/fireworks.ts b/examples/src/models/llm/fireworks.ts index 5f947564aa26..57b81601e11a 100644 --- a/examples/src/models/llm/fireworks.ts +++ b/examples/src/models/llm/fireworks.ts @@ -3,5 +3,5 @@ import { Fireworks } from "@langchain/community/llms/fireworks"; const model = new Fireworks({ temperature: 0.9, // In Node.js defaults to process.env.FIREWORKS_API_KEY - fireworksApiKey: "YOUR-API-KEY", + apiKey: "YOUR-API-KEY", }); diff --git a/langchain/src/chat_models/anthropic.ts b/langchain/src/chat_models/anthropic.ts index 58ac4f9d1e4d..5866cbfd9c6a 100644 --- a/langchain/src/chat_models/anthropic.ts +++ b/langchain/src/chat_models/anthropic.ts @@ -157,7 +157,7 @@ type Kwargs = Record; * ```typescript * const model = new ChatAnthropic({ * temperature: 0.9, - * apiKey: 'YOUR-API-KEY', + * anthropicApiKey: 'YOUR-API-KEY', * }); * const res = await model.invoke({ input: 'Hello!' }); * console.log(res); @@ -175,7 +175,7 @@ export class ChatAnthropic< get lc_secrets(): { [key: string]: string } | undefined { return { - apiKey: "ANTHROPIC_API_KEY", + anthropicApiKey: "ANTHROPIC_API_KEY", }; } diff --git a/libs/langchain-anthropic/README.md b/libs/langchain-anthropic/README.md index decfc36a3eb2..db6ea90488ff 100644 --- a/libs/langchain-anthropic/README.md +++ b/libs/langchain-anthropic/README.md @@ -64,7 +64,7 @@ import { ChatAnthropicMessages } from "@langchain/anthropic"; const model = new ChatAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY, - modelName: "claude-3-sonnet-20240229", + model: "claude-3-sonnet-20240229", }); const response = await model.stream(new HumanMessage("Hello world!")); ``` diff --git a/libs/langchain-azure-openai/src/llms.ts b/libs/langchain-azure-openai/src/llms.ts index 9e4cd132a38e..03935d0b4504 100644 --- a/libs/langchain-azure-openai/src/llms.ts +++ b/libs/langchain-azure-openai/src/llms.ts @@ -51,6 +51,7 @@ export class AzureOpenAI< get lc_secrets(): { [key: string]: string } | undefined { return { + apiKey: "AZURE_OPENAI_API_KEY", openAIApiKey: "OPENAI_API_KEY", azureOpenAIApiKey: "AZURE_OPENAI_API_KEY", azureOpenAIEndpoint: "AZURE_OPENAI_API_ENDPOINT", @@ -136,7 +137,7 @@ export class AzureOpenAI< const openAiApiKey = fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY"); - this.azureOpenAIApiKey = + this.azureOpenAIApiKey = fields?.apiKey ?? fields?.azureOpenAIApiKey ?? getEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? openAiApiKey; diff --git a/libs/langchain-azure-openai/src/types.ts b/libs/langchain-azure-openai/src/types.ts index f3ce0391adce..5434c29d2560 100644 --- a/libs/langchain-azure-openai/src/types.ts +++ b/libs/langchain-azure-openai/src/types.ts @@ -122,7 +122,10 @@ export declare interface OpenAIBaseInput { /** Whether to stream the results or not. Enabling disables tokenUsage reporting */ streaming: boolean; - /** Model name to use */ + /** + * Model name to use + * Alias for `model` + */ modelName: string; /** Model name to use */ model?: string; @@ -195,6 +198,7 @@ export interface AzureOpenAIEmbeddingsParams extends EmbeddingsParams { * The model name to provide as part of this embeddings request. * Not applicable to Azure OpenAI, where deployment information should be included in the Azure * resource URI that's connected to. + * Alias for `model` */ modelName?: string; /** diff --git a/libs/langchain-community/src/chat_models/fireworks.ts b/libs/langchain-community/src/chat_models/fireworks.ts index 98da82811a66..3bacc53f0dbb 100644 --- a/libs/langchain-community/src/chat_models/fireworks.ts +++ b/libs/langchain-community/src/chat_models/fireworks.ts @@ -33,7 +33,7 @@ export type ChatFireworksCallOptions = Partial< * ```typescript * const model = new ChatFireworks({ * temperature: 0.9, - * fireworksApiKey: "YOUR-API-KEY", + * apiKey: "YOUR-API-KEY", * }); * * const response = await model.invoke("Hello, how are you?"); @@ -90,8 +90,8 @@ export class ChatFireworks extends ChatOpenAI { super({ ...fields, - modelName: fields?.model || "accounts/fireworks/models/llama-v2-13b-chat", - openAIApiKey: fireworksApiKey, + model: fields?.model || "accounts/fireworks/models/llama-v2-13b-chat", + apiKey: fireworksApiKey, configuration: { baseURL: "https://api.fireworks.ai/inference/v1", }, diff --git a/libs/langchain-community/src/chat_models/togetherai.ts b/libs/langchain-community/src/chat_models/togetherai.ts index 1e50208ebc9c..bec0f1d8b9a3 100644 --- a/libs/langchain-community/src/chat_models/togetherai.ts +++ b/libs/langchain-community/src/chat_models/togetherai.ts @@ -105,8 +105,8 @@ export class ChatTogetherAI extends ChatOpenAI { super({ ...fields, - modelName: fields?.model || "mistralai/Mixtral-8x7B-Instruct-v0.1", - openAIApiKey: togetherAIApiKey, + model: fields?.model || "mistralai/Mixtral-8x7B-Instruct-v0.1", + apiKey: togetherAIApiKey, configuration: { baseURL: "https://api.together.xyz/v1/", }, diff --git a/libs/langchain-community/src/llms/togetherai.ts b/libs/langchain-community/src/llms/togetherai.ts index f903c3619142..288f1227982a 100644 --- a/libs/langchain-community/src/llms/togetherai.ts +++ b/libs/langchain-community/src/llms/togetherai.ts @@ -196,7 +196,7 @@ export class TogetherAI extends LLM { private constructBody(prompt: string, options?: this["ParsedCallOptions"]) { const body = { - model: options?.modelName ?? this?.model, + model: options?.model ?? options?.modelName ?? this?.model, prompt, temperature: this?.temperature ?? options?.temperature, top_k: this?.topK ?? options?.topK,