Skip to content

Commit 9819196

Browse files
committed
Merge branch 'main' of https://github.com/addy-ai/langdrive
2 parents de0965a + 20d5773 commit 9819196

22 files changed

+1812
-1
lines changed

‎demos/langdrive-chatgpt-demo/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ <h1 class="text-xl font-semibold user-prompt">What is a Chatbot?</h1>
101101
</div>
102102

103103
<div class="text-gray-400 text-xs mb-6">
104-
<p>ChatGPT Jan 9 Version. Free Research Preview. Our goal is to make AI systems more natural and
104+
<p>NOT ChatGPT Jan 9 Version. Free Research Preview. Our goal is to make AI systems more natural and
105105
safe to
106106
interact with. Your feedback will help us improve.</p>
107107
</div>

‎docs/api/chatbot.md‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# NPM: Langdrive: DriveChatbot Class
2+
3+
The Chatbot returns Async Promises.
4+
5+
Chatbot's minimal initalization is like so:
6+
`chatbot = new langdrive.DriveChatbot({model_config:{HuggingFaceAPIKey:<KEY>}})`
7+
or like so:
8+
`chatbot = new langdrive.Chatbot({model_config:{openAIApiKey:<KEY>}})`
9+
10+
### Chatbot Example Script
11+
12+
Get started with a sample script by created the following files:
13+
14+
```
15+
npm install langdrive dotenv
16+
node test.js
17+
```
18+
19+
`.env` File:
20+
21+
```
22+
OPENAI_API_KEY=<YOUR_KEY_HERE>
23+
GOOGLE_DESKTOP_CLIENT_KEYFILE_PATH=<YOUR_KEY_HERE>
24+
```
25+
26+
`test.js` File:
27+
28+
```
29+
require("dotenv").config();
30+
const langdrive = require("langdrive");
31+
32+
// LangDrive returns promises
33+
(async()=>{
34+
// To initialize Langdrive, give it a model to use and any associated config information.
35+
// Here we select openAi and pass it an API key (hidden behind .env)
36+
let chatbot = await new langdrive.DriveChatbot({
37+
verbose: true,
38+
drive: {
39+
verbose: false,
40+
...(!GOOGLE_DESKTOP_KEYFILE_PATH
41+
? {}
42+
: {
43+
server: {
44+
embed_from_folder: "chatbot",
45+
embed_to_folder: "chatbot/embeddings",
46+
scopes: ["https://www.googleapis.com/auth/drive"],
47+
// serviceKeyFile: __dirname + "/../" + GOOGLE_SERVICE_KEYFILE_PATH
48+
// OR
49+
desktopKeyFile: __dirname + GOOGLE_DESKTOP_KEYFILE_PATH
50+
// ( Alternately:) desktopKeyFileContents: GOOGLE_DESKTOP_CLIENT_KEYFILE_CONTENTS
51+
// OR
52+
// desktopTokenFile: GOOGLE_DESKTOP_CLIENT_TOKEN_PATH:
53+
// ( Alternately:) desktopTokenFileContents: GOOGLE_DESKTOP_CLIENT_TOKEN_CONTENTS
54+
// OR
55+
//client_id: GOOGLE_DESKTOP_CLIENT_ID, // and
56+
//client_secret: GOOGLE_SERVICE_CLIENT_SECRET //and
57+
//client_redirect_uri: xyz
58+
}
59+
})
60+
},
61+
model: {
62+
service: !!HUGGINGFACE_API_KEY ? "huggingFace" : "chatOpenAi",
63+
model_config: !!HUGGINGFACE_API_KEY
64+
? {
65+
model_id: "meta-llama/Llama-2-30b",
66+
huggingFaceApiKey: HUGGINGFACE_API_KEY
67+
}
68+
: {
69+
modelName: "gpt-3.5-turbo", // default = "text-davinci-003"
70+
// maxTokens: 256, // default = 256
71+
openAIApiKey: OPENAI_API_KEY,
72+
temperature: 0.9
73+
}
74+
},
75+
agent: {
76+
type: "chat-conversational-react-description",
77+
memory_length: 2,
78+
vector_length: 2,
79+
verbose: false,
80+
tools: [],
81+
agent_config: {}
82+
// prefix
83+
// suffix
84+
}
85+
});
86+
// LangDrive returns a promise, so let's await those.
87+
let prompt = "My name is Michael, What can you do for me.";
88+
console.log("> " , await chatbot.sendMessage(prompt));
89+
90+
prompt = "What can you do for me in google drive?";
91+
console.log("> " , await chatbot.sendMessage(prompt));
92+
93+
prompt = "What is my name?";
94+
console.log("> " , await chatbot.sendMessage(prompt));
95+
})()
96+
```
97+
98+
You can also clone the repo and get started with our demo chatbot
99+
100+
1. Download Repo
101+
2. > npm install
102+
3. Create Google OAuth2 Keys
103+
4. .env.examples -> .env + Keys
104+
5. npm run start
105+
106+
### Chatbot Properties
107+
108+
The `props` used in DriveChatbot(`props`) configure your chatbot. Available settings and their default values are shown below.

