Skip to content

Commit

Permalink
Fix ts error and bump up version
Browse files Browse the repository at this point in the history
  • Loading branch information
crybot committed May 28, 2024
1 parent 76df544 commit b56efd8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "flashcards-llm",
"name": "Flashcards LLM",
"version": "0.0.8",
"version": "0.0.9",
"minAppVersion": "0.15.0",
"description": "Use Large Language Models (such as ChatGPT) to automatically generate flashcards from obsidian notes",
"author": "Marco Pampaloni",
Expand Down
5 changes: 5 additions & 0 deletions src/flashcards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { availableChatModels, availableCompletionModels } from "./models";
import { OpenAI } from 'openai';
import { Readable } from "stream";



// TODO:
Expand Down Expand Up @@ -35,6 +37,7 @@ function multilineCardsPrompt(sep: string, flashcardsCount: number): string {
return `You will be provided with a note. At the end of the note are some flashcards. Identify which are the most important concepts within the note and generate exactly ${flashcardsCount} new original flashcard in the format \"question<newline>${sep}<newline>answer\", where <newline> is a newline. The question cannot start with special symbols or numbers. Do not add trailing spaces. Separate invidivual flashcards with a single empty line. An example is \"What is chemical formula of water\\n${sep}\\nH2O\". Do not use any prefix text, start generating right away. The flashcards can be as complex as needed, but have to be rich of information and challenging. Do not repeat or rephrase flashcards. Typeset equations and math formulas correctly (that is using the \$ symbol without trailing spaces)`;
}


export async function* generateFlashcards(
text: string,
apiKey: string,
Expand Down Expand Up @@ -80,10 +83,12 @@ export async function* generateFlashcards(
}, { timeout: 60000 });

if (!stream) {
response = response as OpenAI.ChatCompletion
response = response?.choices[0]?.message?.content?.trim() ?? null;
yield response || '';
}
else {
response = response as AsyncIterable<OpenAI.ChatCompletionChunk>
for await (const chunk of response) {
yield chunk.choices[0]?.delta?.content || '';
}
Expand Down

0 comments on commit b56efd8

Please sign in to comment.