Spaces:
Sleeping
Sleeping
Update analytics/ai_assistant.py
Browse files- analytics/ai_assistant.py +11 -7
analytics/ai_assistant.py
CHANGED
|
@@ -11,7 +11,7 @@ except ImportError as exc:
|
|
| 11 |
|
| 12 |
HF_MODEL_ID = os.environ.get("HF_MODEL_ID", "Qwen/Qwen2.5-7B-Instruct")
|
| 13 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
| 14 |
-
HF_MAX_TOKENS = int(os.environ.get("HF_MAX_TOKENS",
|
| 15 |
HF_TEMPERATURE = float(os.environ.get("HF_TEMPERATURE", 0.3))
|
| 16 |
|
| 17 |
|
|
@@ -164,10 +164,14 @@ def generate_ai_answer(question: str, df: pd.DataFrame, as_of_month: str = None,
|
|
| 164 |
# top_k= 50,
|
| 165 |
# top_p= 0.95
|
| 166 |
#)
|
| 167 |
-
print(response)
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
if
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
HF_MODEL_ID = os.environ.get("HF_MODEL_ID", "Qwen/Qwen2.5-7B-Instruct")
|
| 13 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
| 14 |
+
HF_MAX_TOKENS = int(os.environ.get("HF_MAX_TOKENS", 512))
|
| 15 |
HF_TEMPERATURE = float(os.environ.get("HF_TEMPERATURE", 0.3))
|
| 16 |
|
| 17 |
|
|
|
|
| 164 |
# top_k= 50,
|
| 165 |
# top_p= 0.95
|
| 166 |
#)
|
| 167 |
+
print(response.choices[0].message.content)
|
| 168 |
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
output_text = response.choices[0].message.content if hasattr(response, 'choices') else (response[0].get('generated_text') if isinstance(response, list) else response)
|
| 172 |
+
return (output_text)
|
| 173 |
+
#if isinstance(response, dict):
|
| 174 |
+
# return response.get("generated_text") or response.get("text") or str(response)
|
| 175 |
+
#if isinstance(response, list) and len(response) > 0:
|
| 176 |
+
# return response[0].get("generated_text", str(response[0]))
|
| 177 |
+
#return str(response)
|