Skip to content

Commit

Permalink
Merge pull request #467 from cheshire-cat-ai/develop
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
pieroit authored Sep 27, 2023
2 parents a1262d3 + c26f020 commit a24934a
Show file tree
Hide file tree
Showing 49 changed files with 1,525 additions and 1,309 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ CORE_PORT=1865

# Log levels
LOG_LEVEL=WARNING

# Turn on memory collections' snapshots on embedder change with SAVE_MEMORY_SNAPSHOTS=true
SAVE_MEMORY_SNAPSHOTS=false
61 changes: 30 additions & 31 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
name: Cheshire-Cat Action on Pull Requests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
branches:
- "main"
- "develop"
branches: [main, develop]
push:
branches:
- "main"
- "develop"
branches: [main, develop]

jobs:
pylint:
name: "Coding Standards"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./core
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Download
uses: actions/checkout@v3
- name: Prepare Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: pyproject.toml
- name: Download python dependencies
run: pip install .[dev]
- name: Pylint
run: pylint -f actions ./

# pylint:
# name: "Coding Standards"
# runs-on: ubuntu-latest
# defaults:
# run:
# working-directory: ./core
# strategy:
# matrix:
# python-version: ["3.10"]
# steps:
# - name: Download
# uses: actions/checkout@v3
# - name: Prepare Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# cache: 'pip'
# cache-dependency-path: pyproject.toml
# - name: Download python dependencies
# run: pip install .[dev]
# - name: Pylint
# run: pylint -f actions ./
test:
needs: [ pylint ]
# needs: [ pylint ]
name: "Run Tests"
runs-on: 'ubuntu-latest'

steps:
- uses: actions/checkout@v2
- name: Cat up
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ concurrency:

on:
push:
branches:
- "main"
branches: [main]

permissions:
contents: write
Expand Down
54 changes: 13 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,21 @@

<br/>
<img src="./readme/cheshire_cat_generated_mj.jpeg" alt="Logo" width="600" height="auto" alt="Image generated by Midjourney, prompted by Edgars Romanovskis">
<h4>
Customizable AI architecture
</h4>
</div>

