JKilpatrick commited on
Commit
5866751
1 Parent(s): e9dfa5b

Add application file

Browse files
Files changed (5) hide show
  1. .chainlit/config.toml +78 -0
  2. .gitignore +160 -0
  3. app.py +79 -0
  4. chainlit.md +3 -0
  5. requirements.txt +2 -0
.chainlit/config.toml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Authorize users to upload files with messages
22
+ multi_modal = true
23
+
24
+ # Allows user to use speech to text
25
+ [features.speech_to_text]
26
+ enabled = false
27
+ # See all languages here https://github.com/JamesBrill/react-speech-recognition/blob/HEAD/docs/API.md#language-string
28
+ # language = "en-US"
29
+
30
+ [UI]
31
+ # Name of the app and chatbot.
32
+ name = "Chatbot"
33
+
34
+ # Show the readme while the conversation is empty.
35
+ show_readme_as_default = true
36
+
37
+ # Description of the app and chatbot. This is used for HTML tags.
38
+ # description = ""
39
+
40
+ # Large size content are by default collapsed for a cleaner ui
41
+ default_collapse_content = true
42
+
43
+ # The default value for the expand messages settings.
44
+ default_expand_messages = false
45
+
46
+ # Hide the chain of thought details from the user in the UI.
47
+ hide_cot = false
48
+
49
+ # Link to your github repo. This will add a github button in the UI's header.
50
+ # github = ""
51
+
52
+ # Specify a CSS file that can be used to customize the user interface.
53
+ # The CSS file can be served from the public directory or via an external link.
54
+ # custom_css = "/public/test.css"
55
+
56
+ # Override default MUI light theme. (Check theme.ts)
57
+ [UI.theme.light]
58
+ #background = "#FAFAFA"
59
+ #paper = "#FFFFFF"
60
+
61
+ [UI.theme.light.primary]
62
+ #main = "#F80061"
63
+ #dark = "#980039"
64
+ #light = "#FFE7EB"
65
+
66
+ # Override default MUI dark theme. (Check theme.ts)
67
+ [UI.theme.dark]
68
+ #background = "#FAFAFA"
69
+ #paper = "#FFFFFF"
70
+
71
+ [UI.theme.dark.primary]
72
+ #main = "#F80061"
73
+ #dark = "#980039"
74
+ #light = "#FFE7EB"
75
+
76
+
77
+ [meta]
78
+ generated_by = "0.7.400"
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 (
8
+ Select,
9
+ Switch,
10
+ Slider,
11
+ ) # importing chainlit settings selection tools
12
+ from chainlit.prompt import Prompt, PromptMessage # importing prompt tools
13
+ from chainlit.playground.providers import ChatOpenAI # importing ChatOpenAI tools
14
+
15
+ # You only need the api key inserted here if it's not in your .env file
16
+ # openai.api_key = "YOUR_API_KEY"
17
+
18
+ # ChatOpenAI Templates
19
+ system_template = """You are a helpful assistant who always speaks in a pleasant tone!
20
+ """
21
+
22
+ user_template = """{input}
23
+ Think through your response step by step.
24
+ """
25
+
26
+
27
+ @cl.on_chat_start # marks a function that will be executed at the start of a user session
28
+ async def start_chat():
29
+ settings = {
30
+ "model": "gpt-3.5-turbo",
31
+ "temperature": 0,
32
+ "max_tokens": 500,
33
+ "top_p": 1,
34
+ "frequency_penalty": 0,
35
+ "presence_penalty": 0,
36
+ }
37
+
38
+ cl.user_session.set("settings", settings)
39
+
40
+
41
+ @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
42
+ async def main(message):
43
+ settings = cl.user_session.get("settings")
44
+
45
+ prompt = Prompt(
46
+ provider=ChatOpenAI.id,
47
+ messages=[
48
+ PromptMessage(
49
+ role="system",
50
+ template=system_template,
51
+ formatted=system_template,
52
+ ),
53
+ PromptMessage(
54
+ role="user",
55
+ template=user_template,
56
+ formatted=user_template.format(input=message.content),
57
+ ),
58
+ ],
59
+ inputs={"input": message.content},
60
+ settings=settings,
61
+ )
62
+
63
+ print([m.to_openai() for m in prompt.messages])
64
+
65
+ msg = cl.Message(content="")
66
+
67
+ # Call OpenAI
68
+ async for stream_resp in await openai.ChatCompletion.acreate(
69
+ messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
70
+ ):
71
+ token = stream_resp.choices[0]["delta"].get("content", "")
72
+ await msg.stream_token(token)
73
+
74
+ # Update the prompt object with the completion
75
+ prompt.completion = msg.content
76
+ msg.prompt = prompt
77
+
78
+ # Send and close the message stream
79
+ 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,2 @@
 
 
 
1
+ chainlit
2
+ openai