Skip to content

Commit

Permalink
Merge pull request #141 from holoviz-topics/revamp_docs
Browse files Browse the repository at this point in the history
Revamp docs
  • Loading branch information
ahuang11 authored May 29, 2024
2 parents f28289e + 082affc commit 5b4b09f
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ To install and serve all examples:
```bash
git clone https://github.com/holoviz-topics/panel-chat-examples
cd panel-chat-examples
pip install -e ".[all]" # or instead of `all`, just `openai`, `mistralai`, `langchain`, `llamaindex`, `llamacpp`
# Optionally set the OPENAI_API_KEY environment variable
panel serve docs/examples/**/*.py --static-dirs thumbnails=docs/assets/thumbnails --autoreload
```
Expand Down
1 change: 1 addition & 0 deletions docs/applicable_recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ We use [OpenAI *Function Calling*](https://platform.openai.com/docs/guides/funct
We use [OpenAI *Function Calling*](https://platform.openai.com/docs/guides/function-calling) and
[hvPlot](https://hvplot.holoviz.org/) to create an **advanced chatbot** that can create plots.
"""

import json
from pathlib import Path

Expand Down
Binary file added docs/assets/thumbnails/llama_cpp_python.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/thumbnails/llama_index.mp4
Binary file not shown.
Binary file added docs/assets/thumbnails/llama_index.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/videos/llama_cpp_python.mp4
Binary file not shown.
Binary file added docs/assets/videos/llama_index.mp4
Binary file not shown.
15 changes: 11 additions & 4 deletions docs/chat_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Highlights:
without it, only one letter would be displayed at a time.
"""


from asyncio import sleep

import panel as pn
Expand Down Expand Up @@ -321,7 +320,7 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
instance.respond()
elif user == PERSON_2:
instance.send(
f"Yup, I heard!",
"Yup, I heard!",
user=PERSON_3,
avatar="😆",
respond=False,
Expand Down Expand Up @@ -387,7 +386,10 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
# use send instead of stream/yield/return to keep the placeholder text
# while still sending a message; ensure respond=False to avoid a recursive loop
instance.send(
"Let me flip the coin for you...", user="Game Master", avatar="🎲", respond=False
"Let me flip the coin for you...",
user="Game Master",
avatar="🎲",
respond=False,
)
await sleep(1)

Expand All @@ -405,7 +407,11 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
# equivalently, use a dict instead of a pn.chat.ChatMessage
yield {"object": f"Woohoo, {result}! You win!", "user": "Coin", "avatar": "🎲"}
else:
yield {"object": f"Aw, got {result}. Try again!", "user": "Coin", "avatar": "🎲"}
yield {
"object": f"Aw, got {result}. Try again!",
"user": "Coin",
"avatar": "🎲",
}


chat_interface = pn.chat.ChatInterface(
Expand Down Expand Up @@ -457,6 +463,7 @@ Highlights:
- Set `show_*` parameters to `False` to hide the respective buttons.
- Use `message_params` to customize the appearance of each chat messages.
"""

import panel as pn

pn.extension()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
We use [OpenAI *Function Calling*](https://platform.openai.com/docs/guides/function-calling) and
[hvPlot](https://hvplot.holoviz.org/) to create an **advanced chatbot** that can create plots.
"""

import json
from pathlib import Path

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/chat_features/chained_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
instance.respond()
elif user == PERSON_2:
instance.send(
f"Yup, I heard!",
"Yup, I heard!",
user=PERSON_3,
avatar="😆",
respond=False,
Expand Down
11 changes: 9 additions & 2 deletions docs/examples/chat_features/control_callback_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
# use send instead of stream/yield/return to keep the placeholder text
# while still sending a message; ensure respond=False to avoid a recursive loop
instance.send(
"Let me flip the coin for you...", user="Game Master", avatar="🎲", respond=False
"Let me flip the coin for you...",
user="Game Master",
avatar="🎲",
respond=False,
)
await sleep(1)

Expand All @@ -41,7 +44,11 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
# equivalently, use a dict instead of a pn.chat.ChatMessage
yield {"object": f"Woohoo, {result}! You win!", "user": "Coin", "avatar": "🎲"}
else:
yield {"object": f"Aw, got {result}. Try again!", "user": "Coin", "avatar": "🎲"}
yield {
"object": f"Aw, got {result}. Try again!",
"user": "Coin",
"avatar": "🎲",
}


chat_interface = pn.chat.ChatInterface(
Expand Down
1 change: 0 additions & 1 deletion docs/examples/chat_features/stream_echo_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
without it, only one letter would be displayed at a time.
"""


from asyncio import sleep

import panel as pn
Expand Down
1 change: 1 addition & 0 deletions docs/examples/chat_features/styled_slim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Set `show_*` parameters to `False` to hide the respective buttons.
- Use `message_params` to customize the appearance of each chat messages.
"""

import panel as pn

pn.extension()
Expand Down
8 changes: 8 additions & 0 deletions docs/kickstart_snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Highlights:
- Uses `serialize` to get chat history from the `ChatInterface`.
- Uses `yield` to continuously concatenate the parts of the response.

<video controls poster="../assets/thumbnails/llama_cpp_python.png" >
<source src="../assets/videos/llama_cpp_python.mp4" type="video/mp4"
style="max-height: 400px; max-width: 600px;">
Your browser does not support the video tag.
</video>



<details>

<summary>Source code for <a href='../examples/kickstart_snippets/llama_cpp_python_.py' target='_blank'>llama_cpp_python_.py</a></summary>
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ mistralai = [
langchain = [
"langchain>=0.0.350",
]
llama_index = [
llamaindex = [
"llama_index>=0.10.40",
]
llama_cpp_python = [
llamacpp = [
"llama_cpp_python",
]
all = [
"panel-chat-examples[openai,mistralai,langchain,llama_index,llama_cpp]",
"panel-chat-examples[openai,mistralai,langchain,llamaindex,llamacpp]",
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sahred pytest configuration and fixtures"""

import os
import re
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Locust load test file"""

from pathlib import Path
from random import choice

Expand Down
7 changes: 5 additions & 2 deletions tests/test_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test all app .py files py running them with python"""

import subprocess
from pathlib import Path

Expand All @@ -12,9 +13,11 @@ def test_app(app_path):

def test_has_thumbnail(app_path):
name = Path(app_path).name
assert (THUMBNAILS_PATH / name.replace(".py", ".png")).exists()
assert (
THUMBNAILS_PATH / name.replace(".py", ".png").replace("_.png", ".png")
).exists()


def test_has_video(app_path):
name = Path(app_path).name
assert (VIDEOS_PATH / name.replace(".py", ".mp4")).exists()
assert (VIDEOS_PATH / name.replace(".py", ".mp4").replace("_.mp4", ".mp4")).exists()
2 changes: 0 additions & 2 deletions tests/ui/inputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import re
import time
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions tests/ui/test_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the UI of all apps via Playwright"""

import os
import sys
import time
Expand Down

0 comments on commit 5b4b09f

Please sign in to comment.