Skip to content

Commit

Permalink
2.18.6: fix: pull file content locally for Ava Ask
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Feb 24, 2023
1 parent b72da14 commit b6f5bd7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "ava",
"name": "🧙 AVA",
"version": "2.18.5",
"version": "2.18.6",
"minAppVersion": "0.12.0",
"description": "AI assistant for Obsidian",
"author": "louis030195",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ava",
"version": "2.18.5",
"version": "2.18.6",
"description": "AI assistant for Obsidian",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ export default class AvaPlugin extends Plugin {
this.settings.token,
this.settings.vaultId,
this.manifest.version,
app,
)
);
this.streamingSource.addEventListener(
Expand Down
15 changes: 8 additions & 7 deletions src/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { complete, search } from "./utils";
import { App } from "obsidian";
import { complete, getCompleteFiles, 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);
export const createContext = async (question: string, token: string, vaultId: string, version: string, app: App) => {
const [searchResponse, files] = await Promise.all([search(question, token, vaultId, version), getCompleteFiles(app)]);
let curLen = 0;
const returns = [];
for (const similarity of searchResponse["similarities"]) {
const sentence = similarity["data"];
const sentence = files.find((file) => file.path === similarity["id"])?.content;
// const nTokens = enc.encode(sentence).length;
const nChars = sentence.length;
const nChars = sentence?.length || 0;
// curLen += nTokens + 4;
curLen += nChars;
if (curLen > maxLen) {
Expand All @@ -24,8 +25,8 @@ export const createContext = async (question: string, token: string, vaultId: st
// 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);
export const generativeSearch = async (question: string, token: string, vaultId: string, version: string, app: App) => {
const context = await createContext(question, token, vaultId, version, app);
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, {
Expand Down
2 changes: 0 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ export const complete = async (
): Promise<any | string> => {
// TODO: back-end
prompt = prompt.trim();
console.log('Prompt:', prompt);
const stream = options?.stream !== undefined ? options?.stream : true;
console.log('Options:', options, 'Stream:', stream);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body: any = {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@
"2.17.3": "0.12.0",
"2.18.3": "0.12.0",
"2.18.4": "0.12.0",
"2.18.5": "0.12.0"
"2.18.5": "0.12.0",
"2.18.6": "0.12.0"
}

0 comments on commit b6f5bd7

Please sign in to comment.