Du Mingzhe commited on
Commit
0e7cc61
·
1 Parent(s): 79c91ff
Files changed (2) hide show
  1. app.py +7 -2
  2. playground.ipynb +70 -0
app.py CHANGED
@@ -2,6 +2,7 @@ from pinecone import Pinecone
2
  from datetime import datetime
3
  from openai import OpenAI
4
  import streamlit as st
 
5
 
6
  st.title("Talk with Mingzhe 🔮")
7
 
@@ -18,7 +19,6 @@ def response_generate(prompt, history):
18
  # Session History
19
  messages += [{"role": h["role"], "content": h["content"]} for h in history]
20
 
21
- print(messages)
22
 
23
  stream = llm_client.chat.completions.create(
24
  model = "gpt-4-1106-preview",
@@ -29,6 +29,7 @@ def response_generate(prompt, history):
29
 
30
  if "messages" not in st.session_state:
31
  st.session_state.messages = []
 
32
 
33
  for message in st.session_state.messages:
34
  with st.chat_message(message["role"]):
@@ -42,4 +43,8 @@ if prompt := st.chat_input("What's up?"):
42
  with st.chat_message("assistant"):
43
  stream = response_generate(prompt, st.session_state.messages)
44
  response = st.write_stream(stream)
45
- st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
 
 
2
  from datetime import datetime
3
  from openai import OpenAI
4
  import streamlit as st
5
+ import uuid
6
 
7
  st.title("Talk with Mingzhe 🔮")
8
 
 
19
  # Session History
20
  messages += [{"role": h["role"], "content": h["content"]} for h in history]
21
 
 
22
 
23
  stream = llm_client.chat.completions.create(
24
  model = "gpt-4-1106-preview",
 
29
 
30
  if "messages" not in st.session_state:
31
  st.session_state.messages = []
32
+ st.session_state['sid'] = uuid.uuid1().hex
33
 
34
  for message in st.session_state.messages:
35
  with st.chat_message(message["role"]):
 
43
  with st.chat_message("assistant"):
44
  stream = response_generate(prompt, st.session_state.messages)
45
  response = st.write_stream(stream)
46
+ st.session_state.messages.append({"role": "assistant", "content": response})
47
+
48
+ st.session_state.messages.append({"role": "assistant", "content": st.session_state['sid']})
49
+
50
+
playground.ipynb ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import uuid"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 3,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "sid = uuid.uuid1()"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 5,
24
+ "metadata": {},
25
+ "outputs": [
26
+ {
27
+ "data": {
28
+ "text/plain": [
29
+ "'4d742a38dea811ee8aad1e30bc5366a5'"
30
+ ]
31
+ },
32
+ "execution_count": 5,
33
+ "metadata": {},
34
+ "output_type": "execute_result"
35
+ }
36
+ ],
37
+ "source": [
38
+ "sid.hex"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": null,
44
+ "metadata": {},
45
+ "outputs": [],
46
+ "source": []
47
+ }
48
+ ],
49
+ "metadata": {
50
+ "kernelspec": {
51
+ "display_name": "toy",
52
+ "language": "python",
53
+ "name": "python3"
54
+ },
55
+ "language_info": {
56
+ "codemirror_mode": {
57
+ "name": "ipython",
58
+ "version": 3
59
+ },
60
+ "file_extension": ".py",
61
+ "mimetype": "text/x-python",
62
+ "name": "python",
63
+ "nbconvert_exporter": "python",
64
+ "pygments_lexer": "ipython3",
65
+ "version": "3.9.16"
66
+ }
67
+ },
68
+ "nbformat": 4,
69
+ "nbformat_minor": 2
70
+ }