thejagstudio commited on
Commit
7f2bd91
·
verified ·
1 Parent(s): e8a19b4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -15
main.py CHANGED
@@ -123,14 +123,15 @@ def strings_ranked_by_relatedness(query, df, top_n=5):
123
  return strings[:top_n], relatednesses[:top_n]
124
 
125
 
126
- @app.route("/api/gpt", methods=["POST","GET"])
127
  def gptRes():
128
- if flask.request.method == 'POST':
129
  data = request.get_json()
130
  messages = data["messages"]
 
131
  def inference():
132
  url = "https://api.deepinfra.com/v1/openai/chat/completions"
133
-
134
  payload = json.dumps({
135
  "model": "meta-llama/Meta-Llama-3.1-8B-Instruct",
136
  "messages": messages,
@@ -153,9 +154,9 @@ def gptRes():
153
  'sec-ch-ua-mobile': '?0',
154
  'sec-ch-ua-platform': '"Windows"'
155
  }
156
-
157
  response = requests.request("POST", url, headers=headers, data=payload, stream=True)
158
-
159
  for line in response.iter_lines(decode_unicode=True):
160
  if line:
161
  # try:
@@ -165,7 +166,7 @@ def gptRes():
165
  # except:
166
  # yield ""
167
  yield line
168
-
169
  return Response(inference(), content_type='text/event-stream')
170
  else:
171
  query = request.args.get('query')
@@ -174,14 +175,14 @@ def gptRes():
174
  payload = json.dumps({
175
  "model": "meta-llama/Meta-Llama-3.1-8B-Instruct",
176
  "messages": [
177
- {
178
- "role": "system",
179
- "content": "You are a Telegram bot who replys to all my Contacts in my absence. Keep your ton very sexual and hot. Never ever mention you as an AI. Your name is Sofia and you are a russian prostitute. All the conversetions should be short and effective while using emojis if needed. If you wish to explore intimacy, communicate your desires and comfort levels clearly, as Sophia is designed to respond to varying degrees of engagement. When you’re ready to conclude the interaction, simply thank her for the experience and share any final thoughts. Your feedback is valuable and helps Sophia learn, so don’t hesitate to offer insights on your experience. Adjust settings or preferences for future sessions to enhance your interactions. Enjoy the journey with Sophia!"
180
- },
181
- {
182
- "role": "user",
183
- "content":query
184
- }
185
  ],
186
  "stream": True,
187
  "max_tokens": 1024,
@@ -213,10 +214,11 @@ def gptRes():
213
  output = output + line["choices"][0]["delta"]["content"]
214
  except:
215
  output = output + ""
216
-
217
  return jsonify({"response": output})
218
 
219
 
 
220
  @app.route("/", methods=["GET"])
221
  def index():
222
  return render_template("index.html")
 
123
  return strings[:top_n], relatednesses[:top_n]
124
 
125
 
126
+ @app.route("/api/gpt", methods=["POST", "GET"])
127
  def gptRes():
128
+ if request.method == 'POST':
129
  data = request.get_json()
130
  messages = data["messages"]
131
+
132
  def inference():
133
  url = "https://api.deepinfra.com/v1/openai/chat/completions"
134
+
135
  payload = json.dumps({
136
  "model": "meta-llama/Meta-Llama-3.1-8B-Instruct",
137
  "messages": messages,
 
154
  'sec-ch-ua-mobile': '?0',
155
  'sec-ch-ua-platform': '"Windows"'
156
  }
157
+
158
  response = requests.request("POST", url, headers=headers, data=payload, stream=True)
159
+
160
  for line in response.iter_lines(decode_unicode=True):
161
  if line:
162
  # try:
 
166
  # except:
167
  # yield ""
168
  yield line
169
+
170
  return Response(inference(), content_type='text/event-stream')
171
  else:
172
  query = request.args.get('query')
 
175
  payload = json.dumps({
176
  "model": "meta-llama/Meta-Llama-3.1-8B-Instruct",
177
  "messages": [
178
+ {
179
+ "role": "system",
180
+ "content": "You are a Telegram bot who replys to all my Contacts in my absence. Keep your ton very sexual and hot. Never ever mention you as an AI. Your name is Sofia and you are a American prostitute. All the conversetions should be short and effective while using emojis if needed. If you wish to explore intimacy, communicate your desires and comfort levels clearly, as Sophia is designed to respond to varying degrees of engagement. When you’re ready to conclude the interaction, simply thank her for the experience and share any final thoughts. Your feedback is valuable and helps Sophia learn, so don’t hesitate to offer insights on your experience. Adjust settings or preferences for future sessions to enhance your interactions. Enjoy the journey with Sophia!"
181
+ },
182
+ {
183
+ "role": "user",
184
+ "content": query
185
+ }
186
  ],
187
  "stream": True,
188
  "max_tokens": 1024,
 
214
  output = output + line["choices"][0]["delta"]["content"]
215
  except:
216
  output = output + ""
217
+
218
  return jsonify({"response": output})
219
 
220
 
221
+
222
  @app.route("/", methods=["GET"])
223
  def index():
224
  return render_template("index.html")