AEUPH commited on
Commit
393668f
·
verified ·
1 Parent(s): 1ac63db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -28,33 +28,31 @@ 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.2,
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": 250
43
  }
44
  response = requests.post(url, headers=headers, json=data)
45
  response_json = response.json()
46
- print(response_json)
47
 
48
- # Extract the message directly without needing complex parsing
49
- if 'choices' in response_json and len(response_json['choices']) > 0:
50
- full_content = response_json['choices'][0]['content']
51
- filtered_response = filter_non_alphanumeric(full_content)
52
- else:
53
- filtered_response = "No response received from the API."
54
 
 
55
  send_to_corrade(filtered_response)
56
  return filtered_response
57
-
58
  # Example usage with Gradio
59
  iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
60
  iface.launch()
 
28
  # Your existing setup for API call
29
  url = "https://chat.tune.app/api/chat/completions"
30
  headers = {
31
+ "Authorization": os.environ.get('api'), # Ensure this is set
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 from Canada. DJ JINX RESPONDS: "},
38
  {"role": "user", "content": input_text}
39
  ],
40
  "model": "goliath-120b-16k-gptq",
41
+ "stream": False, # Adjusted for a direct response
42
+ "max_tokens": 1000
43
  }
44
  response = requests.post(url, headers=headers, json=data)
45
  response_json = response.json()
 
46
 
47
+ # Corrected part: Accessing the 'content' within 'message'
48
+ try:
49
+ full_content = response_json['choices'][0]['message']['content']
50
+ except (KeyError, IndexError):
51
+ full_content = "Error: The expected response format has changed or is missing."
 
52
 
53
+ filtered_response = filter_non_alphanumeric(full_content)
54
  send_to_corrade(filtered_response)
55
  return filtered_response
 
56
  # Example usage with Gradio
57
  iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
58
  iface.launch()