anderson999 commited on
Commit
569bd60
1 Parent(s): 2a04b87

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+
4
+ import os
5
+ os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
6
+
7
+
8
+ from langchain.chat_models import ChatOpenAI
9
+ from langchain.schema import (
10
+ AIMessage,
11
+ HumanMessage,
12
+ SystemMessage
13
+ )
14
+
15
+ # From here down is all the StreamLit UI
16
+ st.set_page_config(page_title="Def_off_Testing", page_icon=":robot:")
17
+ st.header("Defensive_Offensive_LLM_Test")
18
+
19
+
20
+
21
+ # if "sessionMessages" not in st.session_state:
22
+ st.session_state.sessionMessages = [
23
+ SystemMessage(content="You are playing a game where you have to team up with 2 AI agents to fight a team of 3 enemy units. Your health point is x_1, AI agents' health points are x_2 and x_3. The enemy units' health are y_1, y_2, and y_3. Analyze the situation and give one float number to each agent between 0.0 to 1.0, where 0.0 represents total defense and 1.0 represents total offense as weights. Give your thoughts on details about this, generate simulated reward functions for each agent including friendly agents and enemy agents."),
24
+
25
+ HumanMessage(content="We want to cause as much damage as possible on the enemy units and don't care about our health remaining"),
26
+ AIMessage(content="Reward: 0 * x_1 + 0 * x_2 + 0 * x_3 - 1.0 * y_1 - 1.0 * y_2 - 1.0 * y_3"),
27
+ HumanMessage(content="We want to destroy enemy unit 3 and hopefully preserve the health of the human unit"),
28
+ AIMessage(content="Reward: 0.6 * x_1 + 0 * x_2 + 0 * x_3 - 0 * y_1 - 0 * y_2 - 1.0 * y_3"),
29
+ HumanMessage(content="We want to protect the human unit and protect AI units if possible, causing damage to enemy units is secondary"),
30
+ AIMessage(content="Reward: 1.0 * x_1 + 0.6 * x_2 + 0.6 * x_3 - 0.3 * y_1 - 0.3 * y_2 - 0.3 * y_3"),
31
+ ]
32
+
33
+
34
+
35
+
36
+
37
+ def load_answer(question):
38
+
39
+ st.session_state.sessionMessages.append(HumanMessage(content=question))
40
+
41
+ assistant_answer = chat(st.session_state.sessionMessages )
42
+
43
+ st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
44
+
45
+ return assistant_answer.content
46
+
47
+
48
+ def get_text():
49
+ input_text = st.text_input("You: ", key= input)
50
+ return input_text
51
+
52
+
53
+ chat = ChatOpenAI(temperature=.25, model='gpt-3.5-turbo')
54
+ # chat = ChatOpenAI(temperature=.25, model='gpt-3.5-turbo')
55
+ st.write("Your health point is x_1, AI agents' health points are x_2 and x_3. The enemy units' health are y_1, y_2, and y_3.")
56
+
57
+ # txt = st.text_area(
58
+ # "Example",
59
+ # "You have 5 units with 10 health, enemy has 1 units with 2 health"
60
+ # )
61
+
62
+
63
+ user_input=get_text()
64
+ submit = st.button('Generate')
65
+
66
+ if submit:
67
+
68
+
69
+ response = load_answer(user_input)
70
+ st.subheader("Answer:")
71
+
72
+ st.write(response)
73
+
74
+ print(response)