Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch], azure-openai[patch]: tag langchainjs in azure integrations calls #4411

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export class AzureBlobStorageContainerLoader extends BaseDocumentLoader {
*/
public async load() {
const blobServiceClient = BlobServiceClient.fromConnectionString(
this.connectionString
this.connectionString,
{
userAgentOptions: {
userAgentPrefix: "langchainjs-blob-storage-container",
},
}
);

const containerClient = blobServiceClient.getContainerClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export class AzureBlobStorageFileLoader extends BaseDocumentLoader {

try {
const blobServiceClient = BlobServiceClient.fromConnectionString(
this.connectionString
this.connectionString,
{
userAgentOptions: {
userAgentPrefix: "langchainjs-blob-storage-file",
},
}
);

const containerClient = blobServiceClient.getContainerClient(
Expand Down
11 changes: 9 additions & 2 deletions libs/langchain-azure-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
FunctionDef,
formatFunctionDefinitions,
} from "./utils/openai-format-fndef.js";
import { USER_AGENT_PREFIX } from "./constants.js";

function _convertDeltaToMessageChunk(
delta: ChatResponseMessage,
Expand Down Expand Up @@ -302,12 +303,18 @@ export class AzureChatOpenAI
if (isTokenCredential(azureCredential)) {
this.client = new AzureOpenAIClient(
this.azureOpenAIEndpoint ?? "",
azureCredential as TokenCredential
azureCredential as TokenCredential,
{
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
}
);
} else {
this.client = new AzureOpenAIClient(
this.azureOpenAIEndpoint ?? "",
azureCredential as KeyCredential
azureCredential as KeyCredential,
{
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
}
);
}
}
Expand Down
1 change: 1 addition & 0 deletions libs/langchain-azure-openai/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const USER_AGENT_PREFIX = "langchainjs-azure-openai";
11 changes: 9 additions & 2 deletions libs/langchain-azure-openai/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { getEnvironmentVariable } from "@langchain/core/utils/env";
import { chunkArray } from "@langchain/core/utils/chunk_array";
import { AzureOpenAIInput, AzureOpenAIEmbeddingsParams } from "./types.js";
import { USER_AGENT_PREFIX } from "./constants.js";

export class AzureOpenAIEmbeddings
extends Embeddings
Expand Down Expand Up @@ -96,12 +97,18 @@ export class AzureOpenAIEmbeddings
if (isTokenCredential(azureCredential)) {
this.client = new AzureOpenAIClient(
this.azureOpenAIEndpoint ?? "",
azureCredential as TokenCredential
azureCredential as TokenCredential,
{
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
}
);
} else {
this.client = new AzureOpenAIClient(
this.azureOpenAIEndpoint ?? "",
azureCredential as KeyCredential
azureCredential as KeyCredential,
{
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
}
);
}
}
Expand Down
11 changes: 9 additions & 2 deletions libs/langchain-azure-openai/src/llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
isTokenCredential,
} from "@azure/core-auth";
import { AzureOpenAIInput, OpenAICallOptions, OpenAIInput } from "./types.js";
import { USER_AGENT_PREFIX } from "./constants.js";

/**
* Interface for tracking token usage in OpenAI calls.
Expand Down Expand Up @@ -175,12 +176,18 @@ export class AzureOpenAI<
if (isTokenCredential(azureCredential)) {
this.client = new AzureOpenAIClient(
this.azureOpenAIEndpoint ?? "",
azureCredential as TokenCredential
azureCredential as TokenCredential,
{
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
}
);
} else {
this.client = new AzureOpenAIClient(
this.azureOpenAIEndpoint ?? "",
azureCredential as KeyCredential
azureCredential as KeyCredential,
{
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
}
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions libs/langchain-community/src/vectorstores/azure_aisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type AzureAISearchFilterType = {
includeEmbeddings?: boolean;
};

const USER_AGENT_PREFIX = "langchainjs-azure-aisearch";
const DEFAULT_FIELD_ID = "id";
const DEFAULT_FIELD_CONTENT = "content";
const DEFAULT_FIELD_CONTENT_VECTOR = "content_vector";
Expand Down Expand Up @@ -151,9 +152,13 @@ export class AzureAISearchVectorStore extends VectorStore {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const credential = new AzureKeyCredential(key!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.client = new SearchClient(endpoint!, this.indexName, credential);
this.client = new SearchClient(endpoint!, this.indexName, credential, {
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const indexClient = new SearchIndexClient(endpoint!, credential);
const indexClient = new SearchIndexClient(endpoint!, credential, {
userAgentOptions: { userAgentPrefix: USER_AGENT_PREFIX },
});

// Start initialization, but don't wait for it to finish here
this.initPromise = this.ensureIndexExists(indexClient).catch((error) => {
Expand Down
4 changes: 3 additions & 1 deletion libs/langchain-community/src/vectorstores/azure_cosmosdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class AzureCosmosDBVectorStore extends VectorStore {

if (!dbConfig.client) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.client = new MongoClient(connectionString!);
this.client = new MongoClient(connectionString!, {
appName: "langchainjs",
});
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
Loading