[![Try in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/cheshire-cat-ai/core)

## What is this?
## Production ready AI assistant framework

The Cheshire Cat is a framework to build custom AIs on top of any language model.
If you ever used systems like WordPress or Django to build web apps, imagine the Cat as a similar tool, but specific for AI.

Why use the Cat:
- 🌍 Language model agnostic (works with OpenAI, Cohere, HuggingFace models, custom)
- 🐘 Long term memory
- 🚀 Extensible via plugins
- 🔧 Can use external tools (APIs, custom python code, other models)
- 📄 Can ingest documents (.pdf, .txt, .md)
- 🐋 100% [dockerized](https://docs.docker.com/get-docker/)
- 👩‍👧‍👦 Active [Discord community](https://discord.gg/bHX5sNFCYU)
- 🌍 Supports any language model (works with OpenAI chatGPT, LLAMA2, HuggingFace models, custom)
- 🐘 Rememebers conversations and documents and uses them in conversation
- 🚀 Extensible via plugins (AI can connect to your APIs or execute custom python code)
- 🐋 Production Ready - 100% [dockerized](https://docs.docker.com/get-docker/)
- 👩‍👧‍👦 Active [Discord community](https://discord.gg/bHX5sNFCYU) and easy to understand [docs](https://cheshire-cat-ai.github.io/docs/)

If you want to know more about our vision and values, read the [Code of Ethics](./readme/CODE-OF-ETHICS.md). We are committed to openness, privacy and creativity, we want to bring AI to the long tail.
We are committed to openness, privacy and creativity, we want to bring AI to the long tail. If you want to know more about our vision and values, read the [Code of Ethics](./readme/CODE-OF-ETHICS.md).

This project is growing fast, refactorings and code changes happens very often, join the [Issues](https://github.com/cheshire-cat-ai/core/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) to help!

Expand All @@ -58,7 +51,7 @@ This project is growing fast, refactorings and code changes happens very often,

### Install

To make Cheshire Cat run on your machine, you just need [`docker`](https://docs.docker.com/get-docker/) and [`docker-compose`](https://docs.docker.com/compose/install/) installed.
To make Cheshire Cat run on your machine, you just need [`docker`](https://docs.docker.com/get-docker/) and [`docker compose`](https://docs.docker.com/compose/install/) installed.
Clone the repo:

```bash
Expand All @@ -74,11 +67,9 @@ cd cheshire-cat
After that you can run:

```bash
docker-compose up
docker compose up
```

> NOTE: if you have a later version of docker-compose, use the command `docker compose up` (without the dash). [REF.](https://stackoverflow.com/questions/66514436/difference-between-docker-compose-and-docker-compose)
The first time (only) it will take several minutes, as the images occupy a few GBs.

- Chat with the Cheshire Cat on [localhost:1865/admin](http://localhost:1865/admin).
Expand All @@ -91,18 +82,18 @@ Enjoy the Cat!

When you're done, remember to CTRL+c in the terminal and
```
docker-compose down
docker compose down
```

### Update

From time to time it is a good idea to update the Cat:

```
docker-compose down
docker compose down
git pull origin main
docker-compose build --no-cache
docker-compose up
docker compose build --no-cache
docker compose up
```

### Running Tests
Expand All @@ -113,31 +104,12 @@ To run the tests within the Docker container, execute the following command:
docker exec cheshire_cat_core python -m pytest --color=yes .
```

If you are running the tests locally on your machine, use the following command:

```bash
python -m pytest --color=yes .
```

### Try in GitHub Codespaces

You can try Cheshire Cat in GitHub Codespaces. The free account provides 60 free hours a month.

[![Try in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/cheshire-cat-ai/core)


#### Instructions

- Right-click this [link](https://codespaces.new/cheshire-cat-ai/core) and select "open a new window." It will open a webpage titled "Create a new codespace":
- You can ignore the options on the screen and press the green button "create codespace"
- Wait for the codespace to load, and then type on the terminal "docker-compose up"
- It will take a few minutes. When you read "Application startup complete," it will show three links: REST API, PUBLIC, and ADMIN.
- Click on the ADMIN link to configure Cheshire Cat and start playing with it.
- Have fun!
- As soon as you're satisfied, you can press "CTRL C" on the terminal to stop the Cheshire Cat. Then type docker-compose down to close the docker container.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## Roadmap

Detailed roadmap is [here](./readme/ROADMAP.md).
Expand Down
8 changes: 7 additions & 1 deletion core/cat/api_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import fnmatch

from fastapi import Request
from fastapi import Security, HTTPException
from fastapi.security.api_key import APIKeyHeader

Expand All @@ -15,13 +17,15 @@
api_key_header = APIKeyHeader(name="access_token", auto_error=False)


def check_api_key(api_key: str = Security(api_key_header)) -> None | str:
def check_api_key(request: Request, api_key: str = Security(api_key_header)) -> None | str:
"""Authenticate endpoint.
Check the provided key is available in API keys list.
Parameters
----------
request : Request
HTTP request.
api_key : str
API keys to be checked.
Expand All @@ -38,6 +42,8 @@ def check_api_key(api_key: str = Security(api_key_header)) -> None | str:
"""
if not API_KEY:
return None
if fnmatch.fnmatch(request.url.path, "/admin*"):
return None
if api_key in API_KEY:
return api_key
else:
Expand Down
47 changes: 0 additions & 47 deletions core/cat/infrastructure/package.py

This file was deleted.

79 changes: 43 additions & 36 deletions core/cat/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def get_caller_info(self, skip=3):
if module_info:
mod = module_info.__name__.split(".")
package = mod[0]
module = mod[1]
module = ".".join(mod[1:])

# class name.
klass = None
klass = ""
if "self" in parentframe.f_locals:
klass = parentframe.f_locals["self"].__class__.__name__

Expand All @@ -140,15 +140,40 @@ def get_caller_info(self, skip=3):

return package, module, klass, caller, line

def __call__(self, msg, level="DEBUG"):
"""Alias of self.log()"""
self.log(msg, level)

def debug(self, msg):
"""Logs a DEBUG message"""
self.log(msg, level="DEBUG")

def info(self, msg):
"""Logs an INFO message"""
self.log(msg, level="INFO")

def warning(self, msg):
"""Logs a WARNING message"""
self.log(msg, level="WARNING")

def error(self, msg):
"""Logs an ERROR message"""
self.log(msg, level="ERROR")

def critical(self, msg):
"""Logs a CRITICAL message"""
self.log(msg, level="CRITICAL")

def log(self, msg, level="DEBUG"):
"""Add to log based on settings.
"""Log a message
Parameters
----------
msg :
Message to be logged.
level : str
Logging level."""

global logger
logger.remove()

Expand Down Expand Up @@ -203,40 +228,22 @@ def log(self, msg, level="DEBUG"):
# After our custom log we need to set again the logger as default for the other dependencies
self.default_log()

def welcome(self):
"""Welcome message in the terminal."""
secure = os.getenv('CORE_USE_SECURE_PROTOCOLS', '')
if secure != '':
secure = 's'

logEngine = CatLogEngine()


def log(msg, level="DEBUG"):
"""Create function wrapper to class.
Parameters
----------
msg : str
Message to be logged.
level : str
Logging level.
Returns
-------
"""
global logEngine
return logEngine.log(msg, level)


def welcome():
"""Welcome message in the terminal."""
secure = os.getenv('CORE_USE_SECURE_PROTOCOLS', '')
if secure != '':
secure = 's'
cat_address = f'http{secure}://{os.environ["CORE_HOST"]}:{os.environ["CORE_PORT"]}'

cat_address = f'http{secure}://{os.environ["CORE_HOST"]}:{os.environ["CORE_PORT"]}'
with open("cat/welcome.txt", 'r') as f:
print(f.read())

with open("cat/welcome.txt", 'r') as f:
print(f.read())
print('\n=============== ^._.^ ===============\n')
print(f'Cat REST API:\t{cat_address}/docs')
print(f'Cat PUBLIC:\t{cat_address}/public')
print(f'Cat ADMIN:\t{cat_address}/admin\n')
print('======================================')

print('\n=============== ^._.^ ===============\n')
print(f'Cat REST API:\t{cat_address}/docs')
print(f'Cat PUBLIC:\t{cat_address}/public')
print(f'Cat ADMIN:\t{cat_address}/admin\n')
print('======================================')
# logger instance
log = CatLogEngine()
Loading

0 comments on commit a24934a

Please sign in to comment.