rwitz commited on
Commit
84fe385
1 Parent(s): ad2f780

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -96,33 +96,39 @@ from tenacity import retry, stop_after_attempt, wait_exponential
96
 
97
  async def get_bot_response(adapter_id, prompt, state, bot_index):
98
  chatml_prompt = format_chatml_prompt(state)
 
 
 
99
  payload = {
100
- "inputs": chatml_prompt[bot_index],
101
- "parameters": {
102
- "adapter_id": adapter_id,
103
- "adapter_source": "hub",
104
- "temperature": 0.7,
105
- "max_new_tokens": 100
106
- }
 
 
107
  }
108
  headers = {
 
109
  "Content-Type": "application/json",
110
- "Authorization": f"Bearer {os.environ.get('PREDIBASE_TOKEN')}"
111
  }
 
112
  async with aiohttp.ClientSession() as session:
113
  try:
114
- async with session.post("https://serving.app.predibase.com/79957f/deployments/v2/llms/mistral-7b/generate",
115
- json=payload, headers=headers, timeout=30) as response:
116
  if response.status == 200:
117
  response_data = await response.json()
118
- response_text = response_data.get('generated_text', '')
119
  else:
120
  error_text = await response.text()
121
  print(error_text)
122
  response_text = "Sorry, I couldn't generate a response."
123
  except (aiohttp.ClientError, asyncio.TimeoutError):
124
  response_text = "Sorry, I couldn't generate a response."
125
- return response_text.split('<|im_end|>')[0].strip()
126
  async def chat_with_bots(user_input, state):
127
  # Use existing bot order from state if available, otherwise shuffle and initialize
128
  if 'last_bots' not in state or not state['last_bots']:
 
96
 
97
  async def get_bot_response(adapter_id, prompt, state, bot_index):
98
  chatml_prompt = format_chatml_prompt(state)
99
+ fireworks_adapter_name = next(entry['fireworks_adapter_name'] for entry in chatbots_data if entry['adapter'] == adapter_id)
100
+
101
+ url = "https://api.fireworks.ai/inference/v1/completions"
102
  payload = {
103
+ "model": f"accounts/gaingg19-432d9f/models/{fireworks_adapter_name}",
104
+ "max_tokens": 100,
105
+ "top_p": 1,
106
+ "top_k": 40,
107
+ "presence_penalty": 0,
108
+ "frequency_penalty": 0,
109
+ "temperature": 0.7,
110
+ "prompt": chatml_prompt[bot_index],
111
+ "stop": ["<|im_end|>"]
112
  }
113
  headers = {
114
+ "Accept": "application/json",
115
  "Content-Type": "application/json",
116
+ "Authorization": f"Bearer {os.environ.get('FIREWORKS_API_KEY')}"
117
  }
118
+
119
  async with aiohttp.ClientSession() as session:
120
  try:
121
+ async with session.post(url, json=payload, headers=headers, timeout=30) as response:
 
122
  if response.status == 200:
123
  response_data = await response.json()
124
+ response_text = response_data['choices'][0]['text']
125
  else:
126
  error_text = await response.text()
127
  print(error_text)
128
  response_text = "Sorry, I couldn't generate a response."
129
  except (aiohttp.ClientError, asyncio.TimeoutError):
130
  response_text = "Sorry, I couldn't generate a response."
131
+ return response_text.strip()
132
  async def chat_with_bots(user_input, state):
133
  # Use existing bot order from state if available, otherwise shuffle and initialize
134
  if 'last_bots' not in state or not state['last_bots']: