drewgenai commited on
Commit
6bd9353
·
2 Parent(s): c8fb6b9945be61

message-here

Browse files
Files changed (9) hide show
  1. .chainlit/config.toml +84 -0
  2. .env.sample +1 -0
  3. .gitattributes +35 -0
  4. .gitignore +5 -0
  5. Dockerfile +11 -0
  6. README.md +193 -0
  7. app.py +80 -0
  8. chainlit.md +3 -0
  9. requirements.txt +5 -0
.chainlit/config.toml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ # Whether to enable telemetry (default: true). No personal data is collected.
3
+ enable_telemetry = true
4
+
5
+ # List of environment variables to be provided by each user to use the app.
6
+ user_env = []
7
+
8
+ # Duration (in seconds) during which the session is saved when the connection is lost
9
+ session_timeout = 3600
10
+
11
+ # Enable third parties caching (e.g LangChain cache)
12
+ cache = false
13
+
14
+ # Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
15
+ # follow_symlink = false
16
+
17
+ [features]
18
+ # Show the prompt playground
19
+ prompt_playground = true
20
+
21
+ # Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
22
+ unsafe_allow_html = false
23
+
24
+ # Process and display mathematical expressions. This can clash with "$" characters in messages.
25
+ latex = false
26
+
27
+ # Authorize users to upload files with messages
28
+ multi_modal = true
29
+
30
+ # Allows user to use speech to text
31
+ [features.speech_to_text]
32
+ enabled = false
33
+ # See all languages here https://github.com/JamesBrill/react-speech-recognition/blob/HEAD/docs/API.md#language-string
34
+ # language = "en-US"
35
+
36
+ [UI]
37
+ # Name of the app and chatbot.
38
+ name = "Chatbot"
39
+
40
+ # Show the readme while the conversation is empty.
41
+ show_readme_as_default = true
42
+
43
+ # Description of the app and chatbot. This is used for HTML tags.
44
+ # description = ""
45
+
46
+ # Large size content are by default collapsed for a cleaner ui
47
+ default_collapse_content = true
48
+
49
+ # The default value for the expand messages settings.
50
+ default_expand_messages = false
51
+
52
+ # Hide the chain of thought details from the user in the UI.
53
+ hide_cot = false
54
+
55
+ # Link to your github repo. This will add a github button in the UI's header.
56
+ # github = ""
57
+
58
+ # Specify a CSS file that can be used to customize the user interface.
59
+ # The CSS file can be served from the public directory or via an external link.
60
+ # custom_css = "/public/test.css"
61
+
62
+ # Override default MUI light theme. (Check theme.ts)
63
+ [UI.theme.light]
64
+ #background = "#FAFAFA"
65
+ #paper = "#FFFFFF"
66
+
67
+ [UI.theme.light.primary]
68
+ #main = "#F80061"
69
+ #dark = "#980039"
70
+ #light = "#FFE7EB"
71
+
72
+ # Override default MUI dark theme. (Check theme.ts)
73
+ [UI.theme.dark]
74
+ #background = "#FAFAFA"
75
+ #paper = "#FFFFFF"
76
+
77
+ [UI.theme.dark.primary]
78
+ #main = "#F80061"
79
+ #dark = "#980039"
80
+ #light = "#FFE7EB"
81
+
82
+
83
+ [meta]
84
+ generated_by = "0.7.700"
.env.sample ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY=###
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore CHANGED
@@ -106,10 +106,15 @@ ipython_config.py
106
  #pdm.lock
107
  # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
  # in version control.
 
109
  # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
  .pdm.toml
111
  .pdm-python
112
  .pdm-build/
 
 
 
 
113
 
114
  # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
  __pypackages__/
 
106
  #pdm.lock
107
  # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
  # in version control.
109
+ <<<<<<< HEAD
110
  # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111
  .pdm.toml
112
  .pdm-python
113
  .pdm-build/
114
+ =======
115
+ # https://pdm.fming.dev/#use-with-ide
116
+ .pdm.toml
117
+ >>>>>>> BCBranch
118
 
119
  # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
120
  __pypackages__/
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ RUN useradd -m -u 1000 user
3
+ USER user
4
+ ENV HOME=/home/user \
5
+ PATH=/home/user/.local/bin:$PATH
6
+ WORKDIR $HOME/app
7
+ COPY --chown=user . $HOME/app
8
+ COPY ./requirements.txt ~/app/requirements.txt
9
+ RUN pip install -r requirements.txt
10
+ COPY . .
11
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
README.md CHANGED
@@ -1,2 +1,195 @@
 
1
  # genaichal
2
  gen ai challenge repo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <<<<<<< HEAD
2
  # genaichal
3
  gen ai challenge repo
