Spaces:
Sleeping
Sleeping
Akinkunle Akinola
commited on
Commit
•
6971c54
1
Parent(s):
5445609
Add application file
Browse files- .chainlit/.env +1 -0
- .chainlit/config.toml +66 -0
- Dockerfile +11 -0
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +74 -0
.chainlit/.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
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
|
.chainlit/config.toml
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
# Whether to enable telemetry (default: true). No personal data is collected.
|
3 |
+
enable_telemetry = true
|
4 |
+
|
5 |
+
# List of environment variables to be provided by each user to use the app.
|
6 |
+
user_env = []
|
7 |
+
|
8 |
+
# Duration (in seconds) during which the session is saved when the connection is lost
|
9 |
+
session_timeout = 3600
|
10 |
+
|
11 |
+
# Enable third parties caching (e.g LangChain cache)
|
12 |
+
cache = false
|
13 |
+
|
14 |
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
15 |
+
# follow_symlink = false
|
16 |
+
|
17 |
+
[features]
|
18 |
+
# Show the prompt playground
|
19 |
+
prompt_playground = true
|
20 |
+
|
21 |
+
[UI]
|
22 |
+
# Name of the app and chatbot.
|
23 |
+
name = "Chatbot"
|
24 |
+
|
25 |
+
# Description of the app and chatbot. This is used for HTML tags.
|
26 |
+
# description = ""
|
27 |
+
|
28 |
+
# Large size content are by default collapsed for a cleaner ui
|
29 |
+
default_collapse_content = true
|
30 |
+
|
31 |
+
# The default value for the expand messages settings.
|
32 |
+
default_expand_messages = false
|
33 |
+
|
34 |
+
# Hide the chain of thought details from the user in the UI.
|
35 |
+
hide_cot = false
|
36 |
+
|
37 |
+
# Link to your github repo. This will add a github button in the UI's header.
|
38 |
+
# github = ""
|
39 |
+
|
40 |
+
# Specify a CSS file that can be used to customize the user interface.
|
41 |
+
# The CSS file can be served from the public directory or via an external link.
|
42 |
+
# custom_css = "/public/test.css"
|
43 |
+
|
44 |
+
# Override default MUI light theme. (Check theme.ts)
|
45 |
+
[UI.theme.light]
|
46 |
+
#background = "#FAFAFA"
|
47 |
+
#paper = "#FFFFFF"
|
48 |
+
|
49 |
+
[UI.theme.light.primary]
|
50 |
+
#main = "#F80061"
|
51 |
+
#dark = "#980039"
|
52 |
+
#light = "#FFE7EB"
|
53 |
+
|
54 |
+
# Override default MUI dark theme. (Check theme.ts)
|
55 |
+
[UI.theme.dark]
|
56 |
+
#background = "#FAFAFA"
|
57 |
+
#paper = "#FFFFFF"
|
58 |
+
|
59 |
+
[UI.theme.dark.primary]
|
60 |
+
#main = "#F80061"
|
61 |
+
#dark = "#980039"
|
62 |
+
#light = "#FFE7EB"
|
63 |
+
|
64 |
+
|
65 |
+
[meta]
|
66 |
+
generated_by = "0.7.2"
|
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
RUN useradd -m -u 1000 user
|
3 |
+
USER user
|
4 |
+
ENV HOME=/Users/kakin \
|
5 |
+
PATH=/Users/kakin/.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"]
|
__pycache__/app.cpython-311.pyc
ADDED
Binary file (3.27 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# You can find this code for Chainlit python streaming here (https://docs.chainlit.io/concepts/streaming/python)
|
2 |
+
|
3 |
+
# OpenAI Chat completion
|
4 |
+
|
5 |
+
import openai #importing openai for API usage
|
6 |
+
import chainlit as cl #importing chainlit for our app
|
7 |
+
from chainlit.input_widget import Select, Switch, Slider #importing chainlit settings selection tools
|
8 |
+
from chainlit.prompt import Prompt, PromptMessage #importing prompt tools
|
9 |
+
from chainlit.playground.providers import ChatOpenAI #importing ChatOpenAI tools
|
10 |
+
|
11 |
+
# You only need the api key inserted here if it's not in your .env file
|
12 |
+
#openai.api_key = "YOUR_API_KEY"
|
13 |
+
|
14 |
+
# ChatOpenAI Templates
|
15 |
+
system_template = """You are a helpful assistant who always speaks in a pleasant tone!
|
16 |
+
"""
|
17 |
+
|
18 |
+
user_template = """{input}
|
19 |
+
Think through your response step by step.
|
20 |
+
"""
|
21 |
+
|
22 |
+
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
23 |
+
async def start_chat():
|
24 |
+
settings = {
|
25 |
+
"model": "gpt-3.5-turbo",
|
26 |
+
"temperature": 0,
|
27 |
+
"max_tokens": 500,
|
28 |
+
"top_p": 1,
|
29 |
+
"frequency_penalty": 0,
|
30 |
+
"presence_penalty": 0,
|
31 |
+
}
|
32 |
+
|
33 |
+
cl.user_session.set("settings", settings)
|
34 |
+
|
35 |
+
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
36 |
+
async def main(message: str):
|
37 |
+
|
38 |
+
settings = cl.user_session.get("settings")
|
39 |
+
|
40 |
+
prompt = Prompt(
|
41 |
+
provider=ChatOpenAI.id,
|
42 |
+
messages=[
|
43 |
+
PromptMessage(
|
44 |
+
role="system",
|
45 |
+
template=system_template,
|
46 |
+
formatted=system_template,
|
47 |
+
),
|
48 |
+
PromptMessage(
|
49 |
+
role="user",
|
50 |
+
template=user_template,
|
51 |
+
formatted=user_template.format(input=message),
|
52 |
+
)
|
53 |
+
],
|
54 |
+
inputs = {"input" : message},
|
55 |
+
settings=settings
|
56 |
+
)
|
57 |
+
|
58 |
+
print([m.to_openai() for m in prompt.messages])
|
59 |
+
|
60 |
+
msg = cl.Message(content="")
|
61 |
+
|
62 |
+
# Call OpenAI
|
63 |
+
async for stream_resp in await openai.ChatCompletion.acreate(
|
64 |
+
messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
|
65 |
+
):
|
66 |
+
token = stream_resp.choices[0]["delta"].get("content", "")
|
67 |
+
await msg.stream_token(token)
|
68 |
+
|
69 |
+
# Update the prompt object with the completion
|
70 |
+
prompt.completion = msg.content
|
71 |
+
msg.prompt = prompt
|
72 |
+
|
73 |
+
# Send and close the message stream
|
74 |
+
await msg.send()
|