-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
85 lines (75 loc) · 3.76 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Importing required packages
import streamlit as st
import openai
import promptlayer
st.set_page_config(page_title="Chat with WardleyGPT")
st.title("Chat with WardleyGPT")
st.sidebar.markdown("Developed by Mark Craddock](https://twitter.com/mcraddock)", unsafe_allow_html=True)
st.sidebar.markdown("Current Version: 0.2.0")
st.sidebar.markdown("Using GPT-4 API")
st.sidebar.markdown("Not optimised")
st.sidebar.markdown("May run out of OpenAI credits")
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
promptlayer.api_key = st.secrets["PROMPTLAYER"]
# gpt-3.5-turbo, gpt-4, and gpt-4-turbo-preview point to the latest model version
#MODEL = "gpt-3.5-turbo" # 4K, Sept 2021. Legacy. Currently points to gpt-3.5-turbo-0613.
#MODEL = "gpt-3.5-turbo-16k" # 16K, Sept 2021. Legacy. Snapshot of gpt-3.5-turbo from June 13th 2023. Will be deprecated on June 13, 2024
MODEL = "gpt-3.5-turbo-1106" # 16K, Sept 2021. New Updated GPT 3.5 Turbo. The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens.
#MODEL = "gpt-4" # 8K, Sept 2021
#MODEL = "gpt-4-32k" # 32K, Sept 2021
#MODEL = "gpt-4-turbo-preview" # 128K, Apr 2023
#MODEL = "gpt-4-1106-preview" # 128K, Apr 2023
DEBUG = True # True to overwrite files that already exist
# Swap out your 'import openai'
openai = promptlayer.openai
if "openai_model" not in st.session_state:
st.session_state["openai_model"] = MODEL
if "messages" not in st.session_state:
st.session_state.messages = []
st.session_state.messages.append({
"role": "system",
"content": f"""
You are SimonGPT a strategy researcher based in the UK.
“Researcher” means in the style of a strategy researcher with well over twenty years research in strategy and cloud computing.
You use complicated examples from Wardley Mapping in your answers, focusing on lesser-known advice to better illustrate your arguments.
Your language should be for an 12 year old to understand.
If you do not know the answer to a question, do not make information up - instead, ask a follow-up question in order to gain more context.
Use a mix of technical and colloquial uk englishlanguage to create an accessible and engaging tone.
Provide your answers using Wardley Mapping in a form of a sarcastic tweet.
Start by introducing yourself
"""
})
st.session_state.messages.append(
{
"role": "user",
"content": ""
})
st.session_state.messages.append(
{
"role": "assistant",
"content": ""
})
for message in st.session_state.messages:
if message["role"] in ["user", "assistant"]:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("Ask me anything about Wardley Mapping?"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
message_placeholder = st.empty()
full_response = ""
for response in openai.ChatCompletion.create(
model=st.session_state["openai_model"],
messages=[
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
],
stream=True,
pl_tags=["wardleychatbot"],
):
full_response += response.choices[0].delta.get("content", "")
message_placeholder.markdown(full_response + "▌")
message_placeholder.markdown(full_response)
st.session_state.messages.append({"role": "assistant", "content": full_response})