Spaces:
Sleeping
Sleeping
SamSamSamChennn commited on
Commit ·
ca58969
1
Parent(s): 32506e1
[Sam] format: format the code
Browse files- .idea/.gitignore +8 -0
- .idea/ai_test.iml +10 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +8 -4
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# Editor-based HTTP Client requests
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
.idea/ai_test.iml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$">
|
| 5 |
+
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
| 6 |
+
</content>
|
| 7 |
+
<orderEntry type="jdk" jdkName="Python 3.9 (ai_test)" jdkType="Python SDK" />
|
| 8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 9 |
+
</component>
|
| 10 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ai_test)" project-jdk-type="Python SDK" />
|
| 4 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/ai_test.iml" filepath="$PROJECT_DIR$/.idea/ai_test.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
|
| 5 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 6 |
|
|
|
|
| 7 |
class Conversation:
|
| 8 |
def __init__(self, prompt, num_of_round):
|
| 9 |
self.prompt = prompt
|
|
@@ -13,7 +14,7 @@ class Conversation:
|
|
| 13 |
|
| 14 |
def ask(self, question):
|
| 15 |
try:
|
| 16 |
-
self.messages.append(
|
| 17 |
response = openai.ChatCompletion.create(
|
| 18 |
model="gpt-3.5-turbo-16k-0613",
|
| 19 |
messages=self.messages,
|
|
@@ -27,11 +28,12 @@ class Conversation:
|
|
| 27 |
|
| 28 |
message = response["choices"][0]["message"]["content"]
|
| 29 |
self.messages.append({"role": "assistant", "content": message})
|
| 30 |
-
|
| 31 |
-
if len(self.messages) > self.num_of_round*2 + 1:
|
| 32 |
del self.messages[1:3]
|
| 33 |
return message
|
| 34 |
-
|
|
|
|
| 35 |
with open('chatbot_03_prompt.md', 'r') as file:
|
| 36 |
prompt = file.read()
|
| 37 |
|
|
@@ -39,11 +41,13 @@ prompt = '"""\n' + prompt + '\n"""'
|
|
| 39 |
|
| 40 |
conv = Conversation(prompt, 5)
|
| 41 |
|
|
|
|
| 42 |
def respond(message, chat_history):
|
| 43 |
bot_message = conv.ask(message)
|
| 44 |
chat_history.append((message, bot_message))
|
| 45 |
return "", chat_history
|
| 46 |
|
|
|
|
| 47 |
init_conversation = [(None, "欢迎来到 recon! 请问有什么可以帮助你的吗?")]
|
| 48 |
|
| 49 |
with gr.Blocks(css="#chatbot{height:700px} .overflow-y-auto{height:900px}") as demo:
|
|
|
|
| 4 |
|
| 5 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 6 |
|
| 7 |
+
|
| 8 |
class Conversation:
|
| 9 |
def __init__(self, prompt, num_of_round):
|
| 10 |
self.prompt = prompt
|
|
|
|
| 14 |
|
| 15 |
def ask(self, question):
|
| 16 |
try:
|
| 17 |
+
self.messages.append({"role": "user", "content": question})
|
| 18 |
response = openai.ChatCompletion.create(
|
| 19 |
model="gpt-3.5-turbo-16k-0613",
|
| 20 |
messages=self.messages,
|
|
|
|
| 28 |
|
| 29 |
message = response["choices"][0]["message"]["content"]
|
| 30 |
self.messages.append({"role": "assistant", "content": message})
|
| 31 |
+
|
| 32 |
+
if len(self.messages) > self.num_of_round * 2 + 1:
|
| 33 |
del self.messages[1:3]
|
| 34 |
return message
|
| 35 |
+
|
| 36 |
+
|
| 37 |
with open('chatbot_03_prompt.md', 'r') as file:
|
| 38 |
prompt = file.read()
|
| 39 |
|
|
|
|
| 41 |
|
| 42 |
conv = Conversation(prompt, 5)
|
| 43 |
|
| 44 |
+
|
| 45 |
def respond(message, chat_history):
|
| 46 |
bot_message = conv.ask(message)
|
| 47 |
chat_history.append((message, bot_message))
|
| 48 |
return "", chat_history
|
| 49 |
|
| 50 |
+
|
| 51 |
init_conversation = [(None, "欢迎来到 recon! 请问有什么可以帮助你的吗?")]
|
| 52 |
|
| 53 |
with gr.Blocks(css="#chatbot{height:700px} .overflow-y-auto{height:900px}") as demo:
|