‎docs/api/dataOverview.md‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Data Connectors Overview
2+
3+
Welcome to the Data Connectors Overview! This document offers a detailed guide on the functionalities and capabilities of several Node.js classes, designed to enhance your development experience.
4+
5+
## Firestore Class Overview
6+
7+
### Class: `Firestore`
8+
The `Firestore` class in Node.js is designed for robust interaction with Firebase Firestore. It supports various operations like querying, adding, updating, and deleting documents in your Firestore database.
9+
10+
#### Constructor
11+
- **Parameters**:
12+
- `props` (Object): Contains the Firestore database instance.
13+
- **Description**:
14+
- Initializes the Firestore class with a database instance.
15+
16+
#### Key Methods
17+
- **`filterCollectionWithWhereClause(...)`**: Filters a collection using a where clause.
18+
- **`addDocumentToCollection(...)`**: Adds a new document to a specified collection.
19+
- **`updateDocument(...)`**: Updates an existing document in a collection.
20+
- **`deleteDocumentFromCollection(...)`**: Deletes a document from a collection.
21+
- **`getAllDocumentsInCollection(...)`**: Retrieves all documents from a specified collection.
22+
23+
---
24+
25+
## EmailRetriever Class Overview
26+
27+
### Class: `EmailRetriever`
28+
The `EmailRetriever` class in Node.js is tailored for retrieving emails from different email clients using SMTP configurations. It provides a streamlined approach to email retrieval.
29+
30+
#### Constructor
31+
- **Parameters**:
32+
- `emailAddress` (String): The email account's address.
33+
- `emailPassword` (String): The email account's password.
34+
- `emailClient` (String): The email client hosting the account.
35+
- `verbose` (Boolean): Enables verbose error logging.
36+
- **Description**:
37+
- Initializes the `EmailRetriever` with email credentials and client.
38+
39+
#### Key Methods
40+
- **`getEmailsInFolder(...)`**: Retrieves emails from a specific folder in the email account.
41+
- **`validateSMTPConfig()`**: Validates the SMTP configuration for the email client.
42+
43+
#### Additional Information
44+
- **SMTP Configuration**: Uses predefined SMTP settings for supported email clients.
45+
- **Error Handling**: Robust error management, especially for unsupported email clients.
46+
- **External API Integration**: Utilizes external APIs for email retrieval.
47+
48+
---
49+
50+
# DriveUtils
51+
52+
## Class: `DriveUtils`
53+
54+
The `DriveUtils` class in Node.js is designed to interface with Google Drive. It handles authentication, file listing, information retrieval, and file operations using Google APIs.
55+
56+
### Constructor
57+
- **Parameters**: `props` (Object) containing various configuration options.
58+
- **Description**:
59+
- Initializes the class with properties such as `client_id`, `client_secret`, `scopes`, and `keyFilePath`.
60+
- Handles authentication for different application types (server, desktop, web).
61+
62+
### Key Methods
63+
- **`getDrive()`**: Initializes and retrieves the Google Drive instance.
64+
- **`listFiles(props)`**: Lists files in Google Drive based on properties like directory, mime type, etc.
65+
- **`listDirectories(props)`**: Lists all directories or directories within a specific directory.
66+
- **`getFileInfo(props)`**: Retrieves information about a specific file based on provided criteria.
67+
- **`getFileById(props)`**: Retrieves a file by its ID.
68+
- **`getFileByName(props)`**: Retrieves a file by its name.
69+
- **`createFile(props)`**: Creates a file in Google Drive.
70+
- **`createAndOrGetContent(props)`**: Creates or retrieves content based on a given path and other criteria.
71+
- **`updateFile(props)`**: Updates a file in Google Drive.
72+
73+
### Static Methods
74+
- **`getAuthUrl(config)`**: Generates a Google authentication URL for obtaining access tokens.
75+
- **`handleAuthCallback(config)`**: Handles the authentication callback from Google to get access tokens.
76+
- **`checkAndRefresh(config)`**: Checks and refreshes the access token if it is expired.
77+
- **`refreshToken(config)`**: Refreshes the access token.
78+
79+
## Comments and Additional Information
80+
- The class provides various static and instance methods for handling Google Drive operations.
81+
- It supports different types of applications like server, desktop, and web.
82+
- The methods are comprehensive, covering from authentication to

