CSAle commited on
Commit
7cc3907
1 Parent(s): 8c18b31

Updating App and Requirements

Browse files
Files changed (5) hide show
  1. .chainlit/config.toml +0 -78
  2. .env +0 -1
  3. .env.sample +1 -0
  4. app.py +13 -12
  5. requirements.txt +5 -2
.chainlit/config.toml DELETED
@@ -1,78 +0,0 @@
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"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.env DELETED
@@ -1 +0,0 @@
1
- OPENAI_API_KEY=sk-###
 
 
.env.sample ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY=###
app.py CHANGED
@@ -1,19 +1,14 @@
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!
@@ -39,9 +34,13 @@ async def start_chat():
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=[
@@ -65,10 +64,12 @@ async def main(message):
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
 
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 = """You are a helpful assistant who always speaks in a pleasant tone!
 
34
 
35
 
36
  @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
37
+ async def main(message: cl.Message):
38
  settings = cl.user_session.get("settings")
39
 
40
+ client = AsyncOpenAI()
41
+
42
+ print(message.content)
43
+
44
  prompt = Prompt(
45
  provider=ChatOpenAI.id,
46
  messages=[
 
64
  msg = cl.Message(content="")
65
 
66
  # Call OpenAI
67
+ async for stream_resp in await client.chat.completions.create(
68
  messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
69
  ):
70
+ token = stream_resp.choices[0].delta.content
71
+ if not token:
72
+ token = ""
73
  await msg.stream_token(token)
74
 
75
  # Update the prompt object with the completion
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
- chainlit
2
- openai
 
 
 
 
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