Updated: Azure Cognitive Search Plugin/ Free AI APIs 🔎 (#1230)

* Update azure_cognitive_search.md

* Updated: Azure Cognitive Search Plugin to Azure AI Search Plugin.

Update Docs: Azure Cognitive Search Plugin to Azure AI Search Plugin.

Updated:.env.example Azure Cognitive Search to Azure AI Search

Updated: mkdocs.yml link

Updated: SDK Azure 11.3.2 to 12.0.0

* fix:.env AZURE- to AZURE_

* Update azure_ai_search.md

* Updated:(api/package.json, package-lock.json): updated for new version the
  plugin (@azure/search-documents)

* fix:Resolved incorrect file name AzureAISearch

* fix:.env Azure AI Search

* fix:"-" to "_"

* Update Docs: Azure AI Search ith an improved tutorial featuring images and easier-to-understand instructions

fix: Change name of plugin "Azure Ai Search" to "Azure AI Search" i

* Update:Version of REST API versions (Azure AI Search)

* Update azure_ai_search.md

* Update azure_ai_search.md

* Update azure_ai_search.md

* fix: docs Azure AI Seach Images were not appearing.

* fix:Updated to the new repository with working APIs

* Update: Added Compatibility for Previous Environment Variable Names in AzureAISearch Plugin

* Update: Added Compatibility for Previous Environment Variable Names in AzureAISearch Plugin

* Update: Added Compatibility for Previous Environment Variable Names in AzureAISearch Plugin

* Update: Added Compatibility for Previous Environment Variable Names in AzureAISearch Plugin

* Update: o AzureAiSearch.js

* Atualizar o AzureAISearch.js

* Update/fix:EnvironmentVariablesForDeprecation

* fix:The file is outdated and needs to be updated.

* fix:The file is outdated and needs to be updated.

* update: translation portuguese brazilian

* Refactor:Improve Readability and Cleanliness of AzureAISearch Class

* Update AzureAiSearch.js

* Update AzureAISearch.js
This commit is contained in:
Raí Santos 2023-11-30 15:50:28 -03:00 committed by GitHub
parent 690acf1c93
commit d327c8f5d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 315 additions and 332 deletions

View file

@ -0,0 +1,59 @@
const { Tool } = require('langchain/tools');
const { SearchClient, AzureKeyCredential } = require('@azure/search-documents');
class AzureAISearch extends Tool {
static DEFAULT_API_VERSION = '2023-11-01';
static DEFAULT_QUERY_TYPE = 'simple';
static DEFAULT_TOP = 5;
constructor(fields = {}) {
super();
this.initializeProperties(fields);
this.initializeClient();
}
initializeProperties(fields) {
const getValue = (fieldNames, defaultValue) => {
for (const name of fieldNames) {
const value = fields[name] || process.env[name];
if (value !== undefined && value !== null) return value;
}
return defaultValue;
};
this.serviceEndpoint = getValue(['AZURE_AI_SEARCH_SERVICE_ENDPOINT', 'AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT'], this.getServiceEndpoint());
this.indexName = getValue(['AZURE_AI_SEARCH_INDEX_NAME', 'AZURE_COGNITIVE_SEARCH_INDEX_NAME'], this.getIndexName());
this.apiKey = getValue(['AZURE_AI_SEARCH_API_KEY', 'AZURE_COGNITIVE_SEARCH_API_KEY'], this.getApiKey());
this.apiVersion = getValue(['AZURE_AI_SEARCH_API_VERSION', 'AZURE_COGNITIVE_SEARCH_API_VERSION'], AzureAISearch.DEFAULT_API_VERSION);
this.queryType = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE'], AzureAISearch.DEFAULT_QUERY_TYPE);
this.top = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_TOP', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP'], AzureAISearch.DEFAULT_TOP);
this.select = this.getSelect();
}
initializeClient() {
this.client = new SearchClient(this.serviceEndpoint, this.indexName, new AzureKeyCredential(this.apiKey), { apiVersion: this.apiVersion });
}
name = 'azure-ai-search';
description =
'Use the \'azure-ai-search\' tool to retrieve search results relevant to your input';
async _call(query) {
try {
const searchOptions = {
queryType: this.queryType,
top: this.top,
select: this.select
};
const searchResults = await this.client.search(query, searchOptions);
return JSON.stringify(searchResults.results.map(result => result.document));
} catch (error) {
console.error(`Azure AI Search request failed: ${error}`);
return 'There was an error with Azure AI Search.';
}
}
}
module.exports = AzureAISearch;

