MCPcopy
hub / github.com/Tele-AI/Telechat / main

Function main

service/web_demo.py:30–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28
29
30def main():
31 url = "http://0.0.0.0:8070/telechat/gptDialog/v2"
32 messages = init_chat_history()
33 prompt = st.chat_input("Shift + Enter 换行, Enter 发送")
34 if prompt:
35 with st.chat_message("user", avatar='user'):
36 st.markdown(prompt)
37 messages.append({"role": "user", "content": prompt})
38 print(f"[user] {prompt}", flush=True)
39 with st.chat_message("bot", avatar="assistant"):
40 placeholder = st.empty()
41 data = {"dialog": messages}
42 headers = {"Content-Type": "application/json"}
43 res = requests.post(url=url, data=json.dumps(data), headers=headers, stream=True)
44 response = ""
45 for chunk in res.iter_content(chunk_size=1024):
46 response += chunk.decode(encoding="utf-8")
47 placeholder.markdown(response)
48
49 messages.append({"role": "bot", "content": response})
50 print(json.dumps(messages, ensure_ascii=False), flush=True)
51
52 st.button("清空对话", on_click=clear_chat_history)
53
54
55if __name__ == "__main__":

Callers 1

web_demo.pyFile · 0.70

Calls 2

init_chat_historyFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected