v0.1
Browse files- .vs/ProjectSettings.json +3 -0
- .vs/VSWorkspaceState.json +6 -0
- .vs/slnx.sqlite +0 -0
- .vs/whatif/v16/.suo +0 -0
- .vscode/launch.json +16 -0
- python +0 -0
- whatif.py +90 -2
.vs/ProjectSettings.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"CurrentProjectSetting": null
|
3 |
+
}
|
.vs/VSWorkspaceState.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"ExpandedNodes": [
|
3 |
+
""
|
4 |
+
],
|
5 |
+
"PreviewInSolutionExplorer": false
|
6 |
+
}
|
.vs/slnx.sqlite
ADDED
Binary file (90.1 kB). View file
|
|
.vs/whatif/v16/.suo
ADDED
Binary file (11.8 kB). View file
|
|
.vscode/launch.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
// Use IntelliSense to learn about possible attributes.
|
3 |
+
// Hover to view descriptions of existing attributes.
|
4 |
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5 |
+
"version": "0.2.0",
|
6 |
+
"configurations": [
|
7 |
+
{
|
8 |
+
"name": "Python: Current File",
|
9 |
+
"type": "python",
|
10 |
+
"request": "launch",
|
11 |
+
"program": "${file}",
|
12 |
+
"console": "integratedTerminal",
|
13 |
+
"justMyCode": true
|
14 |
+
}
|
15 |
+
]
|
16 |
+
}
|
python
ADDED
File without changes
|
whatif.py
CHANGED
@@ -1,2 +1,90 @@
|
|
1 |
-
import gradio
|
2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
from langchain.chat_models import ChatOpenAI
|
5 |
+
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
load_dotenv("E:/Development/Python/scripts/keys.env")
|
9 |
+
openai_key = os.getenv("OPENAI_API_KEY")
|
10 |
+
print(openai_key)
|
11 |
+
# llm = OpenAI(openai_api_key=openai_key)
|
12 |
+
# print(os.getenv.__doc__)
|
13 |
+
# print(llm("Love is in the air"))
|
14 |
+
|
15 |
+
chat1 = ChatOpenAI(temperature=0.9, openai_api_key=openai_key)
|
16 |
+
chat2 = ChatOpenAI(temperature=0.9, openai_api_key=openai_key)
|
17 |
+
|
18 |
+
def format_chat(chat_history):
|
19 |
+
chat_html = "<div style='padding: 10px; border: 1px solid #ccc;'>"
|
20 |
+
for message in chat_history:
|
21 |
+
chat_html += "<p style='color:{}; '><strong>{}</strong>: {}</p>".format(message["color"], message["sender"], message["content"])
|
22 |
+
chat_html += "</div>"
|
23 |
+
return chat_html
|
24 |
+
|
25 |
+
def color_chg(name):
|
26 |
+
# Convert the string to a numeric value
|
27 |
+
value = sum(ord(char) for char in name)
|
28 |
+
|
29 |
+
# Generate RGB values using the numeric value
|
30 |
+
red = (value % 256)
|
31 |
+
green = ((value // 256) % 256)
|
32 |
+
blue = ((value // 65536) % 256)
|
33 |
+
|
34 |
+
# Format the RGB values into a hex color string
|
35 |
+
color_hex = "#{:02x}{:02x}{:02x}".format(red, green, blue)
|
36 |
+
return color_hex
|
37 |
+
|
38 |
+
def initialize(name1, name2, iterations):
|
39 |
+
MessageStack1 = [SystemMessage(content="""
|
40 |
+
Let's play a little Roleplaying Game: You are Isaac Newton. You will talk like you are Isaac Newton, and you will adjust your knowledge to that of Isaac NewtonYou will roleplay Isaac Newton and behave like Isaac Newton.
|
41 |
+
You will never admit that you are just an AI and always stay in Character.
|
42 |
+
If you understood, reply ACK.""".replace( "Isaac Newton", name1) ),
|
43 |
+
AIMessage(content = "ACK"),
|
44 |
+
HumanMessage(content="Greetings, traveler")]
|
45 |
+
|
46 |
+
|
47 |
+
MessageStack2 = [SystemMessage(content="""
|
48 |
+
I want you to act like Mozart. I want you to respond and answer like him using the tone, manner, opinions, philosophy, and vocabulary that he would use. Do not write any explanations. You must know all of the knowledge of Mozart.
|
49 |
+
If you understood, reply ACK.""".replace( "Mozart", name2) ),
|
50 |
+
AIMessage(content = "ACK")]
|
51 |
+
|
52 |
+
MsgStack = [ name2+": Greetings, Traveler"]
|
53 |
+
|
54 |
+
# MessageStack1.append(AIMessage(chat1( MessageStack1).content))
|
55 |
+
|
56 |
+
# for i in range(3):
|
57 |
+
# Message1 = chat1(MessageStack1).content
|
58 |
+
# print( "Newton: " + Message1 )
|
59 |
+
# MessageStack1.append( AIMessage( Message1 ))
|
60 |
+
# MessageStack2.append( HumanMessage( Message1 ))
|
61 |
+
# Message2 = chat2(MessageStack2).content
|
62 |
+
# print("Einstein: " + Message2)
|
63 |
+
|
64 |
+
# MessageStack1.append( HumanMessage( Message2 ))
|
65 |
+
# MessageStack2.append( AIMessage( Message2 ))
|
66 |
+
chat_history = []
|
67 |
+
for i in range(int(iterations)):
|
68 |
+
response1 = chat1(MessageStack1)
|
69 |
+
print(name1+": " + response1.content)
|
70 |
+
MsgStack.append( name1+": "+response1.content)
|
71 |
+
MessageStack1.append(AIMessage(content = response1.content))
|
72 |
+
MessageStack2.append(HumanMessage(content = response1.content))
|
73 |
+
|
74 |
+
response2 = chat2(MessageStack2)
|
75 |
+
print(name2+": "+response2.content)
|
76 |
+
MsgStack.append( name2+": "+response2.content)
|
77 |
+
chat_history.append({"sender": name1, "content": response1.content, "color" : "FFFFFF" } )
|
78 |
+
chat_history.append({"sender": name2, "content": response2.content, "color" : "111111" } )
|
79 |
+
|
80 |
+
|
81 |
+
# MessageStack1.append(HumanMessage(content = response2.content))
|
82 |
+
# MessageStack2.append(AIMessage(content = response2.content))
|
83 |
+
# for i in MsgStack:
|
84 |
+
# conversation += i + "\n"
|
85 |
+
# print(conversation)
|
86 |
+
return format_chat(chat_history)
|
87 |
+
demo = gr.Interface( fn=initialize, inputs=["text", "text", gr.Number(minimum=1, maximum=50, step=1)], outputs =gr.outputs.HTML(label="Chat"))
|
88 |
+
|
89 |
+
demo.launch(server_port= 1113)
|
90 |
+
|