OuroborosM commited on
Commit
217671d
·
1 Parent(s): 55f3887

add colored code

Browse files
Files changed (2) hide show
  1. app.py +14 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -32,7 +32,9 @@ import torch
32
  from langchain.chains import LLMMathChain
33
  from interpreter.code_interpreter import CodeInterpreter
34
 
35
-
 
 
36
 
37
  langchain.debug = True
38
 
@@ -43,6 +45,9 @@ CurrentAgent = 'Structured Zero Short Agent'
43
  global Audio_output
44
  Audio_output = []
45
 
 
 
 
46
  class DB_Search2(BaseTool):
47
  name = "Vector Database Search"
48
  description = "This is the internal vector database to search information firstly (i.e. engineering data, acronym.)"
@@ -418,5 +423,12 @@ if prompt := st.chat_input(placeholder="Input Your Request"):
418
  st_cb = StreamlitCallbackHandler(st.container(), expand_new_thoughts=False)
419
  response = agent.run(prompt, callbacks=[st_cb])
420
  # st.write(response)
421
- st.markdown(response)
 
 
 
 
 
 
 
422
  print(msgs.messages)
 
32
  from langchain.chains import LLMMathChain
33
  from interpreter.code_interpreter import CodeInterpreter
34
 
35
+ from pygments import highlight
36
+ from pygments.lexers import PythonLexer
37
+ from pygments.formatters import HtmlFormatter
38
 
39
  langchain.debug = True
40
 
 
45
  global Audio_output
46
  Audio_output = []
47
 
48
+ def colored_code_block(code: str):
49
+ return highlight(code, PythonLexer(), HtmlFormatter(style="monokai"))
50
+
51
  class DB_Search2(BaseTool):
52
  name = "Vector Database Search"
53
  description = "This is the internal vector database to search information firstly (i.e. engineering data, acronym.)"
 
423
  st_cb = StreamlitCallbackHandler(st.container(), expand_new_thoughts=False)
424
  response = agent.run(prompt, callbacks=[st_cb])
425
  # st.write(response)
426
+ # st.markdown(response)
427
+
428
+ for content in response:
429
+ if isinstance(content, str):
430
+ st.write(content)
431
+ elif isinstance(content, dict) and content.get('type') == 'code':
432
+ st.markdown(colored_code_block(content.get('code')), unsafe_allow_html=True)
433
+
434
  print(msgs.messages)
requirements.txt CHANGED
@@ -31,3 +31,4 @@ regex
31
  graphviz
32
  streamlit
33
  streamlit_chat
 
 
31
  graphviz
32
  streamlit
33
  streamlit_chat
34
+ pygments