Skip to content

Commit 0bef004

Browse files
authored
Merge pull request #70 from sudoleg/develop
project structure updates & embedding models
2 parents a176f59 + a2efbb2 commit 0bef004

File tree

9 files changed

+57
-32
lines changed

9 files changed

+57
-32
lines changed

.assets/home.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# YTAI - Your personal YouTube AI
22

3-
Get insights from YouTube videos with YTAI, an LLM-based app that allows you to summarize or even ask questions and receive answers about them! tailors YouTube video summaries to your needs, offering a custom prompt feature for summaries exactly how you want them.
4-
5-
Check out the project on [GitHub](https://github.com/sudoleg/ytai) for more information! Also, if you like the app, I would be very happy about a star :star:
3+
Get insights from YouTube videos with YTAI, an LLM-based app that allows you to summarize or even ask questions and receive answers about them! Check out the project on [GitHub](https://github.com/sudoleg/ytai) for more information! Also, if you like the app, I would be very happy about a star :star:
64

75
## Summary
86

.assets/rag_quidelines.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ You can either provide a question or just a topic from the video. If you ask a q
66

77
## General tips
88

9-
- be specific
10-
- be concise
11-
- Don't include instructions, like 'explain in detail' or 'answer from a perspective of X' etc.
9+
- be concise and specific
10+
- don't combine questions unless they are closely related!
11+
- don't include instructions, like 'explain in detail' or 'answer from a perspective of X' etc.
1212

1313
## Important notice ❗
1414

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ docker build --tag=ytai:latest .
4949
docker run -d -p 8501:8501 -v $(pwd):/app/responses -e OPENAI_API_KEY=<your-openai-api-key> --name yt-summarizer sudoleg/ytai:latest
5050
```
5151

52-
### development in virtual environment
53-
54-
```bash
55-
python -m venv .venv
56-
source .venv/bin/activate
57-
pip install -r requirements.txt
58-
export OPENAI_API_KEY=<your-openai-api-key>
59-
streamlit run main.py
60-
```
61-
6252
## Contributing
6353

6454
Feedback and contributions are welcome! This is a small side-project and it's very easy to get started! Here’s the gist to get your changes rolling:
@@ -72,6 +62,22 @@ Feedback and contributions are welcome! This is a small side-project and it's ve
7262
5. **Pull Request**: Push your changes to your fork and submit a pull request (PR) to the main repository. Describe your changes and any relevant details.
7363
6. **Engage**: Respond to feedback on your PR to finalize your contribution.
7464

65+
### development in virtual environment
66+
67+
```bash
68+
# create and activate a virtual environment
69+
python -m venv .venv
70+
source .venv/bin/activate
71+
# install requirements
72+
pip install -r requirements.txt
73+
# you'll need an API key
74+
export OPENAI_API_KEY=<your-openai-api-key>
75+
# run chromadb (necessary for chat)
76+
docker-compose up -d chromadb
77+
# run app
78+
streamlit run main.py
79+
```
80+
7581
## Technologies used
7682

7783
The project is built using some amazing libraries:

config.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
"app_title": "AI YouTube Video Summarizer",
33
"github_repo_link": "https://github.com/sudoleg/ytai",
44
"default_model": "gpt-3.5-turbo",
5-
"available_models": [
6-
"gpt-3.5-turbo",
7-
"gpt-4",
8-
"gpt-4-turbo",
9-
"gpt-4o"
10-
],
5+
"available_models": {
6+
"embeddings": [
7+
"text-embedding-3-small",
8+
"text-embedding-3-large"
9+
],
10+
"gpts": [
11+
"gpt-3.5-turbo",
12+
"gpt-4",
13+
"gpt-4-turbo",
14+
"gpt-4o"
15+
]
16+
},
1117
"temperature": 1.0,
1218
"top_p": 1.0,
1319
"help_texts": {
@@ -19,6 +25,7 @@
1925
"saving_responses": "Whether to save responses in the directory, where you run the app. The responses will be saved under '<YT-channel-name>/<video-title>.md'.",
2026
"chunk_size": "A larger chunk size increases the amount of context provided to the model to answer your question. However, it may be less relevant than with a small chunk size, as smaller chunks can encapsulate more semantic meaning. I would reccommend to use a smaller chunk size for shorter and a larger one for longer videos (> 1h).",
2127
"preprocess_checkbox": "By enabling this, the original transcript gets preprocessed. This can greatly improve the results, especially for videos with automatically generated transcripts. However, it results in higher costs, as the whole transcript get's processed by gpt3.5-turbo. Also, the preprocessing will take a substantial amount of time.",
22-
"selected_video": "Once you process a video, it gets saved in a database. You can chat with it at any time, without processing it again! Tip: you may also search for videos by typing (parts of) its title."
28+
"selected_video": "Once you process a video, it gets saved in a database. You can chat with it at any time, without processing it again! Tip: you may also search for videos by typing (parts of) its title.",
29+
"embeddings": "Embeddings are a numerical representation of text that can be used to measure the relatedness between two pieces of text. Embedding models create these numerical representations. Read more at https://platform.openai.com/docs/models/embeddings"
2330
}
2431
}
File renamed without changes.

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ services:
4141
# the summaries to be saved
4242
- /Users/Shared/yt-summaries:/app/responses
4343
# leave as it is
44-
- sqlite:/app/data/app
44+
- ./data:/app/data
4545
environment:
4646
# replace with your OpenAI API key or the name of the environment
4747
# variable that stores it on your machine
@@ -54,5 +54,3 @@ services:
5454
volumes:
5555
chroma:
5656
driver: local
57-
sqlite:
58-
driver: local

modules/persistance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
UUIDField,
1212
)
1313

14-
SQL_DB = SqliteDatabase("data/app/videos.sqlite3")
14+
SQL_DB = SqliteDatabase("data/videos.sqlite3")
1515

1616

1717
class BaseModel(Model):

modules/ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def display_model_settings_sidebar():
6262
st.header("Model settings")
6363
model = st.selectbox(
6464
"Select a large language model",
65-
tuple(get_default_config_value("available_models")),
65+
tuple(get_default_config_value("available_models.gpts")),
6666
key="model",
6767
help=get_default_config_value("help_texts.model"),
6868
)

pages/chat.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@
4545

4646
CHUNK_SIZE_FOR_UNPROCESSED_TRANSCRIPT = 512
4747

48-
4948
st.set_page_config("Chat", layout="wide", initial_sidebar_state="auto")
5049
display_api_key_warning()
5150

5251
# --- sidebar with model settings ---
5352
display_nav_menu()
5453
display_model_settings_sidebar()
54+
st.sidebar.info("Choose `text-embedding-3-large` if your video is **not** in English!")
55+
selected_embeddings_model = st.sidebar.selectbox(
56+
label="Select an embedding model",
57+
options=tuple(get_default_config_value("available_models.embeddings")),
58+
key="embeddings_model",
59+
help=get_default_config_value("help_texts.embeddings"),
60+
)
5561
display_link_to_repo()
5662
# --- end ---
5763

@@ -91,7 +97,7 @@
9197
)
9298
openai_embedding_model = OpenAIEmbeddings(
9399
api_key=st.session_state.openai_api_key,
94-
model="text-embedding-3-small",
100+
model=st.session_state.embeddings_model,
95101
)
96102
# --- end ---
97103

@@ -237,9 +243,9 @@ def refresh_page(message: str):
237243
collection = chroma_client.get_or_create_collection(
238244
name=randomname.get_name(),
239245
metadata={
240-
"yt_video_id": saved_video.yt_video_id,
241-
"yt_channel": saved_video.channel,
242246
"yt_video_title": saved_video.title,
247+
"chunk_size": chunk_size,
248+
"embeddings_model": selected_embeddings_model,
243249
},
244250
)
245251

@@ -305,6 +311,15 @@ def refresh_page(message: str):
305311

306312
with col2:
307313
if collection and collection.count() > 0:
314+
315+
# the users input has to be embedded using the same embeddings model as was used for creating
316+
# the embeddings for the transcript excerpts. Here we ensure that the embedding function passed
317+
# as argument to the vector store is the same as was used for the embeddings
318+
collection_embeddings_model = collection.metadata.get("embeddings_model")
319+
if collection_embeddings_model != selected_embeddings_model:
320+
openai_embedding_model.model = collection_embeddings_model
321+
322+
# init vector store
308323
chroma_db = Chroma(
309324
client=chroma_client,
310325
collection_name=collection.name,
@@ -322,6 +337,7 @@ def refresh_page(message: str):
322337
if prompt:
323338
with st.spinner("Generating answer..."):
324339
try:
340+
325341
relevant_docs = find_relevant_documents(query=prompt, db=chroma_db)
326342
response = generate_response(
327343
question=prompt,

0 commit comments

Comments
 (0)