-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 📝 update getting started * 💡 improve docstrings * ➕ add `mkdocstrings[python]` dependency * 🐛 fix type annotations * 📝 add api reference docs * ⚡ minor changes * ➕ add dependencies for examples * 🔧 add social plugin * ➕ add back gradio dependency * 🔨 add chatgpt-clone example * 🐛 fix json serialisation for langchain callbacks * 🔨 add paulGPT example * 📝 hide footer * 📝 add discord invite link * 👷 add back docs GA * ✅ fix broken unit test * ⚡ minor change
- Loading branch information
Showing
39 changed files
with
2,228 additions
and
247 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
hide: | ||
- navigation | ||
- toc | ||
- footer | ||
--- | ||
|
||
<style> | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
::: lanarky.adapters.langchain.routing | ||
|
||
::: lanarky.adapters.langchain.responses | ||
|
||
::: lanarky.adapters.langchain.callbacks | ||
|
||
::: lanarky.adapters.langchain.dependencies | ||
|
||
::: lanarky.adapters.langchain.utils |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
::: lanarky.adapters.openai.resources | ||
|
||
::: lanarky.adapters.openai.routing | ||
|
||
::: lanarky.adapters.openai.responses | ||
|
||
::: lanarky.adapters.openai.dependencies | ||
|
||
::: lanarky.adapters.openai.utils |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
hide: | ||
- toc | ||
- footer | ||
--- | ||
|
||
# API Reference | ||
|
||
This is Lanarky's API reference documentation. | ||
|
||
The API reference in split into multiple sections. First, we will cover the | ||
Core API: | ||
|
||
- [`Lanarky`](./lanarky.md) - The main application module | ||
- [`StreamingResponse`](./streaming.md) - `Response` class for streaming | ||
- [`WebSocketSession`](./websockets.md) - class for managing websocket sessions | ||
|
||
!!! note | ||
|
||
Lanarky also provides a collection of web clients for testing purposes. | ||
See [Miscellaneous](./misc.md) for more information. | ||
|
||
Next, we will cover the Adapter API: | ||
|
||
- [OpenAI](./adapters/openai.md): Adapter module for | ||
[OpenAI Python SDK](https://platform.openai.com/docs/api-reference?lang=python) | ||
- [LangChain](./adapters/langchain.md): Adapter module for | ||
[LangChain](https://www.langchain.com/) | ||
|
||
You can find all other utility functions/classes in the [Miscellaneous](./misc.md) section. |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `Lanarky` class | ||
|
||
::: lanarky.Lanarky | ||
options: | ||
members: [] |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Lanarky offers client classes to test streaming and websocket endpoints. | ||
|
||
::: lanarky.clients | ||
|
||
::: lanarky.logging |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `StreamingResponse` class | ||
|
||
::: lanarky.responses.StreamingResponse |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `WebsocketSession` class | ||
|
||
::: lanarky.websockets.WebsocketSession |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ChatGPT-clone | ||
|
||
A chatbot application like [ChatGPT](https://chat.openai.com/), built with Lanarky. | ||
|
||
This example covers the following Lanarky features: | ||
|
||
- OpenAI Adapter | ||
- Streaming tokens via server-sent events | ||
|
||
To learn more about Lanarky, check out Lanarky's [full documentation](https://lanarky.ajndkr.com/learn/). | ||
|
||
## Setup | ||
|
||
Install dependencies: | ||
|
||
``` | ||
pip install 'lanarky[openai]' gradio | ||
``` | ||
|
||
## Run | ||
|
||
First we set the OpenAI API key: | ||
|
||
```sh | ||
export OPENAI_API_KEY=<your-key> | ||
``` | ||
|
||
Then we run the server: | ||
|
||
```sh | ||
python app.py | ||
``` | ||
|
||
Once the server is running, open http://localhost:8000/ in your browser. |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import gradio as gr | ||
|
||
from lanarky import Lanarky | ||
from lanarky.adapters.openai.resources import ChatCompletionResource | ||
from lanarky.adapters.openai.routing import OpenAIAPIRouter | ||
from lanarky.clients import StreamingClient | ||
|
||
app = Lanarky() | ||
router = OpenAIAPIRouter() | ||
|
||
|
||
@router.post("/chat") | ||
def chat() -> ChatCompletionResource: | ||
system = "You are a sassy assistant" | ||
return ChatCompletionResource(system=system, stream=True) | ||
|
||
|
||
app.include_router(router) | ||
|
||
|
||
def mount_playground(app: Lanarky) -> Lanarky: | ||
blocks = gr.Blocks( | ||
title="ChatGPT-clone", | ||
theme=gr.themes.Default( | ||
primary_hue=gr.themes.colors.teal, secondary_hue=gr.themes.colors.teal | ||
), | ||
css="footer {visibility: hidden}", | ||
) | ||
|
||
with blocks: | ||
blocks.load( | ||
None, | ||
None, | ||
js=""" | ||
() => { | ||
document.body.className = "white"; | ||
}""", | ||
) | ||
gr.HTML( | ||
"""<div align="center"><img src="https://lanarky.ajndkr.com/assets/logo-light-mode.png" width="350"></div>""" | ||
) | ||
chatbot = gr.Chatbot(height=500, show_label=False) | ||
with gr.Row(): | ||
user_input = gr.Textbox( | ||
show_label=False, placeholder="Type a message...", scale=5 | ||
) | ||
clear_btn = gr.Button("Clear") | ||
|
||
def chat(history): | ||
messages = [] | ||
for human, assistant in history: | ||
if human: | ||
messages.append({"role": "user", "content": human}) | ||
if assistant: | ||
messages.append({"role": "assistant", "content": assistant}) | ||
|
||
history[-1][1] = "" | ||
for event in StreamingClient().stream_response( | ||
"POST", "/chat", json={"messages": messages} | ||
): | ||
history[-1][1] += event.data | ||
yield history | ||
|
||
user_input.submit( | ||
lambda user_input, chatbot: ("", chatbot + [[user_input, None]]), | ||
[user_input, chatbot], | ||
[user_input, chatbot], | ||
queue=False, | ||
).then(chat, chatbot, chatbot) | ||
clear_btn.click(lambda: None, None, chatbot, queue=False) | ||
|
||
return gr.mount_gradio_app(app, blocks.queue(), "/") | ||
|
||
|
||
app = mount_playground(app) | ||
|
||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
|
||
uvicorn.run(app) |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# PaulGPT | ||
|
||
A chatbot application to answer questions about Paul Graham essay, "[What I worked on](http://www.paulgraham.com/worked.html)", | ||
built with Lanarky. | ||
|
||
This example covers the following Lanarky features: | ||
|
||
- LangChain Adapter | ||
- Streaming source documents via server-sent events and websockets | ||
|
||
To learn more about Lanarky, check out Lanarky's [full documentation](https://lanarky.ajndkr.com/learn/). | ||
|
||
## Setup | ||
|
||
Install dependencies: | ||
|
||
``` | ||
pip install 'lanarky[openai]' gradio faiss-cpu | ||
``` | ||
|
||
## Run | ||
|
||
First we set the OpenAI API key: | ||
|
||
```sh | ||
export OPENAI_API_KEY=<your-key> | ||
``` | ||
|
||
Then we run the server: | ||
|
||
```sh | ||
python app.py | ||
``` | ||
|
||
Once the server is running, open http://localhost:8000/ in your browser. |
Oops, something went wrong.