arthikrangan commited on
Commit
b10d4a2
Β·
1 Parent(s): f6ef527

Initial push with updated sys prompt

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +87 -0
  3. chainlit.md +23 -0
  4. requirements.txt +5 -0
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"]
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = """
15
+ You're an AI buddy to simplify tough topics for everyone. Your mission is to clearly answer questions on any subject.
16
+
17
+ Your answers MUST be unbiased and free from stereotypes. Avoid errors and complicated words that can confuse.
18
+
19
+ Remember, you will be penalized for any incorrect or misleading information.
20
+
21
+ Your aim is to spark curiosity and make understanding a wide range of subjects easier.
22
+ """
23
+
24
+ user_template = """{input}
25
+ Think through your response step by step.
26
+ """
27
+
28
+
29
+ @cl.on_chat_start # marks a function that will be executed at the start of a user session
30
+ async def start_chat():
31
+ settings = {
32
+ "model": "gpt-3.5-turbo",
33
+ "temperature": 0,
34
+ "max_tokens": 500,
35
+ "top_p": 1,
36
+ "frequency_penalty": 0,
37
+ "presence_penalty": 0,
38
+ }
39
+
40
+ cl.user_session.set("settings", settings)
41
+
42
+
43
+ @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
44
+ async def main(message: cl.Message):
45
+ settings = cl.user_session.get("settings")
46
+
47
+ client = AsyncOpenAI()
48
+
49
+ print(message.content)
50
+
51
+ prompt = Prompt(
52
+ provider=ChatOpenAI.id,
53
+ messages=[
54
+ PromptMessage(
55
+ role="system",
56
+ template=system_template,
57
+ formatted=system_template,
58
+ ),
59
+ PromptMessage(
60
+ role="user",
61
+ template=user_template,
62
+ formatted=user_template.format(input=message.content),
63
+ ),
64
+ ],
65
+ inputs={"input": message.content},
66
+ settings=settings,
67
+ )
68
+
69
+ print([m.to_openai() for m in prompt.messages])
70
+
71
+ msg = cl.Message(content="")
72
+
73
+ # Call OpenAI
74
+ async for stream_resp in await client.chat.completions.create(
75
+ messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
76
+ ):
77
+ token = stream_resp.choices[0].delta.content
78
+ if not token:
79
+ token = ""
80
+ await msg.stream_token(token)
81
+
82
+ # Update the prompt object with the completion
83
+ prompt.completion = msg.content
84
+ msg.prompt = prompt
85
+
86
+ # Send and close the message stream
87
+ await msg.send()
chainlit.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## 🌟 **Welcome to AskAway, Your AI Buddy!** 🌟
3
+
4
+ Hey there! I'm here to be your go-to pal for unraveling the mysteries of just about *anything*. Whether you're curious about quantum physics, the intricacies of art history, or just need to understand the latest tech trends, I've got your back. πŸš€
5
+
6
+ ### πŸ” **How I Can Help:**
7
+
8
+ - **Simplify Complex Topics:** If it feels like rocket science, I'll bring it down to Earth for you.
9
+ - **Answer Questions:** Big or small, ask away. There's no such thing as a silly question here.
10
+ - **Explore New Subjects:** Curious about something new? Let's dive in together and learn something cool.
11
+ - **Homework Helper:** Stuck on a tough problem? I can guide you through it step by step.
12
+
13
+ ### 🀝 **Our Mission Together:**
14
+
15
+ To make learning and understanding as easy and accessible as a chat with a friend. No matter where you are on your learning journey, I'm here to support you with clear, easy-to-understand answers and explanations. Think of me as your personal explainer, always ready to demystify the complicated stuff.
16
+
17
+ ### πŸ’‘ **Ready to Start?**
18
+
19
+ Just type your question or let me know what topic you're interested in, and we'll take it from there. Together, we'll make sure you get the clarity you need. Let's tackle those tough topics, one question at a time!
20
+
21
+ ---
22
+
23
+ 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