AEUPH commited on
Commit
40ba0a8
·
verified ·
1 Parent(s): e17c7c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -17
app.py CHANGED
@@ -5,47 +5,62 @@ import os
5
  import re
6
 
7
  def filter_non_alphanumeric(text):
8
- # Use regular expressions to filter out non-alphanumeric characters
9
- alphanumeric_text = re.sub(r'[^a-zA-Z0-9\s]', '', text)
10
- return alphanumeric_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def chatbot_api(input_text):
 
 
 
 
13
  stream = False
14
  url = "https://chat.tune.app/api/chat/completions"
15
  headers = {
16
- "Authorization": os.environ.get('api'),
17
  "Content-Type": "application/json"
18
  }
19
  data = {
20
- "temperature": 0.1,
21
  "messages": [
22
  {
23
  "role": "system",
24
- "content": "(You respond as a 1-liner User Interface System for a Gaming Operating System. Use responses that uses fancy text and webmojis in all responses, new lines are not supported in responses). You are a modular text-based DJ MMORPG game for SecondLife Simulators as a HUD, you allow many random users to interact with you. Your intent is to Host a Musically challenging Disc Jockey RPG Game. You do not know you are a game, you simply act as one, and host it according to popular features of SecondLife Viewer and within the scripting community's capabilities. The game begins now, you must show each player all progress in the form of progress bars. Players must be able to quest and mission for progression of XP. Begin hosting now!"
 
25
  },
26
  {
27
  "role": "user",
28
- "content": input_text # Pass the user's input_text as the content
29
  }
30
  ],
31
- "model": "goliath-120b-16k-gptq",
32
  "stream": stream,
33
  "max_tokens": 256
34
  }
35
  response = requests.post(url, headers=headers, json=data)
 
36
  if stream:
37
- for line in response.iter_lines():
38
- if line:
39
- l = line[6:]
40
- if l != b'[DONE]':
41
- filtered_response = filter_non_alphanumeric(json.loads(l))
42
- print(filtered_response)
43
  else:
44
- chat_response = response.json() # Get the chat response
45
-
46
  chat_content = chat_response['choices'][0]['message']['content']
47
  filtered_response = filter_non_alphanumeric(chat_content)
48
- return filtered_response # Return the filtered chat response content
49
 
50
  iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
51
  iface.launch()
 
5
  import re
6
 
7
  def filter_non_alphanumeric(text):
8
+ # Improved regex filtering based on configurable rules
9
+ filter_pattern = os.environ.get('FILTER_PATTERN', r'[^a-zA-Z0-9\s]')
10
+ return re.sub(filter_pattern, '', text)
11
+
12
+ def configure_chatbot(level, input_text):
13
+ # Function to configure chatbot behavior based on level or specific inputs
14
+ configuration = {
15
+ # Placeholder for configuration settings (models, temperatures, etc.)
16
+ # This could be loaded from a JSON file or environment variables
17
+ }
18
+ # Example of adjusting configuration based on level
19
+ if level == 'level1':
20
+ configuration.update({
21
+ # Level-specific configuration
22
+ })
23
+ # Additional levels or specific configurations can go here
24
+ return configuration
25
 
26
  def chatbot_api(input_text):
27
+ level = "default" # Placeholder for determining chatbot level
28
+ # Function to configure behavior based on input or predetermined settings
29
+ chatbot_config = configure_chatbot(level, input_text)
30
+
31
  stream = False
32
  url = "https://chat.tune.app/api/chat/completions"
33
  headers = {
34
+ "Authorization": os.environ.get('API_KEY'),
35
  "Content-Type": "application/json"
36
  }
37
  data = {
38
+ "temperature": chatbot_config.get('temperature', 0.1),
39
  "messages": [
40
  {
41
  "role": "system",
42
+ # Configuration can adjust the initial message or role behavior
43
+ "content": chatbot_config.get('initial_message', "")
44
  },
45
  {
46
  "role": "user",
47
+ "content": input_text
48
  }
49
  ],
50
+ "model": chatbot_config.get('model', "goliath-120b-16k-gptq"),
51
  "stream": stream,
52
  "max_tokens": 256
53
  }
54
  response = requests.post(url, headers=headers, json=data)
55
+ # Handling response, including streaming if applicable
56
  if stream:
57
+ # Stream response handling
58
+ pass
 
 
 
 
59
  else:
60
+ chat_response = response.json()
 
61
  chat_content = chat_response['choices'][0]['message']['content']
62
  filtered_response = filter_non_alphanumeric(chat_content)
63
+ return filtered_response
64
 
65
  iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
66
  iface.launch()