diff --git a/README.md b/README.md index 048a666..d572eaf 100644 --- a/README.md +++ b/README.md @@ -19,70 +19,37 @@ You can use [pyenv](https://github.com/pyenv/pyenv), [pipenv](https://github.com [NVM](https://github.com/nvm-sh/nvm) -### Install vite - -`npm install -g vite` or install locally if you prefer - -### Create a .env file at the root of the project - -`cp .env.example .env` - -To gather the API keys for these tools, head to the following links: -- [OpenAI](https://platform.openai.com/api-keys) -- [Weather](https://www.weatherapi.com/) -- [Tavily](https://app.tavily.com/home) -- [Firecrawl](https://www.firecrawl.dev/) - -### Build the frontend - -`cd frontend` - -`vite build` - -### Create a .env file at the example folder - -`cd example` - -`cp .env.example .env` - ### Install dependencies #### Backend -`cd example` - `poetry install` -Install pre-commit hooks: - -`pre-commit install` - #### Frontend -`cd example` - -`npm install` - -### Run the project - -From the example folder: - -#### Frontend +```bash +cd frontend +npm install +``` -`npm run start` +### Install pre-commit hooks -#### Backend +`pre-commit install` -`python manage.py migrate` +### Log in to Django Admin -`python manage.py createsuperuser` +Go to /admin and log in with your superuser account. -`python manage.py runserver` +## Developing with the example project -### Log in to Django Admin +Run the frontend project in build:watch mode: -Go to /admin and log in with your superuser account. +```bash +cd frontend +npm run build:watch +``` +Then follow the instructions in the [example README](example/README.md). ## Contributing diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..2112f70 --- /dev/null +++ b/example/README.md @@ -0,0 +1,88 @@ +# Example + +Django AI Assistant examples. This is a Django project that integrates with Django AI Assistant library. + +Most examples are inside a React frontend, but there is also a HTMX example. + +## Installation + +Go to project root, then frontend dir and build the frontend library: + +```bash +cd .. # back to project root directory +cd frontend +npm install +npm run build +``` + +Then use `npm link` to link the frontend library to the example project: + +```bash +cd frontend +npm link +``` + +Go to the example project to finish the link with the frontend library: + +```bash +cd .. # back to project root directory +cd example +npm link django-ai-assistant-client +``` + +Run the example Webpack devserver to build the React frontend: + +```bash +# in example directory +npm install +npm run start +``` + +Install the example project Python dependencies: + +```bash +cd .. # back to project root directory +poetry install +``` + +Create a `.env` file at the example directory: + +```bash +# in example directory +cp .env.example .env +``` + +Fill the `.env` file with the necessary API keys. You'll need accounts on: + +- [OpenAI](https://platform.openai.com/) +- [Weather](https://www.weatherapi.com/) +- [Tavily](https://app.tavily.com/) +- [Firecrawl](https://www.firecrawl.dev/) + +Run Django migrations: + +```bash +# in example directory +python manage.py migrate +``` + +Create a superuser: + +```bash +# in example directory +python manage.py createsuperuser +``` + +Run the Django server: + +```bash +# in example directory +python manage.py runserver +``` + +Access the Django admin at `http://localhost:8000/admin/` and log in with the superuser account. + +## Usage + +Access the example project at `http://localhost:8000/`. + diff --git a/example/demo/views.py b/example/demo/views.py index 13ac0cf..58d5242 100644 --- a/example/demo/views.py +++ b/example/demo/views.py @@ -29,12 +29,7 @@ def get_assistant_id(self, **kwargs): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - threads = list( - get_threads( - user=self.request.user, - request=self.request, - ) - ) + threads = list(get_threads(user=self.request.user)) context.update( { "assistant_id": self.get_assistant_id(**kwargs), diff --git a/example/package-lock.json b/example/package-lock.json index c350159..0e74ca7 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -12,7 +12,6 @@ "@mantine/hooks": "^7.9.2", "@tabler/icons-react": "^3.4.0", "cookie": "^0.6.0", - "django-ai-assistant-client": "file:../frontend", "modern-normalize": "^2.0.0", "react-markdown": "^9.0.1", "react-router-dom": "^6.23.1" @@ -49,14 +48,17 @@ "../frontend": { "name": "django-ai-assistant-client", "version": "0.0.1", + "extraneous": true, "license": "MIT", "dependencies": { - "axios": "^1.7.2" + "axios": "^1.7.2", + "cookie": "^0.6.0" }, "devDependencies": { "@hey-api/openapi-ts": "^0.46.3", "@testing-library/dom": "^10.1.0", "@testing-library/react": "^16.0.0", + "@types/cookie": "^0.6.0", "@types/jest": "^29.5.12", "@types/node": "^20.14.1", "@types/react": "^18.3.3", @@ -4445,10 +4447,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/django-ai-assistant-client": { - "resolved": "../frontend", - "link": true - }, "node_modules/dns-packet": { "version": "5.6.1", "dev": true, diff --git a/example/package.json b/example/package.json index fd6c27d..6ec3487 100644 --- a/example/package.json +++ b/example/package.json @@ -43,9 +43,8 @@ "@mantine/hooks": "^7.9.2", "@tabler/icons-react": "^3.4.0", "cookie": "^0.6.0", - "django-ai-assistant-client": "file:../frontend", "modern-normalize": "^2.0.0", "react-markdown": "^9.0.1", "react-router-dom": "^6.23.1" } -} +} \ No newline at end of file