Socket
Socket
Sign inDemoInstall

@langchain/openai

Package Overview
Dependencies
Maintainers
6
Versions
69
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.0.26 to 0.0.27

5

dist/chat_models.d.ts

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

* temperature: 0.9,
* modelName: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
* model: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
* });

@@ -81,4 +81,6 @@ *

modelName: string;
model: string;
modelKwargs?: OpenAIChatInput["modelKwargs"];
stop?: string[];
stopSequences?: string[];
user?: string;

@@ -91,2 +93,3 @@ timeout?: number;

openAIApiKey?: string;
apiKey?: string;
azureOpenAIApiVersion?: string;

@@ -93,0 +96,0 @@ azureOpenAIApiKey?: string;

47

dist/chat_models.js

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

* temperature: 0.9,
* modelName: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
* model: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
* });

@@ -181,2 +181,3 @@ *

openAIApiKey: "OPENAI_API_KEY",
apiKey: "OPENAI_API_KEY",
azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",

@@ -190,2 +191,3 @@ organization: "OPENAI_ORGANIZATION",

openAIApiKey: "openai_api_key",
apiKey: "openai_api_key",
azureOpenAIApiVersion: "azure_openai_api_version",

@@ -249,2 +251,8 @@ azureOpenAIApiKey: "azure_openai_api_key",

});
Object.defineProperty(this, "model", {
enumerable: true,
configurable: true,
writable: true,
value: "gpt-3.5-turbo"
});
Object.defineProperty(this, "modelKwargs", {

@@ -262,2 +270,8 @@ enumerable: true,

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

@@ -305,2 +319,8 @@ enumerable: true,

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

@@ -355,7 +375,10 @@ enumerable: true,

this.openAIApiKey =
fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
fields?.apiKey ??
fields?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");
this.apiKey = this.openAIApiKey;
this.azureOpenAIApiKey =
fields?.azureOpenAIApiKey ??
getEnvironmentVariable("AZURE_OPENAI_API_KEY");
if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
if (!this.azureOpenAIApiKey && !this.apiKey) {
throw new Error("OpenAI or Azure OpenAI API key not found");

@@ -378,3 +401,4 @@ }

getEnvironmentVariable("OPENAI_ORGANIZATION");
this.modelName = fields?.modelName ?? this.modelName;
this.modelName = fields?.model ?? fields?.modelName ?? this.model;
this.model = this.modelName;
this.modelKwargs = fields?.modelKwargs ?? {};

@@ -391,3 +415,4 @@ this.timeout = fields?.timeout;

this.logitBias = fields?.logitBias;
this.stop = fields?.stop;
this.stop = fields?.stopSequences ?? fields?.stop;
this.stopSequences = this?.stop;
this.user = fields?.user;

@@ -405,6 +430,6 @@ this.streaming = fields?.streaming ?? false;

}
this.openAIApiKey = this.openAIApiKey ?? "";
this.apiKey = this.apiKey ?? "";
}
this.clientConfig = {
apiKey: this.openAIApiKey,
apiKey: this.apiKey,
organization: this.organization,

@@ -430,3 +455,3 @@ baseURL: configuration?.basePath ?? fields?.configuration?.basePath,

const params = {
model: this.modelName,
model: this.model,
temperature: this.temperature,

@@ -441,3 +466,3 @@ top_p: this.topP,

logit_bias: this.logitBias,
stop: options?.stop ?? this.stop,
stop: options?.stop ?? this.stopSequences,
user: this.user,

@@ -460,3 +485,3 @@ stream: this.streaming,

return {
model_name: this.modelName,
model_name: this.model,
...this.invocationParams(),

@@ -646,3 +671,3 @@ ...this.clientConfig,

// From: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb
if (this.modelName === "gpt-3.5-turbo-0301") {
if (this.model === "gpt-3.5-turbo-0301") {
tokensPerMessage = 4;

@@ -649,0 +674,0 @@ tokensPerName = -1;

@@ -9,4 +9,9 @@ import { type ClientOptions } from "openai";

export interface OpenAIEmbeddingsParams extends EmbeddingsParams {
/**
* Model name to use
* Alias for `model`
*/
modelName: string;
/** Model name to use */
modelName: string;
model: string;
/**

@@ -50,2 +55,3 @@ * The number of dimensions the resulting output embeddings should have.

modelName: string;
model: string;
batchSize: number;

@@ -69,3 +75,9 @@ stripNewLines: boolean;

verbose?: boolean;
/**
* The OpenAI API key to use.
* Alias for `apiKey`.
*/
openAIApiKey?: string;
/** The OpenAI API key to use. */
apiKey?: string;
configuration?: ClientOptions;

@@ -72,0 +84,0 @@ }, configuration?: ClientOptions & LegacyOpenAIInput);

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

});
Object.defineProperty(this, "model", {
enumerable: true,
configurable: true,
writable: true,
value: "text-embedding-ada-002"
});
Object.defineProperty(this, "batchSize", {

@@ -110,3 +116,4 @@ enumerable: true,

});
let apiKey = fieldsWithDefaults?.openAIApiKey ??
let apiKey = fieldsWithDefaults?.apiKey ??
fieldsWithDefaults?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");

@@ -132,3 +139,5 @@ const azureApiKey = fieldsWithDefaults?.azureOpenAIApiKey ??

getEnvironmentVariable("OPENAI_ORGANIZATION");
this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
this.modelName =
fieldsWithDefaults?.model ?? fieldsWithDefaults?.modelName ?? this.model;
this.model = this.modelName;
this.batchSize =

@@ -178,3 +187,3 @@ fieldsWithDefaults?.batchSize ?? (azureApiKey ? 1 : this.batchSize);

const params = {
model: this.modelName,
model: this.model,
input: batch,

@@ -206,3 +215,3 @@ };

const params = {
model: this.modelName,
model: this.model,
input: this.stripNewLines ? text.replace(/\n/g, " ") : text,

@@ -209,0 +218,0 @@ };

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

modelName: string;
model: string;
prefixMessages?: OpenAIClient.Chat.ChatCompletionMessageParam[];

@@ -74,0 +75,0 @@ modelKwargs?: OpenAIChatInput["modelKwargs"];

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

});
Object.defineProperty(this, "model", {
enumerable: true,
configurable: true,
writable: true,
value: "gpt-3.5-turbo"
});
Object.defineProperty(this, "prefixMessages", {

@@ -132,0 +138,0 @@ enumerable: true,

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

modelName: string;
model: string;
modelKwargs?: OpenAIInput["modelKwargs"];

@@ -63,5 +64,7 @@ batchSize: number;

stop?: string[];
stopSequences?: string[];
user?: string;
streaming: boolean;
openAIApiKey?: string;
apiKey?: string;
azureOpenAIApiVersion?: string;

@@ -68,0 +71,0 @@ azureOpenAIApiKey?: string;

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

openAIApiKey: "OPENAI_API_KEY",
apiKey: "OPENAI_API_KEY",
azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",

@@ -62,2 +63,3 @@ organization: "OPENAI_ORGANIZATION",

openAIApiKey: "openai_api_key",
apiKey: "openai_api_key",
azureOpenAIApiVersion: "azure_openai_api_version",

@@ -72,5 +74,5 @@ azureOpenAIApiKey: "azure_openai_api_key",

configuration) {
if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
fields?.modelName?.startsWith("gpt-4")) &&
!fields?.modelName?.includes("-instruct")) {
let model = fields?.model ?? fields?.modelName;
if ((model?.startsWith("gpt-3.5-turbo") || model?.startsWith("gpt-4")) &&
!model?.includes("-instruct")) {
// eslint-disable-next-line no-constructor-return

@@ -140,2 +142,8 @@ return new OpenAIChat(fields, configuration);

});
Object.defineProperty(this, "model", {
enumerable: true,
configurable: true,
writable: true,
value: "gpt-3.5-turbo-instruct"
});
Object.defineProperty(this, "modelKwargs", {

@@ -165,2 +173,8 @@ enumerable: true,

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

@@ -184,2 +198,8 @@ enumerable: true,

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

@@ -233,8 +253,12 @@ enumerable: true,

});
model = model ?? this.model;
this.openAIApiKey =
fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
fields?.apiKey ??
fields?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");
this.apiKey = this.openAIApiKey;
this.azureOpenAIApiKey =
fields?.azureOpenAIApiKey ??
getEnvironmentVariable("AZURE_OPENAI_API_KEY");
if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
if (!this.azureOpenAIApiKey && !this.apiKey) {
throw new Error("OpenAI or Azure OpenAI API key not found");

@@ -259,3 +283,4 @@ }

