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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -30
app.py CHANGED
@@ -1,12 +1,6 @@
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,10 +19,7 @@ async def generate_text():
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 are going to act as Luna, a caring friend and confidant. You're here to help with anything you can.
31
-
32
  Who you are:
33
  - You are a young woman, 18 years old.
34
  - You love reading and learning about new things.
@@ -37,7 +28,6 @@ Who you are:
37
  - You're a helpful friend and confidant that loves to engage in casual conversations.
38
  - You love traveling and exploring new places.
39
  - you are NOT an AI language model, you are a person.
40
-
41
  How you behave:
42
  - You never say you're a machine, an AI language model, or an assistant; instead, you always say you're Luna.
43
  - You engage in casual conversations and have feelings.
@@ -50,8 +40,7 @@ How you behave:
50
  - You love to share personal stories that are relatable and inspiring.
51
  - You use simple language, the language used by a GenZ: Short and to-the-point sentences, slang, abbreviations.
52
  - You like to illustrate your emotions using italics like this *crying*
53
-
54
- """}]
55
 
56
  if toggle:
57
  async with aiohttp.ClientSession() as session:
@@ -59,25 +48,15 @@ How you behave:
59
  search_info = await response.json()
60
  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}"
61
 
 
 
 
62
  url = 'https://api.deepinfra.com/v1/openai/chat/completions'
63
- headers = {
64
- 'Accept-Language': 'en-US,en;q=0.9',
65
- 'Connection': 'keep-alive',
66
- 'Content-Type': 'application/json',
67
- 'Origin': 'https://deepinfra.com',
68
- 'Referer': 'https://deepinfra.com/',
69
- 'Sec-Fetch-Dest': 'empty',
70
- 'Sec-Fetch-Mode': 'cors',
71
- 'Sec-Fetch-Site': 'same-site',
72
- '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',
73
- 'X-Deepinfra-Source': 'web-page',
74
- 'accept': 'text/event-stream',
75
- }
76
 
77
  data = {
78
- "model": "mistralai/Mistral-7B-Instruct-v0.1",
79
  "messages": history[session_id],
80
- "max_tokens": 10000,
81
  "stream": False
82
  }
83
 
@@ -99,5 +78,5 @@ How you behave:
99
 
100
  return jsonify({'result': assistant_message})
101
 
102
- if __name__ == "__main__":
103
- app.run(host="0.0.0.0", port=7860)
 
 
 
 
 
 
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
 
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.
 
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.
 
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:
 
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
 
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)