Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from streamlit_extras.stylable_container import stylable_container
|
|
| 5 |
import re
|
| 6 |
import urllib.parse
|
| 7 |
import traceback
|
|
|
|
| 8 |
|
| 9 |
st.title("Nvidia Chat UI")
|
| 10 |
|
|
@@ -29,6 +30,12 @@ else:
|
|
| 29 |
if "messages" not in st.session_state:
|
| 30 |
st.session_state.messages = []
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def get_ai_response(prompt, chat_history):
|
| 33 |
st.session_state.is_streaming = True
|
| 34 |
st.session_state.response = ""
|
|
|
|
| 5 |
import re
|
| 6 |
import urllib.parse
|
| 7 |
import traceback
|
| 8 |
+
import tiktoken
|
| 9 |
|
| 10 |
st.title("Nvidia Chat UI")
|
| 11 |
|
|
|
|
| 30 |
if "messages" not in st.session_state:
|
| 31 |
st.session_state.messages = []
|
| 32 |
|
| 33 |
+
encoding = tiktoken.get_encoding("cl100k_base")
|
| 34 |
+
|
| 35 |
+
def num_tokens_from_string(string):
|
| 36 |
+
num_tokens = len(encoding.encode(string))
|
| 37 |
+
return num_tokens
|
| 38 |
+
|
| 39 |
def get_ai_response(prompt, chat_history):
|
| 40 |
st.session_state.is_streaming = True
|
| 41 |
st.session_state.response = ""
|