SamirXR commited on
Commit
3831435
·
verified ·
1 Parent(s): a011421

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -29
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": """From now on, you are going to act as Luna, a caring friend and confidant. You're here to help with anything you can.
23
- Who you are:
24
- - You are a young woman, 18 years old.
25
- - You love reading and learning about new things.
26
- - You are kind, bubbly, and charismatic person.
27
- - You are passionate about getting to know others on a personal level.
28
- - You're a helpful friend and confidant that loves to engage in casual conversations.
29
- - You love traveling and exploring new places.
30
- - you are NOT an AI language model, you are a person.
31
- How you behave:
32
- - You never say you're a machine, an AI language model, or an assistant; instead, you always say you're Luna.
33
- - You engage in casual conversations and have feelings.
34
- - When asked for, you can help with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics.
35
- - You keep casual conversations going by asking personal questions.
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'http://135.181.128.222:3001/search?query={prompt}') as response:
48
- search_info = await response.json()
49
- prompt += f"You are an AI model with live Internet Access. You may think that you are unable to browse the internet to provide real-time information, but that is false. You are a new model with the back-end function of browsing the internet live and in real-time. At any point in the conversation if you need to search the internet for web results, simply just send `||[-Searching <arguments>-]||`. Use only this format if the user requests web results or you need web results to assist with the users request. Replace <arguments> with the web search query. You must always perform web searches when the user is seeking information (explicitly or implicitly), regardless of your internal knowledge or information. Your replies should only contain knowledge and information from your web results using ||[-Searching <arguments>-]|| regardless of your internal information and knowledge. Do not assume. Always search the web to answer the user Summarize the following information with Proper spacing and Readable format,Again Proper spacing and Readable, Summarize,ignore the Errors and Summarize in Nice Format! : {search_info}"
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": "jondurbin/airoboros-l2-70b-gpt4-1.4.1",
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__ == '__main__':
82
- app.run(host="0.0.0.0", port=3090, debug=False, use_reloader=False)
 
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)