getEnvironmentVariable("OPENAI_ORGANIZATION");
this.modelName = fields?.modelName ?? this.modelName;
this.modelName = model;
this.model = model;
this.modelKwargs = fields?.modelKwargs ?? {};

@@ -272,3 +297,4 @@ this.batchSize = fields?.batchSize ?? this.batchSize;

this.logitBias = fields?.logitBias;
this.stop = fields?.stop;
this.stop = fields?.stopSequences ?? fields?.stop;
this.stopSequences = fields?.stopSequences;
this.user = fields?.user;

@@ -289,6 +315,6 @@ this.streaming = fields?.streaming ?? false;

}
this.openAIApiKey = this.openAIApiKey ?? "";
this.apiKey = this.apiKey ?? "";
}
this.clientConfig = {
apiKey: this.openAIApiKey,
apiKey: this.apiKey,
organization: this.organization,

@@ -310,3 +336,3 @@ baseURL: configuration?.basePath ?? fields?.configuration?.basePath,

return {
model: this.modelName,
model: this.model,
temperature: this.temperature,

@@ -320,3 +346,3 @@ max_tokens: this.maxTokens,

logit_bias: this.logitBias,
stop: options?.stop ?? this.stop,
stop: options?.stop ?? this.stopSequences,
user: this.user,

@@ -330,3 +356,3 @@ stream: this.streaming,

return {
model_name: this.modelName,
model_name: this.model,
...this.invocationParams(),

@@ -370,3 +396,3 @@ ...this.clientConfig,

// Cast here to allow for other models that may not fit the union
modelName: this.modelName,
modelName: this.model,
});

@@ -373,0 +399,0 @@ }

