rajkstats commited on
Commit
a235334
ยท
1 Parent(s): cb995d2
Files changed (5) hide show
  1. .gitignore +161 -0
  2. Dockerfile +42 -0
  3. README.md +195 -6
  4. chainlit.md +3 -0
  5. pyproject.toml +14 -0
.gitignore ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+ .chainlit/
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ #poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/#use-with-ide
111
+ .pdm.toml
112
+
113
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
114
+ __pypackages__/
115
+
116
+ # Celery stuff
117
+ celerybeat-schedule
118
+ celerybeat.pid
119
+
120
+ # SageMath parsed files
121
+ *.sage.py
122
+
123
+ # Environments
124
+ .env
125
+ .venv
126
+ env/
127
+ venv/
128
+ ENV/
129
+ env.bak/
130
+ venv.bak/
131
+
132
+ # Spyder project settings
133
+ .spyderproject
134
+ .spyproject
135
+
136
+ # Rope project settings
137
+ .ropeproject
138
+
139
+ # mkdocs documentation
140
+ /site
141
+
142
+ # mypy
143
+ .mypy_cache/
144
+ .dmypy.json
145
+ dmypy.json
146
+
147
+ # Pyre type checker
148
+ .pyre/
149
+
150
+ # pytype static type analyzer
151
+ .pytype/
152
+
153
+ # Cython debug symbols
154
+ cython_debug/
155
+
156
+ # PyCharm
157
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
160
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
161
+ #.idea/
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Get a distribution that has uv already installed
2
+ FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
3
+
4
+ # Add Rust compiler installation
5
+ USER root
6
+ RUN apt-get update && apt-get install -y \
7
+ curl \
8
+ build-essential \
9
+ && rm -rf /var/lib/apt/lists/*
10
+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
11
+ ENV PATH="/root/.cargo/bin:${PATH}"
12
+
13
+ # Add user - this is the user that will run the app
14
+ # If you do not set user, the app will run as root (undesirable)
15
+ RUN useradd -m -u 1000 user
16
+ USER user
17
+
18
+ # Set up Rust for the user
19
+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
20
+ ENV PATH="/home/user/.cargo/bin:${PATH}"
21
+
22
+ # Set the home directory and path
23
+ ENV HOME=/home/user \
24
+ PATH=/home/user/.local/bin:$PATH
25
+
26
+ ENV UVICORN_WS_PROTOCOL=websockets
27
+
28
+ # Set the working directory
29
+ WORKDIR $HOME/app
30
+
31
+ # Copy the app to the container
32
+ COPY --chown=user . $HOME/app
33
+
34
+ # Install the dependencies
35
+ # RUN uv sync --frozen
36
+ RUN uv sync
37
+
38
+ # Expose the port
39
+ EXPOSE 7860
40
+
41
+ # Run the app
42
+ CMD ["uv", "run", "chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,11 +1,200 @@
1
  ---
2
- title: Llm App
3
- emoji: ๐Ÿ 
4
- colorFrom: yellow
5
- colorTo: gray
6
  sdk: docker
7
  pinned: false
8
- license: openrail
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: BeyondChatGPT Demo
3
+ emoji: ๐Ÿ“‰
4
+ colorFrom: pink
5
+ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
9
  ---
10
 
11
+ <p align = "center" draggable=โ€falseโ€ ><img src="https://github.com/AI-Maker-Space/LLM-Dev-101/assets/37101144/d1343317-fa2f-41e1-8af1-1dbb18399719"
12
+ width="200px"
13
+ height="auto"/>
14
+ </p>
15
+
16
+
17
+ ## <h1 align="center" id="heading">:wave: Welcome to Beyond ChatGPT!!</h1>
18
+
19
+ For a step-by-step YouTube video walkthrough, watch this! [Deploying Chainlit app on Hugging Face](https://www.youtube.com/live/pRbbZcL0NMI?si=NAYhMZ_suAY84f06&t=2119)
20
+
21
+ ![Beyond ChatGPT: Build Your First LLM Application](https://github.com/AI-Maker-Space/Beyond-ChatGPT/assets/48775140/cb7a74b8-28af-4d12-a008-8f5a51d47b4c)
22
+
23
+ ## ๐Ÿค– Your First LLM App
24
+
25
+ > If you need an introduction to `git`, or information on how to set up API keys for the tools we'll be using in this repository - check out our [Interactive Dev Environment for LLM Development](https://github.com/AI-Maker-Space/Interactive-Dev-Environment-for-LLM-Development/tree/main) which has everything you'd need to get started in this repository!
26
+
27
+ In this repository, we'll walk you through the steps to create a Large Language Model (LLM) application using Chainlit, then containerize it using Docker, and finally deploy it on Huggingface Spaces.
28
+
29
+ Are you ready? Let's get started!
30
+
31
+ <details>
32
+ <summary>๐Ÿ–ฅ๏ธ Accessing "gpt-3.5-turbo" (ChatGPT) like a developer</summary>
33
+
34
+ 1. Head to [this notebook](https://colab.research.google.com/drive/1mOzbgf4a2SP5qQj33ZxTz2a01-5eXqk2?usp=sharing) and follow along with the instructions!
35
+
36
+ 2. Complete the notebook and try out your own system/assistant messages!
37
+
38
+ That's it! Head to the next step and start building your application!
39
+
40
+ </details>
41
+
42
+
43
+ <details>
44
+ <summary>๐Ÿ—๏ธ Building Your First LLM App</summary>
45
+
46
+ 1. Clone [this](https://github.com/AI-Maker-Space/Beyond-ChatGPT/tree/main) repo.
47
+
48
+ ``` bash
49
+ git clone https://github.com/AI-Maker-Space/Beyond-ChatGPT.git
50
+ ```
51
+
52
+ 2. Navigate inside this repo
53
+ ``` bash
54
+ cd Beyond-ChatGPT
55
+ ```
56
+
57
+ 3. Create a virtual environment and install dependencies.
58
+ ``` bash
59
+ # Create a virtual environment
60
+ uv venv
61
+
62
+ # Activate the virtual environment
63
+ # On macOS/Linux:
64
+ source .venv/bin/activate
65
+ # On Windows:
66
+ # .venv\Scripts\activate
67
+
68
+ # Install dependencies from pyproject.toml
69
+ uv sync
70
+ ```
71
+
72
+ 4. Open your `.env` file. Replace the `###` in your `.env` file with your OpenAI Key and save the file.
73
+ ``` bash
74
+ OPENAI_API_KEY=sk-###
75
+ ```
76
+
77
+ 5. Let's try deploying it locally. Make sure you're in the activated virtual environment. Run the app using Chainlit. This may take a minute to run.
78
+ ``` bash
79
+ uv run chainlit run app.py -w
80
+ ```
81
+
82
+ <p align = "center" draggable="false">
83
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/54bcccf9-12e2-4cef-ab53-585c1e2b0fb5">
84
+ </p>
85
+
86
+ Great work! Let's see if we can interact with our chatbot.
87
+
88
+ <p align = "center" draggable="false">
89
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/854e4435-1dee-438a-9146-7174b39f7c61">
90
+ </p>
91
+
92
+ Awesome! Time to throw it into a docker container and prepare it for shipping!
93
+ </details>
94
+
95
+
96
+
97
+ <details>
98
+ <summary>๐Ÿณ Containerizing our App</summary>
99
+
100
+ 1. Let's build the Docker image. We'll tag our image as `llm-app` using the `-t` parameter. The `.` at the end means we want all of the files in our current directory to be added to our image. Note that our Dockerfile is set up to use uv for dependency management and will install all the packages defined in our pyproject.toml file.
101
+
102
+ ``` bash
103
+ docker build -t llm-app .
104
+ ```
105
+
106
+ 2. Run and test the Docker image locally using the `run` command. The `-p`parameter connects our **host port #** to the left of the `:` to our **container port #** on the right.
107
+
108
+ ``` bash
109
+ docker run -p 7860:7860 llm-app
110
+ ```
111
+
112
+ 3. Visit http://localhost:7860 in your browser to see if the app runs correctly.
113
+
114
+ <p align = "center" draggable="false">
115
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/2c764f25-09a0-431b-8d28-32246e0ca1b7">
116
+ </p>
117
+
118
+ Great! Time to ship!
119
+ </details>
120
+
121
+
122
+ <details>
123
+ <summary>๐Ÿš€ Deploying Your First LLM App</summary>
124
+
125
+ 1. Let's create a new Huggingface Space. Navigate to [Huggingface](https://huggingface.co) and click on your profile picture on the top right. Then click on `New Space`.
126
+
127
+ <p align = "center" draggable=โ€falseโ€>
128
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/f0656408-28b8-4876-9887-8f0c4b882bae">
129
+ </p>
130
+
131
+ 2. Setup your space as shown below:
132
+
133
+ - Owner: Your username
134
+ - Space Name: `llm-app`
135
+ - License: `Openrail`
136
+ - Select the Space SDK: `Docker`
137
+ - Docker Template: `Blank`
138
+ - Space Hardware: `CPU basic - 2 vCPU - 16 GB - Free`
139
+ - Repo type: `Public`
140
+
141
+ <p align = "center" draggable=โ€falseโ€>
142
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/8f16afd1-6b46-4d9f-b642-8fefe355c5c9">
143
+ </p>
144
+
145
+ 3. You should see something like this. We're now ready to send our files to our Huggingface Space. After cloning, move your files to this repo and push it along with your docker file. You DO NOT need to create a Dockerfile. Make sure NOT TO push your `.env` file. This should automatically be ignored.
146
+
147
+ <p align = "center" draggable=โ€falseโ€>
148
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/cbf366e2-7613-4223-932a-72c67a73f9c6">
149
+ </p>
150
+
151
+ 4. After pushing all files, navigate to the settings in the top right to add your OpenAI API key.
152
+
153
+ <p align = "center" draggable=โ€falseโ€>
154
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/a1123a6f-abdd-4f76-bea4-39acf9928762">
155
+ </p>
156
+
157
+ 5. Scroll down to `Variables and secrets` and click on `New secret` on the top right.
158
+
159
+ <p align = "center" draggable=โ€falseโ€>
160
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/a8a4a25d-752b-4036-b572-93381370c2db">
161
+ </p>
162
+
163
+ 6. Set the name to `OPENAI_API_KEY` and add your OpenAI key under `Value`. Click save.
164
+
165
+ <p align = "center" draggable=โ€falseโ€>
166
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/0a897538-1779-48ff-bcb4-486af30f7a14">
167
+ </p>
168
+
169
+ 7. To ensure your key is being used, we recommend you `Restart this Space`.
170
+
171
+ <p align = "center" draggable=โ€falseโ€>
172
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/fb1d83af-6ebe-4676-8bf5-b6d88f07c583">
173
+ </p>
174
+
175
+ 8. Congratulations! You just deployed your first LLM! ๐Ÿš€๐Ÿš€๐Ÿš€ Get on linkedin and post your results and experience! Make sure to tag us at #AIMakerspace !
176
+
177
+ Here's a template to get your post started!
178
+
179
+ ```
180
+ ๐Ÿš€๐ŸŽ‰ Exciting News! ๐ŸŽ‰๐Ÿš€
181
+
182
+ ๐Ÿ—๏ธย Today, I'm thrilled to announce that I've successfully built and shipped my first-ever LLM using the powerful combination of Chainlit, Docker, and the OpenAI API! ๐Ÿ–ฅ๏ธ
183
+
184
+ Check it out ๐Ÿ‘‡
185
+ [LINK TO APP]
186
+
187
+ A big shoutout to the @**AI Makerspace** for all making this possible. Couldn't have done it without the incredible community there. ๐Ÿค—๐Ÿ™
188
+
189
+ Looking forward to building with the community! ๐Ÿ™Œโœจย Here's to many more creations ahead! ๐Ÿฅ‚๐ŸŽ‰
190
+
191
+ Who else is diving into the world of AI? Let's connect! ๐ŸŒ๐Ÿ’ก
192
+
193
+ #FirstLLM #Chainlit #Docker #OpenAI #AIMakerspace
194
+ ```
195
+
196
+ </details>
197
+
198
+ <p></p>
199
+
200
+ ### That's it for now! And so it begins.... :)
chainlit.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Beyond ChatGPT
2
+
3
+ This Chainlit app was created following instructions from [this repository!](https://github.com/AI-Maker-Space/Beyond-ChatGPT)
pyproject.toml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "beyond-chatgpt"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "chainlit==0.7.700",
9
+ "cohere==4.37",
10
+ "openai==1.3.5",
11
+ "pydantic==2.10.1",
12
+ "python-dotenv==1.0.0",
13
+ "tiktoken==0.5.1",
14
+ ]