‎docs/api/email.md‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# EmailRetriever Documentation
2+
3+
**Description**: The `EmailRetriever` class is designed to fetch emails from specific folders within an email account. It supports multiple email clients and allows for easy email retrieval with support for IMAP search commands. It leverages proprietary Addy AI technology to interact with email servers and facilitates the extraction of email data for use in applications.
4+
5+
### Constructor: `EmailRetriever()`
6+
7+
**Returns**: An instance of the `EmailRetriever` class.
8+
9+
**Description**:
10+
11+
- Initializes an `EmailRetriever` instance with the provided details for email access and retrieval.
12+
- Throws an error if the specified email client is not supported.
13+
14+
**Example**: Instantiate the `EmailRetriever` for a Gmail account with verbose error logging.
15+
16+
```javascript
17+
const retriever = new EmailRetriever(
18+
'your-email@gmail.com',
19+
'your-password',
20+
'gmail',
21+
true
22+
);
23+
```
24+
25+
**Parameters**:
26+
27+
| Parameter Name | Description | Accepted Values/Data Types |
28+
| -------------- | ----------- | --------------------------- |
29+
| emailAddress | The email address of the account to initialize | String |
30+
| emailPassword | The password of the email account | String |
31+
| emailClient | The email client hosting the email address | "gmail" \| "outlook" |
32+
| verbose | Indicates if errors should be printed out | Boolean |
33+
34+
35+
### Method: `getEmailsInFolder()`
36+
37+
**Returns**: A promise that resolves to an array of emails upon successful retrieval or undefined if unsuccessful.
38+
39+
**Description**:
40+
41+
- Fetches emails from a specified folder within the user's email account up to a specified limit.
42+
- If `verbose` is `true`, any errors encountered will be printed to the console.
43+
44+
**Example**: Retrieve the last 10 unseen emails in the Inbox folder.
45+
46+
```javascript
47+
retriever.getEmailsInFolder('Inbox', '10', 'UNSEEN')
48+
.then(emails => {
49+
if (emails) {
50+
console.log('Retrieved Emails:', emails);
51+
} else {
52+
console.log('No emails fetched or an error occurred');
53+
}
54+
})
55+
.catch(error => console.error(error));
56+
```
57+
58+
**Parameters**:
59+
60+
| Parameter Name | Description | Accepted Values/Data Types |
61+
| ------------------ | ----------- | --------------------------- |
62+
| folderName | The name of the folder to scan for emails | String |
63+
| limit | The maximum number of emails to retrieve | String |
64+
| IMAPSearchCommand | The IMAP command to determine which emails to fetch | "ALL" \| "UNSEEN" \| "SEEN" |
65+
66+
67+
---

‎docs/api/firestore.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Firestore Documentation
2+
3+
**Description**: The Firestore class provides a variety of methods to interact with documents and collections in Firebase Firestore. It allows you to filter, add, create, update, and delete documents in Firestore collections, including subcollections.
4+
5+
For each method follow this structure:
6+
7+
### Method: `filterCollectionWithWhereClause(collection, filterKey, filterData, operation)`
8+
9+
**Returns**: An array of documents that match the provided filters.
10+
11+
**Description**:
12+
- Filters a collection using a where clause and returns the resulting documents.
13+
- Throws an error if there is an issue retrieving the documents.
14+
15+
**Example**: Using this method in a larger project to retrieve documents from a "users" collection where the "status" equals "active".
16+
```javascript
17+
const userDocs = await firestoreInstance.filterCollectionWithWhereClause(
18+
"users",
19+
"status",
20+
"active",
21+
"=="
22+
);
23+
```
24+
25+
**Parameters**:
26+
27+
| Parameter Name | Description | Accepted Values/Data Types |
28+
| -------------- | ------------------------------------------- | ------------------------------- |
29+
| collection | The name of the collection to be filtered. | String |
30+
| filterKey | The key/field name to filter by. | String |
31+
| filterData | The value to match for the given filterKey. | String |
32+
| operation | The Firestore query operator. | String (Firestore query operators) |
33+
34+
35+
### Method: `addDocumentToCollection(document, collection)`
36+
37+
**Returns**: An object containing the success status and the ID of the document added.
38+
39+
**Description**:
40+
- Adds a new document to the specified collection.
41+
- If an error occurs, it throws an exception with the error details.
42+
43+
**Example**: Adding a new user object to the "users" collection in Firestore.
44+
```javascript
45+
const addResult = await firestoreInstance.addDocumentToCollection(newUser, "users");
46+
if (addResult.success) {
47+
console.log(`Added document with ID: ${addResult.docID}`);
48+
}
49+
```
50+
51+
**Parameters**:
52+
53+
| Parameter Name | Description | Accepted Values/Data Types |
54+
| -------------- | -------------------------------- | -------------------------- |
55+
| document | The data object of the document. | Object |
56+
| collection | The name of the target collection. | String |
57+
58+
(Note: The documentation template above is applied to only the `filterCollectionWithWhereClause` method and `addDocumentToCollection`. Similar formatting would follow for each method defined within the `Firestore` class itself, but due to the length and number of methods, not all methods have been templated here. Each method should get its own section following the given structure.)

0 commit comments

Comments
 (0)