Open ofalvai opened 1 month ago
Note: I know there are other Obsidian plugins out there using the Anthropic API with streaming, so I checked one. This one solves the CORS issue in a different way, by running a proxy server with Node.js: https://github.com/logancyang/obsidian-copilot/blob/master/src/proxyServer.ts#L18
requestUrl
does not support response streaming.
Can you give me some pointers how requestUrl()
behaves in the desktop Obsidian app (my plugin is desktop only). What makes it work this way, and is there any way for me to work around it? I assume this function delegates to one of the Node HTTP APIs, can I rely on that as long as I'm only targeting the desktop app?
It's being delegated to the net.request Electron API.
The reasons requestUrl
does not support streaming is mobile, it's a lot more complicated to do that with Capacitor.
If your plugin is "desktopOnly" then you can use the Node API.
I'm using Obsidian's
requestUrl()
helper to bypass CORS restrictions. The API I'm calling is Anthropic's standard chat API that streams AI response chunks using server-sent events. I'm only focusing on desktop only for now, so I assumerequestUrl()
calls a Node.js or Electron networking API.I noticed that even though I have a working API request, the timing of events doesn't feel right.
Given this code (which I tried to make as short as possible, sorry!):
...what I see is that
await requestUrl()
blocks until the last server-sent event is received. In practice, streaming the response chunks doesn't feel any different than using the non-streaming API because the entire response appears at once (after a long delay).I don't think this is a problem with the
fetch-event-stream
wrapper because the blocking happens earlier, between the log linesBefore requestUrl
andAfter requestUrl
. The remaining log lines appear instantly and at the same time.I'm not sure this is a bug in itself, maybe I'm doing something wrong here? I would appreciate any help or guidance about how to use
requestUrl()
or what it's doing behind the scenes. Thank you!