Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
justyns committed Feb 27, 2024
1 parent 37cfef9 commit a71264b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ The list below are the commands available in this plugin.
<!-- start-commands-and-functions -->
- **AI: Summarize Note and open summary**: Uses a built-in prompt to ask the LLM for a summary of either the entire note, or the selected
text. Opens the resulting summary in a temporary right pane.
- **AI: Insert Summary**: Uses a built-in prompt to ask the LLM for a summary of either the entire note, or the selected
text. Inserts the summary at the cursor's position.
- **AI: Call OpenAI with Note as context**: Prompts the user for a custom prompt to send to the LLM. If the user has text selected, the selected text is used as the note content.
If the user has no text selected, the entire note is used as the note content.
The response is streamed to the cursor position.
Expand Down
4 changes: 0 additions & 4 deletions silverbullet-ai.plug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ functions:
path: sbai.ts:openSummaryPanel
command:
name: "AI: Summarize Note and open summary"
insertSummary:
path: sbai.ts:insertSummary
command:
name: "AI: Insert Summary"
callOpenAI:
path: sbai.ts:callOpenAIwithNote
command:
Expand Down
9 changes: 7 additions & 2 deletions src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class OpenAIProvider extends AbstractProvider {
}
}

async streamChat(options: StreamChatOptions): Promise<void> {
async streamChat(options: StreamChatOptions): Promise<string> {
const { messages, onDataReceived } = options;

try {
Expand All @@ -70,15 +70,17 @@ export class OpenAIProvider extends AbstractProvider {
};

const source = new SSE(sseUrl, sseOptions);
let fullMsg = "";

source.addEventListener("message", function (e) {
try {
if (e.data == "[DONE]") {
source.close();
return fullMsg;
} else {
const data = JSON.parse(e.data);
const msg = data.choices[0]?.delta?.content || "";
// TODO: Send msg to a callback that should be registered to the interface
fullMsg += msg;
if (onDataReceived) {
onDataReceived(msg);
}
Expand All @@ -90,6 +92,7 @@ export class OpenAIProvider extends AbstractProvider {

source.addEventListener("end", function () {
source.close();
return fullMsg;
});

source.stream();
Expand All @@ -101,6 +104,7 @@ export class OpenAIProvider extends AbstractProvider {
);
throw error;
}
return "";
}

async nonStreamingChat(messages: Array<ChatMessage>): Promise<void> {
Expand Down Expand Up @@ -146,6 +150,7 @@ export class OpenAIProvider extends AbstractProvider {
}
}

// TODO: Make an interface for image generating models too
export async function generateImageWithDallE(
prompt: string,
n: 1,
Expand Down

0 comments on commit a71264b

Please sign in to comment.