-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
![image](https://private-user-images.githubusercontent.com/98301/261139470-66a65449-bef0-4368-a4c2-81528fc4861b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE5MzU1ODMsIm5iZiI6MTcyMTkzNTI4MywicGF0aCI6Ii85ODMwMS8yNjExMzk0NzAtNjZhNjU0NDktYmVmMC00MzY4LWE0YzItODE1MjhmYzQ4NjFiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI1VDE5MjEyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNlZTg2ZTMwMTAyYmJiYTNjNDJlY2IyMDg0MDQwZWNiYjc3YjdmYWExYmQwNTg3N2U0YmEyMjI1NDg5ODA2ZWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.3Zv0dB7iLkFCrREU0YaxGeAcIoYqGfz-OKbsdld6Di4)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
-GET
to access a resource or query information
- I think we should use this method for text completion and for s2 search)
-DELETE
to delete a resource (no need to repeat delete in the URL, we should have an URL that identify a resource)
-PATCH
to 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. |
@@ -1,7 +1,7 @@ | |||
import inspect | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 --reload
You 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
return
anything ... which needs to happen for the API).Example usage