Skip to content

Commit a72870f

Browse files
committed
Create build.sh
1 parent c096513 commit a72870f

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

custom-build/build.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# Create a custom build of llms.py with selected extensions
4+
5+
# extensions to include
6+
EXTENSIONS="${EXTENSIONS:-providers}"
7+
8+
# Convert to array for easier manipulation and deduplication
9+
IFS=',' read -r -a EXT_ARRAY <<< "$EXTENSIONS"
10+
11+
add_extension() {
12+
local new_ext="$1"
13+
for ext in "${EXT_ARRAY[@]}"; do
14+
if [[ "$ext" == "$new_ext" ]]; then
15+
return 0
16+
fi
17+
done
18+
EXT_ARRAY+=("$new_ext")
19+
}
20+
21+
# enable UI (Look for existing UI variable or default to "1")
22+
UI="${UI:-0}"
23+
24+
# If app,tools,analytics,gallery,katex,system_prompts are enabled, we should enable UI
25+
for item in app tools analytics gallery katex system_prompts; do
26+
if [[ "${EXT_ARRAY[@]}" =~ "$item" ]]; then
27+
UI="1"
28+
break
29+
fi
30+
done
31+
32+
# if UI == 1, we should add 'app' and 'tools' extensions
33+
if [ "$UI" == "1" ]; then
34+
add_extension "app"
35+
add_extension "tools"
36+
fi
37+
38+
rm -rf llms
39+
mkdir -p llms/.llms/cache
40+
41+
cp ../llms/providers.json llms/providers.json
42+
cp ../llms/llms.json llms/llms.json
43+
cp ../llms/main.py llms/main.py
44+
if [ -f ../.env ]; then
45+
echo "Copying .env"
46+
cp ../.env llms/.env;
47+
fi
48+
49+
if [ "$UI" == "1" ]; then
50+
echo "Copying /ui and index.html"
51+
cp ../llms/index.html llms/index.html;
52+
cp -r ../llms/ui llms/ui;
53+
54+
echo "Copying db.py"
55+
cp ../llms/db.py llms/db.py;
56+
fi
57+
58+
# copy extensions
59+
mkdir -p llms/extensions
60+
for ext in "${EXT_ARRAY[@]}"; do
61+
echo "Copying extension: $ext"
62+
cp -r ../llms/extensions/$ext llms/extensions/$ext
63+
done
64+
65+
# create llms.sh
66+
cat <<EOF > llms/llms.sh
67+
#!/bin/bash
68+
69+
LLMS_HOME=.llms PYTHONPATH=.. python3 -m llms "\$@"
70+
EOF
71+
72+
# create __main__.py
73+
cat <<EOF > llms/__main__.py
74+
from .main import main
75+
76+
if __name__ == "__main__":
77+
main()
78+
EOF
79+
80+
# create __init__.py
81+
cat <<EOF > llms/__init__.py
82+
from .main import main as main
83+
84+
__all__ = ["main"]
85+
EOF
86+
87+
chmod +x llms/llms.sh

0 commit comments

Comments
 (0)