View file

@ -1,111 +0,0 @@
const { Tool } = require('langchain/tools');
const { SearchClient, AzureKeyCredential } = require('@azure/search-documents');
class AzureCognitiveSearch extends Tool {
constructor(fields = {}) {
super();
this.serviceEndpoint =
fields.AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT || this.getServiceEndpoint();
this.indexName = fields.AZURE_COGNITIVE_SEARCH_INDEX_NAME || this.getIndexName();
this.apiKey = fields.AZURE_COGNITIVE_SEARCH_API_KEY || this.getApiKey();
this.apiVersion = fields.AZURE_COGNITIVE_SEARCH_API_VERSION || this.getApiVersion();
this.queryType = fields.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE || this.getQueryType();
this.top = fields.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP || this.getTop();
this.select = fields.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_SELECT || this.getSelect();
this.client = new SearchClient(
this.serviceEndpoint,
this.indexName,
new AzureKeyCredential(this.apiKey),
{
apiVersion: this.apiVersion,
},
);
}
/**
* The name of the tool.
* @type {string}
*/
name = 'azure-cognitive-search';
/**
* A description for the agent to use
* @type {string}
*/
description =
'Use the \'azure-cognitive-search\' tool to retrieve search results relevant to your input';
getServiceEndpoint() {
const serviceEndpoint = process.env.AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT || '';
if (!serviceEndpoint) {
throw new Error('Missing AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT environment variable.');
}
return serviceEndpoint;
}
getIndexName() {
const indexName = process.env.AZURE_COGNITIVE_SEARCH_INDEX_NAME || '';
if (!indexName) {
throw new Error('Missing AZURE_COGNITIVE_SEARCH_INDEX_NAME environment variable.');
}
return indexName;
}
getApiKey() {
const apiKey = process.env.AZURE_COGNITIVE_SEARCH_API_KEY || '';
if (!apiKey) {
throw new Error('Missing AZURE_COGNITIVE_SEARCH_API_KEY environment variable.');
}
return apiKey;
}
getApiVersion() {
return process.env.AZURE_COGNITIVE_SEARCH_API_VERSION || '2020-06-30';
}
getQueryType() {
return process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE || 'simple';
}
getTop() {
if (process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP) {
return Number(process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP);
} else {
return 5;
}
}
getSelect() {
if (process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_SELECT) {
return process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_SELECT.split(',');
} else {
return null;
}
}
async _call(query) {
try {
const searchOption = {
queryType: this.queryType,
top: this.top,
};
if (this.select) {
searchOption.select = this.select;
}
const searchResults = await this.client.search(query, searchOption);
const resultDocuments = [];
for await (const result of searchResults.results) {
resultDocuments.push(result.document);
}
return JSON.stringify(resultDocuments);
} catch (error) {
console.error(`Azure Cognitive Search request failed: ${error}`);
return 'There was an error with Azure Cognitive Search.';
}
}
}
module.exports = AzureCognitiveSearch;

View file

