Skip to content

Commit

Permalink
Merge pull request #104 from vintasoftware/fix/readme
Browse files Browse the repository at this point in the history
Dedicated README for example and fix package.json for npm link
  • Loading branch information
fjsj authored Jun 20, 2024
2 parents 285f862 + cf99a96 commit 85ebea5
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 62 deletions.
63 changes: 15 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
88 changes: 88 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -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/`.

7 changes: 1 addition & 6 deletions example/demo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 4 additions & 6 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit 85ebea5

Please sign in to comment.