4
+ =======
5
+ ---
6
+ title: BeyondChatGPT Demo
7
+ emoji: 📉
8
+ colorFrom: pink
9
+ colorTo: yellow
10
+ sdk: docker
11
+ pinned: false
12
+ app_port: 7860
13
+ ---
14
+
15
+ <p align = "center" draggable=”false” ><img src="https://github.com/AI-Maker-Space/LLM-Dev-101/assets/37101144/d1343317-fa2f-41e1-8af1-1dbb18399719"
16
+ width="200px"
17
+ height="auto"/>
18
+ </p>
19
+
20
+
21
+ ## <h1 align="center" id="heading">:wave: Welcome to Beyond ChatGPT!!</h1>
22
+
23
+ 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)
24
+
25
+ ![Beyond ChatGPT: Build Your First LLM Application](https://github.com/AI-Maker-Space/Beyond-ChatGPT/assets/48775140/cb7a74b8-28af-4d12-a008-8f5a51d47b4c)
26
+
27
+ ## 🤖 Your First LLM App
28
+
29
+ > 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!
30
+
31
+ 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.
32
+
33
+ Are you ready? Let's get started!
34
+
35
+ <details>
36
+ <summary>🖥️ Accessing "gpt-3.5-turbo" (ChatGPT) like a developer</summary>
37
+
38
+ 1. Head to [this notebook](https://colab.research.google.com/drive/1mOzbgf4a2SP5qQj33ZxTz2a01-5eXqk2?usp=sharing) and follow along with the instructions!
39
+
40
+ 2. Complete the notebook and try out your own system/assistant messages!
41
+
42
+ That's it! Head to the next step and start building your application!
43
+
44
+ </details>
45
+
46
+
47
+ <details>
48
+ <summary>🏗️ Building Your First LLM App</summary>
49
+
50
+ 1. Clone [this](https://github.com/AI-Maker-Space/Beyond-ChatGPT/tree/main) repo.
51
+
52
+ ``` bash
53
+ git clone https://github.com/AI-Maker-Space/Beyond-ChatGPT.git
54
+ ```
55
+
56
+ 2. Navigate inside this repo
57
+ ``` bash
58
+ cd Beyond-ChatGPT
59
+ ```
60
+
61
+ 3. Install the packages required for this python envirnoment in `requirements.txt`.
62
+ ``` bash
63
+ pip install -r requirements.txt
64
+ ```
65
+
66
+ 4. Open your `.env` file. Replace the `###` in your `.env` file with your OpenAI Key and save the file.
67
+ ``` bash
68
+ OPENAI_API_KEY=sk-###
69
+ ```
70
+
71
+ 5. Let's try deploying it locally. Make sure you're in the python environment where you installed Chainlit and OpenAI. Run the app using Chainlit. This may take a minute to run.
72
+ ``` bash
73
+ chainlit run app.py -w
74
+ ```
75
+
76
+ <p align = "center" draggable=”false”>
77
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/54bcccf9-12e2-4cef-ab53-585c1e2b0fb5">
78
+ </p>
79
+
80
+ Great work! Let's see if we can interact with our chatbot.
81
+
82
+ <p align = "center" draggable=”false”>
83
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/854e4435-1dee-438a-9146-7174b39f7c61">
84
+ </p>
85
+
86
+ Awesome! Time to throw it into a docker container and prepare it for shipping!
87
+ </details>
88
+
89
+
90
+
91
+ <details>
92
+ <summary>🐳 Containerizing our App</summary>
93
+
94
+ 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.
95
+
96
+ ``` bash
97
+ docker build -t llm-app .
98
+ ```
99
+
100
+ 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.
101
+
102
+ ``` bash
103
+ docker run -p 7860:7860 llm-app
104
+ ```
105
+
106
+ 3. Visit http://localhost:7860 in your browser to see if the app runs correctly.
107
+
108
+ <p align = "center" draggable=”false”>
109
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/2c764f25-09a0-431b-8d28-32246e0ca1b7">
110
+ </p>
111
+
112
+ Great! Time to ship!
113
+ </details>
114
+
115
+
116
+ <details>
117
+ <summary>🚀 Deploying Your First LLM App</summary>
118
+
119
+ 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`.
120
+
121
+ <p align = "center" draggable=”false”>
122
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/f0656408-28b8-4876-9887-8f0c4b882bae">
123
+ </p>
124
+
125
+ 2. Setup your space as shown below:
126
+
127
+ - Owner: Your username
128
+ - Space Name: `llm-app`
129
+ - License: `Openrail`
130
+ - Select the Space SDK: `Docker`
131
+ - Docker Template: `Blank`
132
+ - Space Hardware: `CPU basic - 2 vCPU - 16 GB - Free`
133
+ - Repo type: `Public`
134
+
135
+ <p align = "center" draggable=”false”>
136
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/8f16afd1-6b46-4d9f-b642-8fefe355c5c9">
137
+ </p>
138
+
139
+ 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.
140
+
141
+ <p align = "center" draggable=”false”>
142
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/cbf366e2-7613-4223-932a-72c67a73f9c6">
143
+ </p>
144
+
145
+ 4. After pushing all files, navigate to the settings in the top right to add your OpenAI API key.
146
+
147
+ <p align = "center" draggable=”false”>
148
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/a1123a6f-abdd-4f76-bea4-39acf9928762">
149
+ </p>
150
+
151
+ 5. Scroll down to `Variables and secrets` and click on `New secret` on the top right.
152
+
153
+ <p align = "center" draggable=”false”>
154
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/a8a4a25d-752b-4036-b572-93381370c2db">
155
+ </p>
156
+
157
+ 6. Set the name to `OPENAI_API_KEY` and add your OpenAI key under `Value`. Click save.
158
+
159
+ <p align = "center" draggable=”false”>
160
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/0a897538-1779-48ff-bcb4-486af30f7a14">
161
+ </p>
162
+
163
+ 7. To ensure your key is being used, we recommend you `Restart this Space`.
164
+
165
+ <p align = "center" draggable=”false”>
166
+ <img src="https://github.com/AI-Maker-Space/LLMOps-Dev-101/assets/37101144/fb1d83af-6ebe-4676-8bf5-b6d88f07c583">
167
+ </p>
168
+
169
+ 8. Congratulations! You just deployed your first LLM! 🚀🚀🚀 Get on linkedin and post your results and experience! Make sure to tag us at #AIMakerspace !
170
+
171
+ Here's a template to get your post started!
172
+
173
+ ```
174
+ 🚀🎉 Exciting News! 🎉🚀
175
+
176
+ 🏗️ 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! 🖥️
177
+
178
+ Check it out 👇
179
+ [LINK TO APP]
180
+
181
+ A big shoutout to the @**AI Makerspace** for all making this possible. Couldn't have done it without the incredible community there. 🤗🙏
182
+
183
+ Looking forward to building with the community! 🙌✨ Here's to many more creations ahead! 🥂🎉
184
+
185
+ Who else is diving into the world of AI? Let's connect! 🌐💡
186
+
187
+ #FirstLLM #Chainlit #Docker #OpenAI #AIMakerspace
188
+ ```
189
+
190
+ </details>
191
+
192
+ <p></p>
193
+
194
+ ### That's it for now! And so it begins.... :)
195
+ >>>>>>> BCBranch
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # You can find this code for Chainlit python streaming here (https://docs.chainlit.io/concepts/streaming/python)
2
+
3
+ # OpenAI Chat completion
4
+ import os
5
+ from openai import AsyncOpenAI # importing openai for API usage
6
+ import chainlit as cl # importing chainlit for our app
7
+ from chainlit.prompt import Prompt, PromptMessage # importing prompt tools
8
+ from chainlit.playground.providers import ChatOpenAI # importing ChatOpenAI tools
9
+ from dotenv import load_dotenv
10
+
11
+ load_dotenv()
12
+
13
+ # ChatOpenAI Templates
14
+ system_template = """You are a helpful assistant who always speaks in a pleasant tone!
15
+ """
16
+
17
+ user_template = """{input}
18
+ Think through your response step by step.
19
+ """
20
+
21
+
22
+ @cl.on_chat_start # marks a function that will be executed at the start of a user session
23
+ async def start_chat():
24
+ settings = {
25
+ "model": "gpt-3.5-turbo",
26
+ "temperature": 0,
27
+ "max_tokens": 500,
28
+ "top_p": 1,
29
+ "frequency_penalty": 0,
30
+ "presence_penalty": 0,
31
+ }
32
+
33
+ cl.user_session.set("settings", settings)
34
+
35
+
36
+ @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
37
+ async def main(message: cl.Message):
38
+ settings = cl.user_session.get("settings")
39
+
40
+ client = AsyncOpenAI()
41
+
42
+ print(message.content)
43
+
44
+ prompt = Prompt(
45
+ provider=ChatOpenAI.id,
46
+ messages=[
47
+ PromptMessage(
48
+ role="system",
49
+ template=system_template,
50
+ formatted=system_template,
51
+ ),
52
+ PromptMessage(
53
+ role="user",
54
+ template=user_template,
55
+ formatted=user_template.format(input=message.content),
56
+ ),
57
+ ],
58
+ inputs={"input": message.content},
59
+ settings=settings,
60
+ )
61
+
62
+ print([m.to_openai() for m in prompt.messages])
63
+
64
+ msg = cl.Message(content="")
65
+
66
+ # Call OpenAI
67
+ async for stream_resp in await client.chat.completions.create(
68
+ messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
69
+ ):
70
+ token = stream_resp.choices[0].delta.content
71
+ if not token:
72
+ token = ""
73
+ await msg.stream_token(token)
74
+
75
+ # Update the prompt object with the completion
76
+ prompt.completion = msg.content
77
+ msg.prompt = prompt
78
+
79
+ # Send and close the message stream
80
+ await msg.send()
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)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ chainlit==0.7.700
2
+ cohere==4.37
3
+ openai==1.3.5
4
+ tiktoken==0.5.1
5
+ python-dotenv==1.0.0