sahanes commited on
Commit
93b65d5
1 Parent(s): 0ea74ee

Add Dockerfile, app.py, and requirements.txt for LLM app

Browse files
Files changed (3) hide show
  1. Dockerfile +28 -0
  2. app.py +103 -0
  3. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Install system dependencies
4
+ RUN apt-get update && \
5
+ apt-get install -y build-essential gfortran
6
+
7
+ # Create a non-root user
8
+ RUN useradd -m -u 1000 user
9
+ USER user
10
+
11
+ # Set environment variables
12
+ ENV HOME=/home/user \
13
+ PATH=/home/user/.local/bin:$PATH
14
+
15
+ # Set working directory
16
+ WORKDIR $HOME/app
17
+
18
+ # Copy requirements file and install dependencies
19
+ COPY --chown=user . $HOME/app
20
+ COPY ./requirements.txt $HOME/app/requirements.txt
21
+
22
+ RUN pip install --user -r requirements.txt
23
+
24
+ # Copy application code
25
+ COPY . .
26
+
27
+ # Command to run the application
28
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # You can find this code for Chainlit python streaming here (https://docs.chainlit.io/concepts/streaming/python)
2
+
3
+ import chainlit as cl
4
+ # Define a dictionary to keep track of user states
5
+ from openai import AsyncOpenAI # importing openai for API usage
6
+
7
+ client = AsyncOpenAI()
8
+
9
+
10
+ settings = {
11
+ "model": "gpt-3.5-turbo",
12
+ "temperature": 0.7,
13
+ "max_tokens": 500,
14
+ "top_p": 1,
15
+ "frequency_penalty": 0,
16
+ "presence_penalty": 0,
17
+ }
18
+
19
+ @cl.set_starters
20
+ async def set_starters():
21
+
22
+ return [
23
+ cl.Starter(
24
+ label="Morning routine ideation",
25
+ message="Can you help me create a personalized morning routine that would help increase my productivity throughout the day? Start by asking me about my current habits and what activities energize me in the morning.",
26
+ icon="/public/idea.svg",
27
+ ),
28
+
29
+ cl.Starter(
30
+ label="Explain superconductors",
31
+ message="Explain superconductors like I'm five years old.",
32
+ icon="/public/learn.svg",
33
+ ),
34
+
35
+ cl.Starter(
36
+ label="Python script for daily email reports",
37
+ message="Write a script to automate sending daily email reports in Python, and walk me through how I would set it up.",
38
+ icon="/public/terminal.svg",
39
+ ),
40
+
41
+ cl.Starter(
42
+ label="Text inviting friend to wedding",
43
+ message="Write a text asking a friend to be my plus-one at a wedding next month. I want to keep it super short and casual, and offer an out.",
44
+ icon="/public/write.svg",
45
+ )
46
+ ]
47
+ @cl.on_message
48
+ async def on_message(message):
49
+
50
+ content=message.content
51
+ if "morning routine" in content:
52
+ await cl.Message(content="Sure! Let's start with your current habits. What time do you usually wake up, and what are the first things you do after waking up?").send()
53
+ elif "superconductors" in content:
54
+ await cl.Message(content="Superconductors are special materials that can carry electricity without any resistance, like a super-fast slide where nothing slows you down!").send()
55
+ elif "Python script for daily email reports" in content:
56
+ await cl.Message(content="To automate sending daily email reports, you can use the smtplib library in Python. Here's a basic example:").send()
57
+ await cl.Message(content="""
58
+ ```python
59
+ import smtplib
60
+ from email.mime.text import MIMEText
61
+ from email.mime.multipart import MIMEMultipart
62
+
63
+ def send_email(subject, body, to_email):
64
+ from_email = "your_email@example.com"
65
+ from_password = "your_password"
66
+
67
+ msg = MIMEMultipart()
68
+ msg['From'] = from_email
69
+ msg['To'] = to_email
70
+ msg['Subject'] = subject
71
+
72
+ msg.attach(MIMEText(body, 'plain'))
73
+
74
+ server = smtplib.SMTP('smtp.example.com', 587)
75
+ server.starttls()
76
+ server.login(from_email, from_password)
77
+ text = msg.as_string()
78
+ server.sendmail(from_email, to_email, text)
79
+ server.quit()
80
+
81
+ send_email("Daily Report", "Here is the daily report...", "recipient@example.com")
82
+
83
+ """).send()
84
+ elif "Text inviting friend to wedding" in content:
85
+ await cl.Message("Hey! I have a wedding to attend next month and I'd love for you to be my plus-one. No worries if you can't make it, just thought I'd ask!").send()
86
+
87
+ #**********************************
88
+ prompt_messages = [
89
+ {"role": "user", "content": content}
90
+ ]
91
+
92
+ stream = await client.chat.completions.create(
93
+ messages=prompt_messages, stream=True, **settings
94
+ )
95
+
96
+ msg = cl.Message(content="")
97
+
98
+ async for part in stream:
99
+ if token := part.choices[0].delta.content:
100
+ await msg.stream_token(token)
101
+
102
+ # Send the final message
103
+ await msg.send()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ chainlit==1.1.300rc4
2
+ cohere==4.37
3
+ openai==1.3.5
4
+ tiktoken==0.7.0
5
+ python-dotenv==1.0.0
6
+ daal==2021.2.3
7
+ numpy