CSAle commited on
Commit
8c18b31
1 Parent(s): 42ebcde

Updating Chainlit Message Reference

Browse files
Files changed (2) hide show
  1. .chainlit/config.toml +78 -0
  2. app.py +19 -14
.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"
app.py CHANGED
@@ -2,14 +2,18 @@
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!
@@ -19,7 +23,8 @@ 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",
@@ -32,9 +37,9 @@ async def start_chat():
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):
37
 
 
 
38
  settings = cl.user_session.get("settings")
39
 
40
  prompt = Prompt(
@@ -47,12 +52,12 @@ async def main(message):
47
  ),
48
  PromptMessage(
49
  role="user",
50
- template=user_template,
51
- formatted=user_template.format(input=message),
52
- )
53
  ],
54
- inputs = {"input" : message.content},
55
- settings=settings
56
  )
57
 
58
  print([m.to_openai() for m in prompt.messages])
 
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!
 
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",
 
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(
 
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])