Gaston895 commited on
Commit
1567419
·
verified ·
1 Parent(s): ee34be2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -114,18 +114,32 @@ def call_deepseek_api(messages: List[Dict], client_info: Dict, max_retries: int
114
  try:
115
  client = client_info["client"]
116
 
117
- # Use InferenceClient.chat_completion method
118
- response = client.chat_completion(
119
- messages=messages,
120
- max_tokens=1024,
 
 
 
 
 
 
 
 
 
 
 
 
121
  temperature=0.7,
122
  top_p=0.9,
 
 
123
  stream=False
124
  )
125
 
126
  # Extract content from response
127
- if hasattr(response, 'choices') and len(response.choices) > 0:
128
- content = response.choices[0].message.content
129
  logger.info(f"✅ Success with InferenceClient: {client_info['name']} ({client_info['model']})")
130
  return content.strip()
131
  else:
 
114
  try:
115
  client = client_info["client"]
116
 
117
+ # Convert messages to a single prompt for text_generation
118
+ conversation = ""
119
+ for msg in messages:
120
+ if msg["role"] == "system":
121
+ conversation += f"System: {msg['content']}\n\n"
122
+ elif msg["role"] == "user":
123
+ conversation += f"User: {msg['content']}\n\n"
124
+ elif msg["role"] == "assistant":
125
+ conversation += f"Assistant: {msg['content']}\n\n"
126
+
127
+ conversation += "Assistant: "
128
+
129
+ # Use text_generation method instead of chat_completion
130
+ response = client.text_generation(
131
+ prompt=conversation,
132
+ max_new_tokens=1024,
133
  temperature=0.7,
134
  top_p=0.9,
135
+ do_sample=True,
136
+ return_full_text=False,
137
  stream=False
138
  )
139
 
140
  # Extract content from response
141
+ if isinstance(response, str):
142
+ content = response
143
  logger.info(f"✅ Success with InferenceClient: {client_info['name']} ({client_info['model']})")
144
  return content.strip()
145
  else: