-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Eroxl/chat
Chat
- Loading branch information
Showing
43 changed files
with
1,846 additions
and
991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node"; | ||
|
||
if (!process.env.MILVUS_URL) { | ||
throw new Error('MILVUS_URL is not defined'); | ||
} | ||
|
||
const EMBEDDING_DIM = 1536; | ||
|
||
const BLOCK_FIELDS = [ | ||
{ | ||
name: 'block_id', | ||
description: 'The ID of the block (Same as the ID of the block in mongoDB)', | ||
data_type: DataType.VarChar, | ||
max_length: 24, | ||
is_primary_key: true, | ||
}, | ||
{ | ||
name: 'page_id', | ||
description: 'The ID of the page that the block belongs to', | ||
max_length: 24, | ||
data_type: DataType.VarChar, | ||
}, | ||
{ | ||
name: 'embedding', | ||
description: 'The embedding of the block (Generated by OpenAI)', | ||
data_type: DataType.FloatVector, | ||
dim: EMBEDDING_DIM, | ||
}, | ||
{ | ||
name: 'content', | ||
description: 'The content of the block', | ||
data_type: DataType.VarChar, | ||
max_length: 1000, | ||
}, | ||
{ | ||
name: 'context', | ||
description: 'The context of the block', | ||
data_type: DataType.VarChar, | ||
max_length: (24 + 2) * 11 + 2, | ||
} | ||
] | ||
|
||
const milvusClient = new MilvusClient( | ||
process.env.MILVUS_URL, | ||
true, | ||
process.env.MILVUS_USERNAME, | ||
process.env.MILVUS_PASSWORD | ||
); | ||
|
||
(async () => { | ||
const doesCollectionExist = await milvusClient.hasCollection({ | ||
collection_name: 'blocks', | ||
}); | ||
|
||
if (doesCollectionExist.status.error_code !== 'Success') { | ||
throw new Error(doesCollectionExist.status.reason); | ||
} | ||
|
||
if (doesCollectionExist.value) return; | ||
|
||
await milvusClient.createCollection({ | ||
collection_name: 'blocks', | ||
description: 'Collection for storing block embeddings', | ||
fields: BLOCK_FIELDS, | ||
}); | ||
|
||
await milvusClient.createIndex({ | ||
collection_name: 'blocks', | ||
field_name: 'embedding', | ||
index_type: 'AUTOINDEX', | ||
index_name: 'embedding_index', | ||
metric_type: 'L2', | ||
}); | ||
})(); | ||
|
||
export default milvusClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Configuration, OpenAIApi } from 'openai'; | ||
|
||
if (!process.env.OPENAI_API_KEY) { | ||
throw new Error('OPENAI_API_KEY is not defined'); | ||
} | ||
|
||
const configuration = new Configuration({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
||
const OpenAIClient = new OpenAIApi(configuration); | ||
|
||
export default OpenAIClient; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.