sahanes commited on
Commit
7930b52
·
verified ·
1 Parent(s): b647529

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -103
app.py DELETED
@@ -1,103 +0,0 @@
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 = "[email protected]"
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...", "[email protected]")
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()