-
Notifications
You must be signed in to change notification settings - Fork 1
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
Creating endpoint with CRUD for documents and chunks #97
Conversation
@bafaurazan next time - please remember commits are formatted like this
please, fix the commit message, here's how: https://stackoverflow.com/a/41987851 |
P.S. when you're ready, remember to select reviewers - I've seen this PR only because I watch all the events in the repo |
4a277eb
to
3ed9e55
Compare
I added file views.py that have declared types of response for client's CRUD request like( GET,POST,PUT,DEL) for chunks and documents, other files exclude .env.example have declared model shemas, url and routing. I think document's response for CRUD is incorect, because i didn't use foreignkey.
3ed9e55
to
dd41b75
Compare
I additionally renamed folder containing models for code readability from documents into MyModels
In new version of PUT method, client can update objects declaring in request only variables that he want change (no all variables needed).
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.
will CR this properly on saturday/sunday, currently naming is kinda wonky & I think chunks and documents should be separate "django apps"
I separated models creating similar chunks folder to documents folder and connect them using routers in api.api file
api/Dockerfile
Outdated
RUN manage.py collectstatic | ||
|
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.
question: 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 get error message because of this:
i'm propably wrong but in my opinion command should looks like: " RUN python manage.py collectstatic", but then i get another error, because (i think) i can't get data contained in .env file
so i cant currently use this command and temporarily deleted them
if you can, correct me if i'am wrong
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.
it doesn't work, because
- you didn't change workdir in the target stage
- you have to use relative path, unlike on windows, linux treats
SOME_COMMAND
as thing present in PATH and current working directory IS NOT automatically added to path, hence you have to use./manage.py
instead
api/chunks/models.py
Outdated
text = models.CharField(max_length=100) | ||
embedding = VectorField(dimensions=10) | ||
chunk_idx = models.IntegerField() | ||
start_char = models.IntegerField() | ||
end_char = models.IntegerField() |
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.
issue: please add typing, it looks something like this
text = models.CharField[str, str](max_length=100)
note that you have to add type twice, because it's input/output
In this commit i add: - annotations (i don't know if this is correct) - simple tests (i know that i can't do tests on main database, but i don't know how to do it work with test database (how to add extension with pgvector to test database)) P.S. I type following command to run tests: docker compose exec api python manage.py test --keepdb - i create files: documents/controllers.py and chunks/controllers.py and defined logic in them that is used by views.py.
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 didn't duplicate issues, so search the rest of the code for similar cases when resolving
api/api/settings.py
Outdated
"TEST": { | ||
"NAME": env("POSTGRES_DB"), | ||
}, | ||
}, |
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.
question: What is this for?
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.
api/chunks/models.py
Outdated
text: Tuple[str, str] = models.CharField(max_length=100) | ||
embedding: Tuple[list[float], VectorField] = VectorField(dimensions=10) | ||
chunk_idx: Tuple[int, int] = models.IntegerField() | ||
start_char: Tuple[int, int] = models.IntegerField() | ||
end_char: Tuple[int, int] = models.IntegerField() |
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.
issue: This is not correct, see my previous comment. It may help you to set pyright to strict
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.
but your suggestion, didn't work for models, that's why i changed it. The only way i can see is somethinkg like this text: str = models.CharField(max_length=100)
api/documents/models.py
Outdated
class Document(models.Model): | ||
text = models.TextField() | ||
embedding = VectorField(dimensions=10) | ||
chunks = models.ForeignKey(Chunk, on_delete=models.CASCADE, null=True, blank=True) | ||
text: Tuple[str, str] = models.TextField() | ||
embedding: Tuple[list[float], VectorField] = VectorField(dimensions=10) | ||
chunks: Tuple[int, int] = models.ForeignKey(Chunk, on_delete=models.CASCADE, null=True, blank=True) |
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.
Incorrect typing
and Patryk if you could send me some links, that could help me solve the problems with the code, it would help me a lot |
should I add pyrightconfig.json file to the project to define how pyright should work? |
Co-authored-by: Patryk Gronkiewicz <[email protected]>
I added file views.py that have declared types of response for client's CRUD request like( GET,POST,PUT,DEL) for chunks and documents, other files exclude .env.example have declared model schemas, url and routing. I think document's response for CRUD is incorect, because i didn't use foreignkey in document's schemas.
Code based on this site: https://medium.com/@hbakri/introducing-django-ninja-crud-ee937bd2ea65