@ -8,8 +8,8 @@ const StableDiffusionAPI = require('./StableDiffusion');
const WolframAlphaAPI = require('./Wolfram');
const StructuredWolfram = require('./structured/Wolfram');
const SelfReflectionTool = require('./SelfReflection');
const AzureCognitiveSearch = require('./AzureCognitiveSearch');
const StructuredACS = require('./structured/AzureCognitiveSearch');
const AzureAiSearch = require('./AzureAiSearch');
const StructuredACS = require('./structured/AzureAISearch');
const ChatTool = require('./structured/ChatTool');
const E2BTools = require('./structured/E2BTools');
const CodeSherpa = require('./structured/CodeSherpa');
@ -30,7 +30,7 @@ module.exports = {
WolframAlphaAPI,
StructuredWolfram,
SelfReflectionTool,
AzureCognitiveSearch,
AzureAiSearch,
StructuredACS,
E2BTools,
ChatTool,

View file

@ -143,25 +143,25 @@
]
},
{
"name": "Azure Cognitive Search",
"pluginKey": "azure-cognitive-search",
"description": "Use Azure Cognitive Search to find information",
"name": "Azure AI Search",
"pluginKey": "azure-ai-search",
"description": "Use Azure AI Search to find information",
"icon": "https://i.imgur.com/E7crPze.png",
"authConfig": [
{
"authField": "AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT",
"label": "Azur Cognitive Search Endpoint",
"description": "You need to provide your Endpoint for Azure Cognitive Search."
"authField": "AZURE_AI_SEARCH_SERVICE_ENDPOINT",
"label": "Azure AI Search Endpoint",
"description": "You need to provide your Endpoint for Azure AI Search."
},
{
"authField": "AZURE_COGNITIVE_SEARCH_INDEX_NAME",
"label": "Azur Cognitive Search Index Name",
"description": "You need to provide your Index Name for Azure Cognitive Search."
"authField": "AZURE_AI_SEARCH_INDEX_NAME",
"label": "Azure AI Search Index Name",
"description": "You need to provide your Index Name for Azure AI Search."
},
{
"authField": "AZURE_COGNITIVE_SEARCH_API_KEY",
"label": "Azur Cognitive Search API Key",
"description": "You need to provideq your API Key for Azure Cognitive Search."
"authField": "AZURE_AI_SEARCH_API_KEY",
"label": "Azure AI Search API Key",
"description": "You need to provideq your API Key for Azure AI Search."
}
]
},

View file

@ -0,0 +1,68 @@
const { StructuredTool } = require('langchain/tools');
const { z } = require('zod');
const { SearchClient, AzureKeyCredential } = require('@azure/search-documents');
class AzureAISearch extends StructuredTool {
static DEFAULT_API_VERSION = '2023-11-01';
static DEFAULT_QUERY_TYPE = 'simple';
static DEFAULT_TOP = 5;
constructor(fields = {}) {
super();
this.initializeProperties(fields);
this.initializeClient();
this.initializeSchema();
}
initializeProperties(fields) {
const getValue = (fieldNames, defaultValue) => {
for (const name of fieldNames) {
const value = fields[name] || process.env[name];
if (value !== undefined && value !== null) return value;
}
return defaultValue;
};
this.serviceEndpoint = getValue(['AZURE_AI_SEARCH_SERVICE_ENDPOINT', 'AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT'], this.getServiceEndpoint());
this.indexName = getValue(['AZURE_AI_SEARCH_INDEX_NAME', 'AZURE_COGNITIVE_SEARCH_INDEX_NAME'], this.getIndexName());
this.apiKey = getValue(['AZURE_AI_SEARCH_API_KEY', 'AZURE_COGNITIVE_SEARCH_API_KEY'], this.getApiKey());
this.apiVersion = getValue(['AZURE_AI_SEARCH_API_VERSION', 'AZURE_COGNITIVE_SEARCH_API_VERSION'], AzureAISearch.DEFAULT_API_VERSION);
this.queryType = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE'], AzureAISearch.DEFAULT_QUERY_TYPE);
this.top = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_TOP', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP'], AzureAISearch.DEFAULT_TOP);
this.select = this.getSelect();
}
initializeClient() {
this.client = new SearchClient(this.serviceEndpoint, this.indexName, new AzureKeyCredential(this.apiKey), { apiVersion: this.apiVersion });
}
initializeSchema() {
this.schema = z.object({
query: z.string().describe('Search word or phrase to Azure AI Search'),
});
}
name = 'azure-ai-search';
description =
'Use the \'azure-ai-search\' tool to retrieve search results relevant to your input';
async _call(data) {
const { query } = data;
try {
const searchOptions = {
queryType: this.queryType,
top: this.top,
select: this.select
};
const searchResults = await this.client.search(query, searchOptions);
return JSON.stringify(searchResults.results.map(result => result.document));
} catch (error) {
console.error(`Azure AI Search request failed: ${error}`);
return 'There was an error with Azure AI Search.';
}
}
}
module.exports = AzureAISearch;

View file

