forked from steamship-core/langchain-production-starter
-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Enias Cailliau
committed
Jul 26, 2023
1 parent
31bc992
commit f2a07c6
Showing
14 changed files
with
445 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pytimeparse | ||
termcolor | ||
steamship~=2.17.18 | ||
langchain==0.0.200 | ||
steamship@git+https://github.com/steamship-core/python-client@ec/review-mixins | ||
langchain==0.0.200 | ||
scrapetube |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,102 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import streamlit as st | ||
from steamship.cli.create_instance import load_manifest | ||
|
||
sys.path.append(str((Path(__file__) / "..").resolve())) | ||
st.set_page_config(page_title="🎥->🤗 Youtube to Companion") | ||
from utils.data import get_companions, get_companion_attributes, add_resource | ||
from utils.utils import get_instance, to_snake | ||
from utils.ux import sidebar, get_api_key | ||
|
||
# Start page | ||
st.title("🎥->🤗 Youtube to Companion") | ||
st.write( | ||
"Create your AI companion and chat about your favorite youtube video's" | ||
) | ||
|
||
sidebar() | ||
|
||
manifest = load_manifest() | ||
|
||
if not st.session_state.get("instance"): | ||
|
||
# TODO: Add dropdown with examples | ||
col1, col2 = st.columns(2) | ||
|
||
col1.subheader("Attributes") | ||
companion_template = col2.selectbox("Templates (Optional)", options=["<none>", *get_companions()]) | ||
if companion_template != "<none>": | ||
print(companion_template) | ||
companion = get_companion_attributes(companion_template.lower()) | ||
else: | ||
companion = {} | ||
|
||
personality = st.text_input("Name", value=companion.get("name", ""), | ||
placeholder="The name of your companion") | ||
byline = st.text_input("Byline", value=companion.get("byline", ""), | ||
placeholder="The byline of your companion") | ||
identity = st.text_input("Identity", value=companion.get("identity", ""), | ||
placeholder="The identity of your companion") | ||
behavior = st.text_input("Behavior", value=companion.get("behavior", ""), | ||
placeholder="The behavior of your companion") | ||
st.session_state.companion_profile_img = st.text_input("Profile picture", value=companion.get("profile_image", ""), | ||
placeholder="The profile picture of your companion") | ||
|
||
st.session_state.companion_first_message = st.text_input( | ||
label="First message", | ||
placeholder="The first message your companion sends when a new conversation starts.") | ||
|
||
st.subheader("Long term memory") | ||
youtube_video_url = st.text_input("Youtube Video URL") | ||
|
||
if st.button("🤗 Spin up your companion"): | ||
|
||
st.session_state.instance = instance = get_instance(to_snake(personality), config={ | ||
"name": personality, | ||
"byline": byline, | ||
"identity": identity, | ||
"behavior": behavior, | ||
}) | ||
|
||
if youtube_video_url: | ||
with st.spinner("Companion is watching the video 👀..."): | ||
add_resource( | ||
instance.invocation_url, | ||
str(instance.client.config.api_key), | ||
youtube_video_url) | ||
|
||
st.balloons() | ||
st.experimental_rerun() | ||
|
||
else: | ||
instance = st.session_state.instance | ||
companion_name = instance.config["name"] | ||
|
||
if st.button("+ New bot"): | ||
st.session_state.instance = None | ||
st.experimental_rerun() | ||
|
||
st.header(f"Start chatting with {companion_name}") | ||
if st.session_state.get("companion_profile_img"): | ||
st.image(st.session_state.companion_profile_img) | ||
|
||
if "messages" not in st.session_state: | ||
st.session_state["messages"] = [ | ||
{"role": "assistant", "content": st.session_state.companion_first_message} | ||
] | ||
|
||
for msg in st.session_state.messages: | ||
st.chat_message(msg["role"]).write(msg["content"]) | ||
|
||
if prompt := st.chat_input(): | ||
get_api_key() | ||
|
||
st.session_state.messages.append({"role": "user", "content": prompt}) | ||
st.chat_message("user").write(prompt) | ||
with st.chat_message("assistant"): | ||
with st.spinner("Thinking..."): | ||
response = instance.invoke("prompt", prompt=prompt) | ||
st.write(response) | ||
st.session_state.messages.append({"role": "assistant", "content": response}) |
Empty file.
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,63 @@ | ||
import time | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
from steamship import File | ||
|
||
from utils.ux import sidebar, get_instance | ||
|
||
st.title("Manage your chatbot") | ||
|
||
sidebar() | ||
|
||
|
||
def load_and_show_videos(instance): | ||
files = File.query(instance.client, tag_filter_query='kind is "_type"').files | ||
videos = [] | ||
for file in files: | ||
for block in file.blocks: | ||
tag_key_to_value = {tag.kind: tag.name for tag in block.tags} | ||
videos.append( | ||
{ | ||
"Title": tag_key_to_value.get("title"), | ||
"source": "https://www.youtube.com/watch?v=" | ||
+ tag_key_to_value.get("source"), | ||
"thumbnail_url": tag_key_to_value.get("thumbnail_url"), | ||
"Status": [tag.name for tag in file.tags if tag.kind == "status"][ | ||
0 | ||
], | ||
} | ||
) | ||
df = pd.DataFrame(videos) | ||
table.dataframe( | ||
df, | ||
column_config={ | ||
"Title": st.column_config.LinkColumn("source"), | ||
"thumbnail_url": st.column_config.ImageColumn(label="Thumbnail"), | ||
}, | ||
column_order=["thumbnail_url", "Title", "Status"], | ||
) | ||
|
||
return videos | ||
|
||
|
||
instance = get_instance() | ||
refresh_bar = st.progress(0, text="Time till refresh") | ||
|
||
table = st.empty() | ||
videos = [] | ||
i = 0 | ||
# | ||
# if st.button("Add 10 more video's", type="primary"): | ||
# videos = load_and_show_videos(instance) | ||
# index_youtube_channel(st.session_state.channel_url, len(videos), 10) | ||
# i = 0 | ||
|
||
while True: | ||
refresh_bar.progress(i % 20 / 20, text="Time till refresh") | ||
|
||
if i % 20 == 0: | ||
table.text("Loading videos...") | ||
load_and_show_videos(instance) | ||
i += 1 | ||
time.sleep(1) |
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,51 @@ | ||
import streamlit as st | ||
|
||
from tools.utils import sidebar, get_instance | ||
|
||
sidebar() | ||
st.title("Share your chatbot") | ||
instance = get_instance() | ||
|
||
st.subheader("Public URL") | ||
|
||
st.code( | ||
f"https://www.steamship.com/embed/chat?userHandle={instance.user_handle}&workspaceHandle={instance.handle}&instanceHandle={instance.handle}" | ||
) | ||
|
||
st.subheader("Embeddable iframe") | ||
st.write( | ||
"To add the chatbot any where on your website, add this iframe to your html code" | ||
) | ||
|
||
st.code( | ||
""" | ||
<iframe src="https://www.steamship.com/embed/chat?userHandle={instance.user_handle}&workspaceHandle={instance.handle}&instanceHandle={instance.handle}" | ||
width="100%" | ||
height="700" | ||
frameborder="0" | ||
></iframe> | ||
""" | ||
) | ||
st.subheader("Chat bubble") | ||
|
||
st.write( | ||
"To add a chat bubble to the bottom right of your website add this script tag to your html" | ||
) | ||
st.code( | ||
""" | ||
<script | ||
src="https://cdn.jsdelivr.net/gh/EniasCailliau/chatbot@main/index.js" | ||
id="https://www.steamship.com/embed/chat?userHandle={instance.user_handle}&workspaceHandle={instance.handle}&instanceHandle={instance.handle}" > | ||
</script> | ||
""" | ||
) | ||
|
||
st.subheader("Connect to Telegram") | ||
bot_token = st.text_input("Bot Token", type="password") | ||
st.write( | ||
"Learn how to create one [here](https://github.com/steamship-packages/langchain-agent-production-starter/blob/main/docs/register-telegram-bot.md)" | ||
) | ||
if st.button("Connect"): | ||
response = instance.invoke("connect_telegram", bot_token=bot_token) | ||
if response == "OK": | ||
st.info("Chatbot successfully connected to Telegram ✅") |
Empty file.
Empty file.
Oops, something went wrong.