-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
424 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.12.3 | ||
3.12.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,37 @@ Please follow this guide to learn more about how to develop and test the project | |
git clone [email protected]:vintasoftware/django-ai-assistant.git | ||
``` | ||
|
||
### Set up a virtualenv, optionally set up nvm, and activate your environment(s) | ||
### Install development tools | ||
|
||
You can use [pyenv](https://github.com/pyenv/pyenv), [pipenv](https://github.com/pypa/pipenv/blob/main/docs/installation.md), vanilla venvs or the tool of your choice. | ||
This project uses [Poetry](https://python-poetry.org/docs/) for dependency and virtual environment management. | ||
|
||
If you need to install the version of Python recommended for the project, you can use [Pyenv](https://github.com/pyenv/pyenv). | ||
|
||
For installing Node, we recommend [NVM](https://github.com/nvm-sh/nvm). | ||
|
||
### Install dependencies | ||
|
||
#### Backend | ||
|
||
Go to the project root and install the Python dependencies: | ||
Go to the project root. To instantiate the virtual environment, run | ||
|
||
```bash | ||
poetry shell | ||
``` | ||
|
||
Install the Python dependencies: | ||
|
||
```bash | ||
poetry install | ||
``` | ||
|
||
If you encounter an error regarding the Python version required for the project, you can use pyenv to install the appropriate version based on [.python-version](.python-version): | ||
|
||
```bash | ||
pyenv install | ||
``` | ||
|
||
|
||
#### Frontend | ||
|
||
Go to the frontend directory and install the Node dependencies: | ||
|
@@ -68,6 +83,12 @@ Then follow the instructions in the [example README](https://github.com/vintasof | |
|
||
## Tests | ||
|
||
Before running tests copy the `.env.example` file to `.env.tests`. | ||
|
||
```bash | ||
cp .env.example .env.tests | ||
``` | ||
|
||
Run tests with: | ||
|
||
```bash | ||
|
@@ -76,7 +97,8 @@ poetry run pytest | |
|
||
The tests use `pytest-vcr` to record and replay HTTP requests to AI models. | ||
|
||
If you're implementing a new test that needs to call a real AI model, you need to set the `OPENAI_API_KEY` environment variable on root `.env` file. | ||
If you're implementing a new test that needs to call a real AI model, you need to set the `OPENAI_API_KEY` environment variable with a real API key in the `.env.tests` file. | ||
|
||
Then, you will run the tests in record mode: | ||
|
||
```bash | ||
|
@@ -102,10 +124,19 @@ poetry run mkdocs serve | |
To release and publish a new version, follow these steps: | ||
|
||
1. Update the version in `pyproject.toml` and `frontend/package.json`. | ||
2. In the project root, run `poetry run python manage.py generate_openapi_schema --output frontend/openapi_schema.json` to update the OpenAPI schema. | ||
3. In the frontend directory, run `pnpm run generate-client` to update the TypeScript client with the new OpenAPI schema. | ||
4. Update the changelog in `CHANGELOG.md`. | ||
5. Open a PR with the changes. | ||
6. Once the PR is merged, run the [Release GitHub Action](https://github.com/vintasoftware/django-ai-assistant/actions/workflows/release.yml) to create a draft release. | ||
7. Review the draft release, ensure the description has at least the associated changelog entry, and publish it. | ||
8. Once the review is publish, the [Publish GitHub Action](https://github.com/vintasoftware/django-ai-assistant/actions/workflows/publish.yml) will automatically run to publish the new version to [PyPI](https://pypi.org/project/django-ai-assistant) and [npm](https://www.npmjs.com/package/django-ai-assistant-client). Check the logs to ensure the publication was successful. | ||
2. Re-install the local version of the Python project: `poetry install` | ||
3. In the project root, run `poetry run python manage.py generate_openapi_schema --output frontend/openapi_schema.json` to update the OpenAPI schema. | ||
4. Re-install the local version of the frontend project: | ||
|
||
```bash | ||
cd frontend | ||
pnpm install | ||
pnpm run build | ||
``` | ||
|
||
5. In the frontend directory, run `pnpm run generate-client` to update the TypeScript client with the new OpenAPI schema. | ||
6. Update the changelog in `CHANGELOG.md`. | ||
7. Open a PR with the changes. | ||
8. Once the PR is merged, run the [Release GitHub Action](https://github.com/vintasoftware/django-ai-assistant/actions/workflows/release.yml) to create a draft release. | ||
9. Review the draft release, ensure the description has at least the associated changelog entry, and publish it. | ||
10. Once the review is published, the [Publish GitHub Action](https://github.com/vintasoftware/django-ai-assistant/actions/workflows/publish.yml) will automatically run to publish the new version to [PyPI](https://pypi.org/project/django-ai-assistant) and [npm](https://www.npmjs.com/package/django-ai-assistant-client). Check the logs to ensure the publication was successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,58 @@ | ||
from typing import ClassVar, List, Type | ||
|
||
from django.contrib import admin | ||
from django.contrib.admin.options import InlineModelAdmin | ||
from django.urls import reverse | ||
from django.utils.safestring import mark_safe | ||
|
||
from django_ai_assistant.models import Message, Thread | ||
|
||
|
||
class MessageInline(admin.TabularInline): | ||
model = Message | ||
extra = 0 | ||
fields = ("pk", "message_type", "content", "created_at") | ||
readonly_fields = fields | ||
ordering = ("created_at",) | ||
show_change_link = True | ||
|
||
def pk(self, obj): | ||
display_text = "<a href={}>{}</a>".format( | ||
reverse( | ||
f"admin:{Message._meta.app_label}_{Message._meta.model_name}_change", args=(obj.pk,) | ||
), | ||
obj.pk, | ||
) | ||
return mark_safe(display_text) # noqa: S308 | ||
|
||
def message_type(self, obj): | ||
return obj.message.get("type") if obj.message else None | ||
|
||
def content(self, obj): | ||
return obj.message.get("data", {}).get("content") if obj.message else None | ||
|
||
def has_add_permission(self, request, obj=None): | ||
return False | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
return False | ||
|
||
def has_change_permission(self, request, obj=None): | ||
return False | ||
|
||
|
||
@admin.register(Thread) | ||
class ThreadAdmin(admin.ModelAdmin): | ||
list_display = ("name", "created_at", "created_by", "updated_at") | ||
search_fields = ("name",) | ||
list_filter = ("created_at", "updated_at") | ||
raw_id_fields = ("created_by",) | ||
inlines: ClassVar[List[Type[InlineModelAdmin]]] = [MessageInline] | ||
|
||
|
||
@admin.register(Message) | ||
class MessageAdmin(admin.ModelAdmin): | ||
list_display = ("id", "thread", "created_at", "created_at") | ||
list_display = ("id", "thread", "created_at") | ||
search_fields = ("thread__name", "message") | ||
list_filter = ("created_at",) | ||
raw_id_fields = ("thread",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.