@ -1,116 +0,0 @@
const { StructuredTool } = require('langchain/tools');
const { z } = require('zod');
const { SearchClient, AzureKeyCredential } = require('@azure/search-documents');
class AzureCognitiveSearch extends StructuredTool {
constructor(fields = {}) {
super();
this.serviceEndpoint =
fields.AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT || this.getServiceEndpoint();
this.indexName = fields.AZURE_COGNITIVE_SEARCH_INDEX_NAME || this.getIndexName();
this.apiKey = fields.AZURE_COGNITIVE_SEARCH_API_KEY || this.getApiKey();
this.apiVersion = fields.AZURE_COGNITIVE_SEARCH_API_VERSION || this.getApiVersion();
this.queryType = fields.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE || this.getQueryType();
this.top = fields.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP || this.getTop();
this.select = fields.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_SELECT || this.getSelect();
this.client = new SearchClient(
this.serviceEndpoint,
this.indexName,
new AzureKeyCredential(this.apiKey),
{
apiVersion: this.apiVersion,
},
);
this.schema = z.object({
query: z.string().describe('Search word or phrase to Azure Cognitive Search'),
});
}
/**
* The name of the tool.
* @type {string}
*/
name = 'azure-cognitive-search';
/**
* A description for the agent to use
* @type {string}
*/
description =
'Use the \'azure-cognitive-search\' tool to retrieve search results relevant to your input';
getServiceEndpoint() {
const serviceEndpoint = process.env.AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT || '';
if (!serviceEndpoint) {
throw new Error('Missing AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT environment variable.');
}
return serviceEndpoint;
}
getIndexName() {
const indexName = process.env.AZURE_COGNITIVE_SEARCH_INDEX_NAME || '';
if (!indexName) {
throw new Error('Missing AZURE_COGNITIVE_SEARCH_INDEX_NAME environment variable.');
}
return indexName;
}
getApiKey() {
const apiKey = process.env.AZURE_COGNITIVE_SEARCH_API_KEY || '';
if (!apiKey) {
throw new Error('Missing AZURE_COGNITIVE_SEARCH_API_KEY environment variable.');
}
return apiKey;
}
getApiVersion() {
return process.env.AZURE_COGNITIVE_SEARCH_API_VERSION || '2020-06-30';
}
getQueryType() {
return process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE || 'simple';
}
getTop() {
if (process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP) {
return Number(process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP);
} else {
return 5;
}
}
getSelect() {
if (process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_SELECT) {
return process.env.AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_SELECT.split(',');
} else {
return null;
}
}
async _call(data) {
const { query } = data;
try {
const searchOption = {
queryType: this.queryType,
top: this.top,
};
if (this.select) {
searchOption.select = this.select;
}
const searchResults = await this.client.search(query, searchOption);
const resultDocuments = [];
for await (const result of searchResults.results) {
resultDocuments.push(result.document);
}
return JSON.stringify(resultDocuments);
} catch (error) {
console.error(`Azure Cognitive Search request failed: ${error}`);
return 'There was an error with Azure Cognitive Search.';
}
}
}
module.exports = AzureCognitiveSearch;

View file

@ -17,7 +17,7 @@ const {
StableDiffusionAPI,
DALLE3,
StructuredSD,
AzureCognitiveSearch,
AzureAISearch,
StructuredACS,
E2BTools,
CodeSherpa,
@ -101,7 +101,7 @@ const loadTools = async ({
wolfram: functions ? StructuredWolfram : WolframAlphaAPI,
'dall-e': OpenAICreateImage,
'stable-diffusion': functions ? StructuredSD : StableDiffusionAPI,
'azure-cognitive-search': functions ? StructuredACS : AzureCognitiveSearch,
'azure-ai-search': functions ? StructuredACS : AzureAISearch,
CodeBrew: CodeBrew,
};

View file

@ -28,7 +28,7 @@
"homepage": "https://github.com/danny-avila/LibreChat#readme",
"dependencies": {
"@anthropic-ai/sdk": "^0.5.4",
"@azure/search-documents": "^11.3.2",
"@azure/search-documents": "^12.0.0",
"@keyv/mongo": "^2.1.8",
"@keyv/redis": "^2.8.0",
"axios": "^1.3.4",