completed
Browse files- .gitattributes +1 -0
- README.md +19 -13
- app.py +68 -0
- chainlit.md +14 -0
- hitchhikers.pdf +3 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
|
|
|
|
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
|
36 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,13 +1,19 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Building A Finetuning Machine Using Chainlit
|
2 |
+
|
3 |
+
Today we'll take a look at how we can wrap our finetuning process into Chainlit and have our own dynamic fine-tuning machine.
|
4 |
+
|
5 |
+
We'll be leveraging [this](https://github.com/AI-Maker-Space/LLM-Ops-Cohort-1/blob/main/Week%202/Thursday/Automated%20Fine-tuning%20with%20LLamaIndex.ipynb) notebook for finetuning.
|
6 |
+
|
7 |
+
Find worked-out notebook at this [repo](https://github.com/PanoEvJ/LLMOps/tree/main/Week%202/Thursday).
|
8 |
+
|
9 |
+
# Build ποΈ
|
10 |
+
There are 2 main tasks for this assignment:
|
11 |
+
|
12 |
+
- Verify you can run the notebook
|
13 |
+
- Wrap the notebook using Chainlit
|
14 |
+
|
15 |
+
# Ship π’
|
16 |
+
Construct a Chainlit application using the notebook that allows users to interface with the application.
|
17 |
+
|
18 |
+
# Share π
|
19 |
+
Make a social media post about your final application and tag @AIMakerspace
|
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
|
4 |
+
from llama_index.query_engine.retriever_query_engine import RetrieverQueryEngine
|
5 |
+
from llama_index.callbacks.base import CallbackManager
|
6 |
+
from llama_index import (
|
7 |
+
LLMPredictor,
|
8 |
+
ServiceContext,
|
9 |
+
StorageContext,
|
10 |
+
load_index_from_storage,
|
11 |
+
)
|
12 |
+
from llama_index.llms import OpenAI
|
13 |
+
import chainlit as cl
|
14 |
+
|
15 |
+
|
16 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
17 |
+
|
18 |
+
try:
|
19 |
+
# rebuild storage context
|
20 |
+
storage_context = StorageContext.from_defaults(persist_dir="./storage")
|
21 |
+
# load index
|
22 |
+
index = load_index_from_storage(storage_context)
|
23 |
+
except:
|
24 |
+
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
|
25 |
+
|
26 |
+
documents = SimpleDirectoryReader(input_files=["hitchhikers.pdf"]).load_data()
|
27 |
+
index = GPTVectorStoreIndex.from_documents(documents)
|
28 |
+
index.storage_context.persist()
|
29 |
+
|
30 |
+
|
31 |
+
@cl.on_chat_start
|
32 |
+
async def factory():
|
33 |
+
llm_predictor = LLMPredictor(
|
34 |
+
llm=OpenAI(
|
35 |
+
temperature=0,
|
36 |
+
model="ft:gpt-3.5-turbo-0613:personal::7rG4voK4",
|
37 |
+
streaming=True,
|
38 |
+
context_window=2048,
|
39 |
+
),
|
40 |
+
)
|
41 |
+
service_context = ServiceContext.from_defaults(
|
42 |
+
llm_predictor=llm_predictor,
|
43 |
+
chunk_size=512,
|
44 |
+
callback_manager=CallbackManager([cl.LlamaIndexCallbackHandler()]),
|
45 |
+
)
|
46 |
+
|
47 |
+
query_engine = index.as_query_engine(
|
48 |
+
service_context=service_context,
|
49 |
+
streaming=True,
|
50 |
+
)
|
51 |
+
|
52 |
+
cl.user_session.set("query_engine", query_engine)
|
53 |
+
|
54 |
+
|
55 |
+
@cl.on_message
|
56 |
+
async def main(message):
|
57 |
+
query_engine = cl.user_session.get("query_engine") # type: RetrieverQueryEngine
|
58 |
+
response = await cl.make_async(query_engine.query)(message)
|
59 |
+
|
60 |
+
response_message = cl.Message(content="")
|
61 |
+
|
62 |
+
for token in response.response_gen:
|
63 |
+
await response_message.stream_token(token=token)
|
64 |
+
|
65 |
+
if response.response_txt:
|
66 |
+
response_message.content = response.response_txt
|
67 |
+
|
68 |
+
await response_message.send()
|
chainlit.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Welcome to Chainlit! ππ€
|
2 |
+
|
3 |
+
Hi there, Developer! π We're excited to have you on board. Chainlit is a powerful tool designed to help you prototype, debug and share applications built on top of LLMs.
|
4 |
+
|
5 |
+
## Useful Links π
|
6 |
+
|
7 |
+
- **Documentation:** Get started with our comprehensive [Chainlit Documentation](https://docs.chainlit.io) π
|
8 |
+
- **Discord Community:** Join our friendly [Chainlit Discord](https://discord.gg/ZThrUxbAYw) to ask questions, share your projects, and connect with other developers! π¬
|
9 |
+
|
10 |
+
We can't wait to see what you create with Chainlit! Happy coding! π»π
|
11 |
+
|
12 |
+
## Welcome screen
|
13 |
+
|
14 |
+
To modify the welcome screen, edit the `chainlit.md` file at the root of your project. If you do not want a welcome screen, just leave this file empty.
|
hitchhikers.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fbf013abdefb5a9f2bccd3f7345467712213d4f247ce29846045056e8cf603c1
|
3 |
+
size 3402125
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
chainlit==0.6.3
|
2 |
+
llama_index==0.8.9
|
3 |
+
openai==0.27.9
|