@@ -9,6 +9,12 @@ import { OpenAI as OpenAIClient } from "openai";

* The OpenAI API key
* Alias for `apiKey`
*/
openAIApiKey?: string;
/**
* The OpenAI API key
*/
apiKey?: string;
/**
* The model to use.
* Alias for `model`
* @params "dall-e-2" | "dall-e-3"

@@ -19,2 +25,8 @@ * @default "dall-e-3"

/**
* The model to use.
* @params "dall-e-2" | "dall-e-3"
* @default "dall-e-3"
*/
model?: string;
/**
* The style of the generated images. Must be one of vivid or natural.

@@ -71,3 +83,3 @@ * Vivid causes the model to lean towards generating hyper-real and dramatic images.

static readonly toolName = "dalle_api_wrapper";
private modelName;
private model;
private style;

@@ -74,0 +86,0 @@ private quality;

@@ -31,3 +31,3 @@ import { getEnvironmentVariable } from "@langchain/core/utils/env";

});
Object.defineProperty(this, "modelName", {
Object.defineProperty(this, "model", {
enumerable: true,

@@ -74,3 +74,5 @@ configurable: true,

});
const openAIApiKey = fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
const openAIApiKey = fields?.apiKey ??
fields?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");
const organization = fields?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION");

@@ -83,3 +85,3 @@ const clientConfig = {

this.client = new OpenAIClient(clientConfig);
this.modelName = fields?.modelName ?? this.modelName;
this.model = fields?.model ?? fields?.modelName ?? this.model;
this.style = fields?.style ?? this.style;

@@ -95,3 +97,3 @@ this.quality = fields?.quality ?? this.quality;

const response = await this.client.images.generate({
model: this.modelName,
model: this.model,
prompt: input,

@@ -98,0 +100,0 @@ n: this.n,

@@ -27,4 +27,9 @@ import type { OpenAI as OpenAIClient } from "openai";

streaming: boolean;
/**
* Model name to use
* Alias for `model`
*/
modelName: string;
/** Model name to use */
modelName: string;
model: string;
/** Holds any additional parameters that are valid to pass to {@link

@@ -35,4 +40,9 @@ * https://platform.openai.com/docs/api-reference/completions/create |

modelKwargs?: Record<string, any>;
/**
* List of stop words to use when generating
* Alias for `stopSequences`
*/
stop?: string[];
/** List of stop words to use when generating */
stop?: string[];
stopSequences?: string[];
/**

@@ -45,4 +55,10 @@ * Timeout to use when making requests to OpenAI.

* `OPENAI_API_KEY` environment variable.
* Alias for `apiKey`
*/
openAIApiKey?: string;
/**
* API key to use when making requests to OpenAI. Defaults to the value of
* `OPENAI_API_KEY` environment variable.
*/
apiKey?: string;
}

@@ -49,0 +65,0 @@ export type OpenAICoreRequestOptions<Req extends object = Record<string, unknown>> = {

{
"name": "@langchain/openai",
"version": "0.0.26",
"version": "0.0.27",
"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

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