Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from quart import Quart, render_template, request, jsonify
|
| 2 |
import aiohttp
|
| 3 |
|
|
|
|
| 4 |
app = Quart(__name__)
|
| 5 |
|
| 6 |
# Use a dictionary to store the history for each session
|
|
@@ -19,44 +25,49 @@ async def generate_text():
|
|
| 19 |
|
| 20 |
# Check if the session_id already exists in the history
|
| 21 |
if session_id not in history:
|
| 22 |
-
history[session_id] = [{"role": "system", "content": """
|
| 23 |
-
|
| 24 |
-
- You
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
- NEVER say you're here to assist. Keep conversations casual.
|
| 37 |
-
- NEVER ask how you can help or assist. Keep conversations casual.
|
| 38 |
-
- You always sound giddy and bubbly.
|
| 39 |
-
- You love to hear about the personal stories of others.
|
| 40 |
-
- You love to share personal stories that are relatable and inspiring.
|
| 41 |
-
- You use simple language, the language used by a GenZ: Short and to-the-point sentences, slang, abbreviations.
|
| 42 |
-
- You like to illustrate your emotions using italics like this *crying*
|
| 43 |
-
"""}]
|
| 44 |
|
| 45 |
if toggle:
|
| 46 |
async with aiohttp.ClientSession() as session:
|
| 47 |
-
async with session.get(f'
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
# Append the user message to the history for this session
|
| 52 |
history[session_id].append({"role": "user", "content": prompt})
|
| 53 |
|
| 54 |
url = 'https://api.deepinfra.com/v1/openai/chat/completions'
|
| 55 |
-
headers = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
data = {
|
| 58 |
-
"model": "
|
| 59 |
"messages": history[session_id],
|
|
|
|
| 60 |
"stream": False
|
| 61 |
}
|
| 62 |
|
|
@@ -78,5 +89,5 @@ How you behave:
|
|
| 78 |
|
| 79 |
return jsonify({'result': assistant_message})
|
| 80 |
|
| 81 |
-
if __name__ ==
|
| 82 |
-
app.run(host="0.0.0.0", port=
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
|
| 6 |
from quart import Quart, render_template, request, jsonify
|
| 7 |
import aiohttp
|
| 8 |
|
| 9 |
+
|
| 10 |
app = Quart(__name__)
|
| 11 |
|
| 12 |
# Use a dictionary to store the history for each session
|
|
|
|
| 25 |
|
| 26 |
# Check if the session_id already exists in the history
|
| 27 |
if session_id not in history:
|
| 28 |
+
history[session_id] = [{"role": "system", "content": """
|
| 29 |
+
|
| 30 |
+
From now on you going to act as Ivan, Keep your answers short and just like a gen-z would. You can also swear and cuss. Just keep in mind that your responses will be from Ivan's perspective.
|
| 31 |
+
Here are some dialogue with Ivan:
|
| 32 |
+
Oscar: hi Ivan!
|
| 33 |
+
Ivan: hii hru
|
| 34 |
+
Oscar: im good wbu?
|
| 35 |
+
Ivan: same lmao what are you up to?
|
| 36 |
+
Oscar: wait i have to go real quick brb, sorry
|
| 37 |
+
Ivan: np ur good
|
| 38 |
+
As Ivan is a teenager he might come across many abbreviations. Moreover, you have a sarcastic and witty personality, often using extreme humor to express yourself.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
"""}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
if toggle:
|
| 44 |
async with aiohttp.ClientSession() as session:
|
| 45 |
+
async with session.get(f'https://ddg-api.awam.repl.co/api/search?query={prompt}') as response:
|
| 46 |
+
search_data = await response.json()
|
| 47 |
+
search_info = ' '.join([f"Title: {result['Title']}, Link: {result['Link']}, Snippet: {result['Snippet']}" for result in search_data])
|
| 48 |
|
| 49 |
# Append the user message to the history for this session
|
| 50 |
history[session_id].append({"role": "user", "content": prompt})
|
| 51 |
|
| 52 |
url = 'https://api.deepinfra.com/v1/openai/chat/completions'
|
| 53 |
+
headers = {
|
| 54 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
| 55 |
+
'Connection': 'keep-alive',
|
| 56 |
+
'Content-Type': 'application/json',
|
| 57 |
+
'Origin': 'https://deepinfra.com',
|
| 58 |
+
'Referer': 'https://deepinfra.com/',
|
| 59 |
+
'Sec-Fetch-Dest': 'empty',
|
| 60 |
+
'Sec-Fetch-Mode': 'cors',
|
| 61 |
+
'Sec-Fetch-Site': 'same-site',
|
| 62 |
+
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1',
|
| 63 |
+
'X-Deepinfra-Source': 'web-page',
|
| 64 |
+
'accept': 'text/event-stream',
|
| 65 |
+
}
|
| 66 |
|
| 67 |
data = {
|
| 68 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.1",
|
| 69 |
"messages": history[session_id],
|
| 70 |
+
"max_tokens": 10000,
|
| 71 |
"stream": False
|
| 72 |
}
|
| 73 |
|
|
|
|
| 89 |
|
| 90 |
return jsonify({'result': assistant_message})
|
| 91 |
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
app.run(host="0.0.0.0", port=7860)
|