Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,23 +15,28 @@ import google.generativeai as genai
|
|
15 |
def request_to_v2(message, api_keys, context=[]):
|
16 |
context = [message]
|
17 |
|
18 |
-
message = message.replace("\n","##")
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
model = genai.GenerativeModel(model_name="gemini-pro")
|
24 |
-
promt_s = [
|
25 |
-
message
|
26 |
-
]
|
27 |
-
print(f"用户输入:{message}")
|
28 |
-
respose = model.generate_content(promt_s)
|
29 |
-
print(f"模型输出:{list(respose)}")
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# responses = "嘿嘿"
|
34 |
|
|
|
|
|
|
|
|
|
|
|
35 |
context += [responses]
|
36 |
responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
|
37 |
return responses, context
|
|
|
15 |
def request_to_v2(message, api_keys, context=[]):
|
16 |
context = [message]
|
17 |
|
18 |
+
# message = message.replace("\n","##")
|
19 |
+
try:
|
20 |
+
## 加入API_keys
|
21 |
+
genai.configure(api_key=api_keys)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
model = genai.GenerativeModel(model_name="gemini-pro")
|
24 |
+
promt_s = [
|
25 |
+
message
|
26 |
+
]
|
27 |
+
print(f"用户输入:{message}")
|
28 |
+
respose = model.generate_content(promt_s)
|
29 |
+
print(f"模型输出:{list(respose)}")
|
30 |
+
|
31 |
+
responses = respose.text
|
32 |
+
print(f"模型输入:{responses}")
|
33 |
# responses = "嘿嘿"
|
34 |
|
35 |
+
except Exception as e:
|
36 |
+
print(f"报错信息:{e}")
|
37 |
+
responses = f"!!!我出错啦!!!!\n报错内容为:{e}"
|
38 |
+
|
39 |
+
|
40 |
context += [responses]
|
41 |
responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
|
42 |
return responses, context
|