Spaces:
Sleeping
Sleeping
Commit
·
50bddae
1
Parent(s):
1a22ce7
Updated
Browse files
app.py
CHANGED
|
@@ -96,7 +96,7 @@ market_template = PromptTemplate(
|
|
| 96 |
def make_llm(repo_id: str):
|
| 97 |
return HuggingFaceEndpoint(
|
| 98 |
repo_id=repo_id,
|
| 99 |
-
task="conversational", #
|
| 100 |
temperature=0.3,
|
| 101 |
top_p=0.9,
|
| 102 |
do_sample=True,
|
|
@@ -116,7 +116,8 @@ def run_conversational_model(model, prompt: str):
|
|
| 116 |
"""Send plain text prompt to HuggingFaceEndpoint and capture response"""
|
| 117 |
try:
|
| 118 |
logger.info(f"Sending prompt to HF model: {prompt}")
|
| 119 |
-
|
|
|
|
| 120 |
logger.info(f"HF raw response: {result}")
|
| 121 |
except HfHubHTTPError as e:
|
| 122 |
if "exceeded" in str(e).lower() or "quota" in str(e).lower():
|
|
@@ -127,10 +128,10 @@ def run_conversational_model(model, prompt: str):
|
|
| 127 |
|
| 128 |
# Parse output
|
| 129 |
parsed_text = None
|
| 130 |
-
if isinstance(result,
|
|
|
|
|
|
|
| 131 |
parsed_text = result["generated_text"]
|
| 132 |
-
elif isinstance(result, list) and len(result) > 0 and "generated_text" in result[0]:
|
| 133 |
-
parsed_text = result[0]["generated_text"]
|
| 134 |
else:
|
| 135 |
parsed_text = str(result)
|
| 136 |
|
|
|
|
| 96 |
def make_llm(repo_id: str):
|
| 97 |
return HuggingFaceEndpoint(
|
| 98 |
repo_id=repo_id,
|
| 99 |
+
task="conversational", # conversational for HF models
|
| 100 |
temperature=0.3,
|
| 101 |
top_p=0.9,
|
| 102 |
do_sample=True,
|
|
|
|
| 116 |
"""Send plain text prompt to HuggingFaceEndpoint and capture response"""
|
| 117 |
try:
|
| 118 |
logger.info(f"Sending prompt to HF model: {prompt}")
|
| 119 |
+
# Pass prompt as a list of messages for conversational models
|
| 120 |
+
result = model.invoke([{"role": "user", "content": prompt}])
|
| 121 |
logger.info(f"HF raw response: {result}")
|
| 122 |
except HfHubHTTPError as e:
|
| 123 |
if "exceeded" in str(e).lower() or "quota" in str(e).lower():
|
|
|
|
| 128 |
|
| 129 |
# Parse output
|
| 130 |
parsed_text = None
|
| 131 |
+
if isinstance(result, list) and len(result) > 0 and "content" in result[0]:
|
| 132 |
+
parsed_text = result[0]["content"]
|
| 133 |
+
elif isinstance(result, dict) and "generated_text" in result:
|
| 134 |
parsed_text = result["generated_text"]
|
|
|
|
|
|
|
| 135 |
else:
|
| 136 |
parsed_text = str(result)
|
| 137 |
|