Serjesh commited on
Commit
95ddf3a
·
1 Parent(s): 2d2ed84

Adding docker files

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +76 -0
  3. chainlit.md +3 -0
  4. requirements.txt +3 -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,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import openai # 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
+ openai.api_key = os.environ["OPENAI_API_KEY"]
14
+
15
+ # ChatOpenAI Templates
16
+ system_template = """You are a helpful assistant who always speaks in a pleasant tone!
17
+ """
18
+
19
+ user_template = """{input}
20
+ Think through your response step by step.
21
+ """
22
+
23
+
24
+ @cl.on_chat_start # marks a function that will be executed at the start of a user session
25
+ async def start_chat():
26
+ settings = {
27
+ "model": "gpt-3.5-turbo",
28
+ "temperature": 0,
29
+ "max_tokens": 500,
30
+ "top_p": 1,
31
+ "frequency_penalty": 0,
32
+ "presence_penalty": 0,
33
+ }
34
+
35
+ cl.user_session.set("settings", settings)
36
+
37
+
38
+ @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
39
+ async def main(message: str):
40
+ settings = cl.user_session.get("settings")
41
+
42
+ prompt = Prompt(
43
+ provider=ChatOpenAI.id,
44
+ messages=[
45
+ PromptMessage(
46
+ role="system",
47
+ template=system_template,
48
+ formatted=system_template,
49
+ ),
50
+ PromptMessage(
51
+ role="user",
52
+ template=user_template,
53
+ formatted=user_template.format(input=message),
54
+ ),
55
+ ],
56
+ inputs={"input": message},
57
+ settings=settings,
58
+ )
59
+
60
+ print([m.to_openai() for m in prompt.messages])
61
+
62
+ msg = cl.Message(content="")
63
+
64
+ # Call OpenAI
65
+ async for stream_resp in await openai.ChatCompletion.acreate(
66
+ messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
67
+ ):
68
+ token = stream_resp.choices[0]["delta"].get("content", "")
69
+ await msg.stream_token(token)
70
+
71
+ # Update the prompt object with the completion
72
+ prompt.completion = msg.content
73
+ msg.prompt = prompt
74
+
75
+ # Send and close the message stream
76
+ 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,3 @@
 
 
 
 
1
+ chainlit==0.7.0
2
+ openai==0.28.0
3
+ python-dotenv==1.0.0