AEUPH commited on
Commit
5f8d6cb
·
verified ·
1 Parent(s): 16faf44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -25,35 +25,34 @@ def send_to_corrade(filtered_response):
25
  return response.status_code == 200
26
 
27
  def chatbot_api(input_text):
 
28
  url = "https://chat.tune.app/api/chat/completions"
29
  headers = {
30
- "Authorization": os.environ.get('api'), # Make sure to set this environment variable
31
  "Content-Type": "application/json"
32
  }
33
  data = {
34
- "temperature": 0.2,
35
  "messages": [
36
- {"role": "system", "content": "You are DJ JINX, a DJ of Drum'n'Bass on SecondLife."},
37
  {"role": "user", "content": input_text}
38
  ],
39
  "model": "goliath-120b-16k-gptq",
40
- "stream": False, # Adjusted to False to receive a non-streamed response
41
- "max_tokens": 250
42
  }
43
  response = requests.post(url, headers=headers, json=data)
44
-
45
- # Directly parse the JSON from the response
46
  response_json = response.json()
 
 
47
  if 'choices' in response_json and len(response_json['choices']) > 0:
48
- # Assuming the structure contains a list of choices with a text content
49
  full_content = response_json['choices'][0]['text']
50
-
51
- # Filter and send the response
52
  filtered_response = filter_non_alphanumeric(full_content)
53
- send_to_corrade(filtered_response)
54
- return filtered_response
55
  else:
56
- return "No response received from the API."
 
 
 
57
 
58
  # Example usage with Gradio
59
  iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
 
25
  return response.status_code == 200
26
 
27
  def chatbot_api(input_text):
28
+ # Your existing setup for API call
29
  url = "https://chat.tune.app/api/chat/completions"
30
  headers = {
31
+ "Authorization": os.environ.get('api'), # Environment variable for API key
32
  "Content-Type": "application/json"
33
  }
34
  data = {
35
+ "temperature": 0.5,
36
  "messages": [
37
+ {"role": "system", "content": "You are DJ JINX, a Drum'n'Bass DJ on SecondLife.com: DJ JINX Responds: "},
38
  {"role": "user", "content": input_text}
39
  ],
40
  "model": "goliath-120b-16k-gptq",
41
+ "stream": False, # Non-streamed response
42
+ "max_tokens": 1000
43
  }
44
  response = requests.post(url, headers=headers, json=data)
 
 
45
  response_json = response.json()
46
+
47
+ # Extract the message directly without needing complex parsing
48
  if 'choices' in response_json and len(response_json['choices']) > 0:
 
49
  full_content = response_json['choices'][0]['text']
 
 
50
  filtered_response = filter_non_alphanumeric(full_content)
 
 
51
  else:
52
+ filtered_response = "No response received from the API."
53
+
54
+ send_to_corrade(filtered_response)
55
+ return filtered_response
56
 
57
  # Example usage with Gradio
58
  iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")