Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@langchain/openai

Package Overview
Dependencies
Maintainers
11
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@langchain/openai - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

38

dist/azure/chat_models.js

@@ -425,2 +425,7 @@ import { AzureOpenAI as AzureOpenAIClient } from "openai";

openAIBasePath: "openai_api_base",
deploymentName: "deployment_name",
azureOpenAIEndpoint: "azure_endpoint",
azureOpenAIApiVersion: "openai_api_version",
azureOpenAIBasePath: "openai_api_base",
azureOpenAIApiDeploymentName: "deployment_name",
};

@@ -455,2 +460,3 @@ }

baseURL: this.clientConfig.baseURL,
azureOpenAIEndpoint: this.azureOpenAIEndpoint,
};

@@ -511,2 +517,34 @@ const endpoint = getEndpoint(openAIEndpointConfig);

delete json.kwargs.azure_open_ai_base_path;
if (!json.kwargs.azure_endpoint && this.azureOpenAIEndpoint) {
json.kwargs.azure_endpoint = this.azureOpenAIEndpoint;
}
if (!json.kwargs.azure_endpoint && this.azureOpenAIBasePath) {
const parts = this.azureOpenAIBasePath.split("/openai/deployments/");
if (parts.length === 2 && parts[0].startsWith("http")) {
const [endpoint] = parts;
json.kwargs.azure_endpoint = endpoint;
}
}
if (!json.kwargs.azure_endpoint && this.azureOpenAIApiInstanceName) {
json.kwargs.azure_endpoint = `https://${this.azureOpenAIApiInstanceName}.openai.azure.com/`;
}
if (!json.kwargs.deployment_name && this.azureOpenAIApiDeploymentName) {
json.kwargs.deployment_name = this.azureOpenAIApiDeploymentName;
}
if (!json.kwargs.deployment_name && this.azureOpenAIBasePath) {
const parts = this.azureOpenAIBasePath.split("/openai/deployments/");
if (parts.length === 2) {
const [, deployment] = parts;
json.kwargs.deployment_name = deployment;
}
}
if (json.kwargs.azure_endpoint &&
json.kwargs.deployment_name &&
json.kwargs.openai_api_base) {
delete json.kwargs.openai_api_base;
}
if (json.kwargs.azure_openai_api_instance_name &&
json.kwargs.azure_endpoint) {
delete json.kwargs.azure_openai_api_instance_name;
}
}

@@ -513,0 +551,0 @@ return json;

1

dist/chat_models.d.ts

@@ -575,2 +575,3 @@ import { type ClientOptions, OpenAI as OpenAIClient } from "openai";

azureOpenAIBasePath?: string;
azureOpenAIEndpoint?: string;
organization?: string;

@@ -577,0 +578,0 @@ __includeRawResponse?: boolean;

@@ -862,2 +862,8 @@ import { OpenAI as OpenAIClient } from "openai";

});
Object.defineProperty(this, "azureOpenAIEndpoint", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "organization", {

@@ -925,2 +931,5 @@ enumerable: true,

getEnvironmentVariable("OPENAI_ORGANIZATION");
this.azureOpenAIEndpoint =
fields?.azureOpenAIEndpoint ??
getEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
this.modelName = fields?.model ?? fields?.modelName ?? this.model;

@@ -944,5 +953,14 @@ this.model = this.modelName;

if (this.azureOpenAIApiKey || this.azureADTokenProvider) {
if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
if (!this.azureOpenAIApiInstanceName &&
!this.azureOpenAIBasePath &&
!this.azureOpenAIEndpoint) {
throw new Error("Azure OpenAI API instance name not found");
}
if (!this.azureOpenAIApiDeploymentName && this.azureOpenAIBasePath) {
const parts = this.azureOpenAIBasePath.split("/openai/deployments/");
if (parts.length === 2) {
const [, deployment] = parts;
this.azureOpenAIApiDeploymentName = deployment;
}
}
if (!this.azureOpenAIApiDeploymentName) {

@@ -1400,2 +1418,3 @@ throw new Error("Azure OpenAI API deployment name not found");

baseURL: this.clientConfig.baseURL,
azureOpenAIEndpoint: this.azureOpenAIEndpoint,
};

@@ -1402,0 +1421,0 @@ const endpoint = getEndpoint(openAIEndpointConfig);

@@ -173,3 +173,3 @@ import type { OpenAI as OpenAIClient } from "openai";

/**
* Custom endpoint for Azure OpenAI API. This is useful in case you have a deployment in another region.
* Custom base url for Azure OpenAI API. This is useful in case you have a deployment in another region.
* e.g. setting this value to "https://westeurope.api.cognitive.microsoft.com/openai/deployments"

@@ -180,2 +180,8 @@ * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/

/**
* Custom endpoint for Azure OpenAI API. This is useful in case you have a deployment in another region.
* e.g. setting this value to "https://westeurope.api.cognitive.microsoft.com/"
* will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/
*/
azureOpenAIEndpoint?: string;
/**
* A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),

@@ -182,0 +188,0 @@ * which will be invoked on every request.

7

dist/utils/azure.d.ts

@@ -8,2 +8,3 @@ export interface OpenAIEndpointConfig {

baseURL?: string | null;
azureOpenAIEndpoint?: string;
}

@@ -17,9 +18,11 @@ /**

* @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
* @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI.
* @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
* @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
* @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI.
* @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
* @property {string} config.baseURL - Some other custom base path URL.
* @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
*
* The function operates as follows:
* - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
* - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
* - If `azureOpenAIApiKey` is provided, it checks for `azureOpenAIApiInstanceName` and `azureOpenAIApiDeploymentName` and throws an error if any of these is missing. If both are provided, it generates an URL incorporating these parameters.

@@ -26,0 +29,0 @@ * - If none of the above conditions are met, return any custom `baseURL`.

@@ -8,9 +8,11 @@ /**

* @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
* @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI.
* @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
* @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
* @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI.
* @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
* @property {string} config.baseURL - Some other custom base path URL.
* @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
*
* The function operates as follows:
* - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
* - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
* - If `azureOpenAIApiKey` is provided, it checks for `azureOpenAIApiInstanceName` and `azureOpenAIApiDeploymentName` and throws an error if any of these is missing. If both are provided, it generates an URL incorporating these parameters.

@@ -25,3 +27,3 @@ * - If none of the above conditions are met, return any custom `baseURL`.

export function getEndpoint(config) {
const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, } = config;
const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, azureOpenAIEndpoint, } = config;
if ((azureOpenAIApiKey || azureADTokenProvider) &&

@@ -32,2 +34,7 @@ azureOpenAIBasePath &&

}
if ((azureOpenAIApiKey || azureADTokenProvider) &&
azureOpenAIEndpoint &&
azureOpenAIApiDeploymentName) {
return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;
}
if (azureOpenAIApiKey || azureADTokenProvider) {

@@ -34,0 +41,0 @@ if (!azureOpenAIApiInstanceName) {

{
"name": "@langchain/openai",
"version": "0.3.2",
"version": "0.3.3",
"description": "OpenAI integrations for LangChain.js",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc