Add http endpoints for sidecar functionality#359
Conversation
Codecov Report
@@ Coverage Diff @@
## main #359 +/- ##
==========================================
+ Coverage 84.42% 84.75% +0.33%
==========================================
Files 157 169 +12
Lines 9372 9684 +312
Branches 1022 1056 +34
==========================================
+ Hits 7912 8208 +296
- Misses 1449 1465 +16
Partials 11 11
... and 21 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
danvk
left a comment
There was a problem hiding this comment.
Looks good! Two high-level bits of feedback:
- It would be nice to have some tests
- Does this do validation of request bodies for us?
We'll want to get these endpoints into our codegen setup but that can be in a follow-up PR.
Also I'm seeing this error when I try to use the GET /ingest/references endpoint:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
There was a problem hiding this comment.
Agree with Dan's comments.
We should have a distinct entry point for the HTTP server (from the cli/sidecar).
I see the backend for HTTP to translate http parameters (body, querystring) and call the internal functions that return a value. Then, that value is sent back to the client serialized as JSON.
For the CLI application interface, I see the app receiving requests in JSON (...Request) and also call the internal function that return a value. Then is the responsibility of the CLI to translate that to a sys.stdout.write(response.json()) reply.
The HTTP endpoints should also be adjusted to:
- use the first segment to scope the different backend scopes:
- references (ingestion, status, edit, delete, ...),
- ai (completion, chat)
- search (s2) - adopt the best HTTP method
-GETto access a resource or query information
- I think we should use this method for text completion and for s2 search)
-DELETEto delete a resource (no need to repeat delete in the URL, we should have an URL that identify a resource)
-PATCHto partially update a reference
Alternatively, if we want to mimic the sidecar request/reply method of sending a JSON payload and receiving a JSON payload, we should only use POST to a api/v0/sidecar/... endpoint.
We also need to discuss how the settings (ex: OPENAI_API_KEY) are sent/accessible in the HTTP server. We know that the setting is configured by the client.
@cguedes I agree with this approach, though it's a fairly sizable refactor (mainly the tests) that I think would be distracting in this PR. I'll add it as a follow up. |
| import json | ||
|
|
||
| from sidecar import chat, cli, ingest, rewrite, storage, search | ||
| from sidecar import chat, cli, ingest, rewrite, search, storage |
There was a problem hiding this comment.
Not necessary for this PR, but is there a linter/formatter that's not running as part of CI?
There was a problem hiding this comment.
Honestly, this is something my vs-code only does for refstudio and I haven't been able to figure out why
There was a problem hiding this comment.
I had thought it might have been due to prettier integration, but seems not
part of #347
Running this PR
cd refstudio/python poetry run uvicorn web:api --reloadYou should then be able to visit http://127.0.0.1:8000/api/v0/docs in your browser and test various endpoints. Not all of them have been implemented yet, and some need some slight changes due to the way the current sidecar works (i.e. since we communicate via stdout, maybe of the existing sidecar functions do not
returnanything ... which needs to happen for the API).Example usage