forked from different-ai/obsidian-ava
-
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.
2.18.4: feat: Ask your vault questions with the command Ava Ask
- Loading branch information
1 parent
246b42f
commit 8250938
Showing
8 changed files
with
148 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,34 @@ | ||
import { complete, search } from "./utils"; | ||
|
||
// TODO: make it work on browser | ||
// import { merge } from 'embeddings-splitter'; | ||
const maxLen = 1800; // TODO: probably should be more with string length | ||
// TODO: very experimental | ||
export const createContext = async (question: string, token: string, vaultId: string, version: string) => { | ||
const searchResponse = await search(question, token, vaultId, version); | ||
let curLen = 0; | ||
const returns = []; | ||
for (const similarity of searchResponse["similarities"]) { | ||
const sentence = similarity["data"]; | ||
// const nTokens = enc.encode(sentence).length; | ||
const nChars = sentence.length; | ||
// curLen += nTokens + 4; | ||
curLen += nChars; | ||
if (curLen > maxLen) { | ||
break; | ||
} | ||
returns.push(sentence); | ||
} | ||
return returns.join("\n\n###\n\n"); | ||
// return output; | ||
// return merge(searchResponse["similarities"].map((similarity) => similarity["data"])); | ||
} | ||
|
||
export const generativeSearch = async (question: string, token: string, vaultId: string, version: string) => { | ||
const context = await createContext(question, token, vaultId, version); | ||
const newPrompt = `Answer the question based on the context below, and if the question can't be answered based on the context, say "I don't know"\n\nContext: ${context}\n\n---\n\nQuestion: ${question}\nAnswer:`; | ||
console.log('generativeSearch', newPrompt); | ||
return complete(newPrompt, token, version, { | ||
stream: true, | ||
}); | ||
}; |
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