-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port JS chat code over from chat-stream
- Loading branch information
Showing
25 changed files
with
2,289 additions
and
833 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,7 @@ $RECYCLE.BIN/ | |
|
||
.vscode | ||
/samconfig.toml | ||
/samconfig.yaml | ||
/env.json | ||
/env.*.json | ||
/*.parameters | ||
|
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
cd node && npm run lint && npm run prettier && cd - | ||
cd python && ruff check . && cd - |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
nodejs 16.14.0 | ||
nodejs 18.16.1 | ||
java corretto-19.0.1.10.1 | ||
python 3.9.17 |
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,79 @@ | ||
const { WeaviateStore } = require("langchain/vectorstores/weaviate"); | ||
const { Document } = require("langchain/document"); | ||
|
||
class EmbeddedWeaviateStore extends WeaviateStore { | ||
constructor(...args) { | ||
super(...args); | ||
} | ||
|
||
async similaritySearch(query, k = 4, filter = undefined) { | ||
try { | ||
let builder = await this.client.graphql | ||
.get() | ||
.withClassName(this.indexName) | ||
.withFields(this.queryAttrs.join(" ")) | ||
.withNearText({ | ||
concepts: [query], | ||
}) | ||
.withLimit(k); | ||
|
||
if (filter?.where) { | ||
builder = builder.withWhere(filter.where); | ||
} | ||
|
||
const result = await builder.do(); | ||
|
||
const documents = []; | ||
for (const data of result.data.Get[this.indexName]) { | ||
const { [this.textKey]: text, ...rest } = data; | ||
|
||
documents.push( | ||
new Document({ | ||
pageContent: text, | ||
metadata: rest, | ||
}) | ||
); | ||
} | ||
return documents; | ||
} catch (e) { | ||
throw Error(`'Error in similaritySearch' ${e}`); | ||
} | ||
} | ||
|
||
async similaritySearchWithScore(query, k = 4, filter = undefined) { | ||
try { | ||
let builder = await this.client.graphql | ||
.get() | ||
.withClassName(this.indexName) | ||
.withFields(`${this.queryAttrs.join(" ")} _additional { distance }`) | ||
.withNearText({ | ||
concepts: [query], | ||
}) | ||
.withLimit(k); | ||
|
||
if (filter?.where) { | ||
builder = builder.withWhere(filter.where); | ||
} | ||
|
||
const result = await builder.do(); | ||
|
||
const documents = []; | ||
for (const data of result.data.Get[this.indexName]) { | ||
const { [this.textKey]: text, _additional, ...rest } = data; | ||
|
||
documents.push([ | ||
new Document({ | ||
pageContent: text, | ||
metadata: rest, | ||
}), | ||
_additional.distance, | ||
]); | ||
} | ||
return documents; | ||
} catch (e) { | ||
throw Error(`'Error in similaritySearch' ${e}`); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { EmbeddedWeaviateStore }; |
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,23 @@ | ||
const { wrap } = require("./middleware"); | ||
const Honeybadger = require("../honeybadger-setup"); | ||
|
||
/** | ||
* ChatEndpoint - Returns the function URL of the streaming chat handler | ||
*/ | ||
exports.handler = wrap(async (event) => { | ||
try { | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
url: process.env.CHAT_ENDPOINT, | ||
auth: event.userToken.sign(), | ||
}), | ||
}; | ||
} catch (error) { | ||
await Honeybadger.notifyAsync(error); | ||
return { | ||
statusCode: 401, | ||
body: "Error: " + error.message, | ||
}; | ||
} | ||
}); |
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.