Skip to content

Commit

Permalink
feat(docs): add mkdocs (#153)
Browse files Browse the repository at this point in the history
* ➕ add docs dependencies

* 🍱 add doc assets

* 💄 add custom css

* 🔧 add mkdocs.yml

* 🍱 update assets

* 📝 update README

* 🔧 update mkdocs.yml

* 📝 add home page

* 🍱 add doc assets

* 📝 remove documentation badge

* 👷 add workflow to publish docs

* 💄 update primary color

* 🚧 test deployment

* 🔧 add CNAME

* 👷 update GA workflow

* 📝 update README

* ➕ add docs dependency

* 🔧 update mkdocs.yml

* 💄 update css

* 📝 update home page

* 📝 add getting started page

* 🐛 fix callback handler bug

* 📝 update code
  • Loading branch information
ajndkr committed Nov 24, 2023
1 parent 8041b9c commit 4e61fa6
Show file tree
Hide file tree
Showing 17 changed files with 725 additions and 6 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docs

on:
push:
branches:
- main

permissions:
contents: write

env:
PYTHON_VERSION: 3.9

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Update Environment Variables
run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV

- name: Setup Cache
uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- name: Deploy GitHub Pages
run: |
pip install mkdocs-material mdx-include termynal
mkdocs gh-deploy --force
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div align="center">

<img src="https://raw.githubusercontent.com/ajndkr/lanarky/main/assets/logo.png" alt="lanarky-logo" width="250">
<img src="assets/logo-light-mode.png#gh-light-mode-only" alt="lanarky-logo-light-mode" width="500">
<img src="assets/logo-dark-mode.png#gh-dark-mode-only" alt="lanarky-logo-dark-mode" width="500">

<h4>The web framework for building LLM microservices.</h4>

[![Stars](https://img.shields.io/github/stars/ajndkr/lanarky)](https://github.com/ajndkr/lanarky/stargazers)
[![Documentation](https://img.shields.io/badge/documentation-ReadTheDocs-blue.svg)](https://lanarky.readthedocs.io/en/latest/)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ajndkr/lanarky/blob/main/LICENSE)
[![Twitter](https://img.shields.io/twitter/follow/LanarkyAPI?style=social)](https://twitter.com/intent/follow?screen_name=LanarkyAPI)

Expand All @@ -16,9 +16,23 @@

</div>

Lanarky is a **python (3.9+)** web framework for developers who want to build microservices using LLMs.
Here are some of its key features:

- **LLM-first**: Unlike other web frameworks, lanarky is built specifically for LLM developers.
It's unopinionated in terms of how you build your microservices and guarantees zero vendor lock-in
with any LLM tooling frameworks or cloud providers
- **Fast & Modern**: Built on top of FastAPI, lanarky offers all the FastAPI features you know and love.
If you are new to FastAPI, visit [fastapi.tiangolo.com](https://fastapi.tiangolo.com) to learn more
- **Streaming**: Streaming a special requirement when building microservices for chatbot-like applications.
Lanarky has got you covered with built-in streaming support over **HTTP** and **WebSockets**.
- **Open-source**: Lanarky is open-source and free to use. Forever.

To learn more about lanarky and get started, you can find the full documentation on [lanarky.ajndkr.com](https://lanarky.ajndkr.com)

## Installation

The library is available on PyPI and can be installed via `pip`.
The library is available on PyPI and can be installed via `pip`:

```bash
pip install lanarky
Expand Down
Binary file added assets/logo-dark-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-light-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/logo.png
Binary file not shown.
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lanarky.ajndkr.com
Binary file added docs/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/logo-dark-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/logo-light-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
hide:
- navigation
---

This is a quick tutorial on getting started with Lanarky.

We will use LangChain as the LLM tooling framework and OpenAI as the LLM provider to
build our first LLM microservice.

## Install Dependencies

<!-- termynal -->

```
$ pip install lanarky[langchain,openai]
```

## Example

We will use the `ConversationChain` from LangChain library to build our first LLM microservice.

!!! info

You need to set the `OPENAI_API_KEY` environment variable to use OpenAI.
Visit [openai.com](https://openai.com) to get your API key.

```python
import os
from fastapi import FastAPI
from langchain.chains import ConversationChain
from langchain.chat_models import ChatOpenAI
from lanarky.adapters.langchain.routing import LangchainAPIRouter

os.environ["OPENAI_API_KEY"] = "add-your-openai-api-key-here"

app = FastAPI()
langchain_router = LangchainAPIRouter()

@langchain_router.post("/chat")
def chat(streaming: bool = True) -> ConversationChain:
return ConversationChain(llm=ChatOpenAI(streaming=streaming))

app.include_router(langchain_router)
```

Run the application:

<!-- termynal -->

```
$ pip install uvicorn
$ uvicorn app:app --reload
```

View the Swagger docs at [http://localhost:8000/docs](http://localhost:8000/docs).

## Testing

<!-- termynal -->

```
$ pip install httpx-sse
```

Create `client.py` script:

```python
import click
import httpx
from httpx_sse import connect_sse


@click.command()
@click.option("--input", required=True)
@click.option("--streaming", is_flag=True)
def main(input: str, streaming: bool):
url = f"http://localhost:8000/chat?streaming={str(streaming).lower()}"
with httpx.Client() as client:
with connect_sse(
client,
"POST",
url,
json={"input": input},
) as event_source:
for sse in event_source.iter_sse():
print(sse.event, sse.data)


if __name__ == "__main__":
main()
```

Stream output:

<!-- termynal -->

```
$ python client.py --input hi --streaming
```

Recieve all output at once:

<!-- termynal -->

```
$ python client.py --input hi
```
46 changes: 46 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
hide:
- navigation
- toc
---

<style>
.md-content .md-typeset h1 { display: none; }
</style>

<div align="center">

<img src="assets/logo-light-mode.png#only-light" alt="lanarky-logo-light-mode" width="500">
<img src="assets/logo-dark-mode.png#only-dark" alt="lanarky-logo-dark-mode" width="500">

<h4>The web framework for building LLM microservices.</h4>

<a href="https://github.com/ajndkr/lanarky/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License">
</a>
<a href="https://coveralls.io/github/ajndkr/lanarky?branch=main">
<img src="https://coveralls.io/repos/github/ajndkr/lanarky/badge.svg?branch=main" alt="Coverage">
</a>
<a href="https://pypistats.org/packages/lanarky">
<img src="https://img.shields.io/pypi/dm/lanarky.svg" alt="Stats">
</a>

</div>

Lanarky is a **python (3.9+)** web framework for developers who want to build microservices using LLMs.
Here are some of its key features:

- **LLM-first**: Unlike other web frameworks, lanarky is built specifically for LLM developers.
It's unopinionated in terms of how you build your microservices and guarantees zero vendor lock-in
with any LLM tooling frameworks or cloud providers
- **Fast & Modern**: Built on top of FastAPI, lanarky offers all the FastAPI features you know and love.
If you are new to FastAPI, visit [fastapi.tiangolo.com](https://fastapi.tiangolo.com) to learn more
- **Streaming**: Streaming a special requirement when building microservices for chatbot-like applications.
Lanarky has got you covered with built-in streaming support over **HTTP** and **WebSockets**.
- **Open-source**: Lanarky is open-source and free to use. Forever.

<!-- termynal -->

```
$ pip install lanarky
```
49 changes: 49 additions & 0 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[data-md-color-scheme="lanarky"] {
--md-primary-fg-color: #4ce1b5;
--md-primary-fg-color--light: #28f2b6;
--md-primary-fg-color--dark: #0c9a78;

--md-accent-fg-color: #f25353;
--md-accent-fg-color--transparent: rgba(242, 83, 83, 0.1);
}

[data-md-color-scheme="slate"] {
--md-primary-fg-color: #4ce1b5;
--md-primary-fg-color--light: #28f2b6;
--md-primary-fg-color--dark: #0c9a78;

--md-accent-fg-color: #f25353;
--md-accent-fg-color--transparent: rgba(242, 83, 83, 0.1);

--md-hue: 210;
}

.md-header {
color: #303841;
}

.md-tabs {
color: #303841;
}

.md-typeset a {
color: #0c9a78;
}

.md-header__topic:first-child {
font-weight: 400;
}

.md-nav .md-nav__link {
color: #0c9a78;
}

[data-md-color-scheme="lanarky"] img[src$="#only-dark"],
[data-md-color-scheme="lanarky"] img[src$="#gh-dark-mode-only"] {
display: none;
}

[data-md-color-scheme="slate"] img[src$="#only-light"],
[data-md-color-scheme="slate"] img[src$="#gh-light-mode-only"] {
display: none;
}
2 changes: 1 addition & 1 deletion lanarky/adapters/langchain/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async def on_chain_start(self, *args, **kwargs: Any) -> None:

async def on_llm_new_token(self, token: str, **kwargs: Any) -> None:
"""Run on new LLM token. Only available when streaming is enabled."""
if self.streaming:
if not self.streaming:
self.streaming = True

if self.llm_cache_used: # cache missed (or was never enabled) if we are here
Expand Down
77 changes: 77 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
site_name: Lanarky
site_url: https://lanarky.ajndkr.com/
site_author: Ajinkya Indulkar
site_description: The web framework for building LLM microservices
repo_name: ajndkr/lanarky
repo_url: https://github.com/ajndkr/lanarky
copyright: Copyright &copy; 2023 Ajinkya Indulkar

edit_uri: ""

theme:
name: material
palette:
- media: "(prefers-color-scheme: light)"
scheme: lanarky
toggle:
icon: material/toggle-switch
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/toggle-switch-off-outline
name: Switch to light mode
features:
- search.suggest
- search.highlight
- content.tabs.link
- navigation.indexes
- content.tooltips
- navigation.path
- content.code.annotate
- content.code.copy
- content.code.select
- navigation.tabs
icon:
repo: fontawesome/brands/github-alt
logo: assets/icon.svg
favicon: assets/favicon.png
language: en
font:
text: Roboto
code: Roboto Mono

nav:
- Lanarky: index.md
- Getting Started: getting-started.md

markdown_extensions:
- attr_list
- md_in_html
- toc:
permalink: true
- markdown.extensions.codehilite:
guess_lang: false
- mdx_include:
base_path: docs
- admonition
- codehilite
- extra
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true

extra:
social:
- icon: fontawesome/brands/github
link: https://github.com/ajndkr
- icon: fontawesome/brands/python
link: https://pypi.org/project/lanarky/
- icon: fontawesome/brands/twitter
link: https://twitter.com/LanarkyAPI

extra_css:
- stylesheets/extra.css

plugins:
- termynal
Loading

0 comments on commit 4e61fa6

Please sign in to comment.