Spaces:
Sleeping
Sleeping
Update agents.py
Browse files
agents.py
CHANGED
|
@@ -1,37 +1,19 @@
|
|
| 1 |
-
import
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
model=MODEL_NAME,
|
| 10 |
-
token=HF_TOKEN
|
| 11 |
)
|
| 12 |
|
| 13 |
|
| 14 |
def run_agent(system_prompt: str, user_input: str) -> str:
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
"content": system_prompt
|
| 24 |
-
},
|
| 25 |
-
{
|
| 26 |
-
"role": "user",
|
| 27 |
-
"content": user_input
|
| 28 |
-
}
|
| 29 |
-
]
|
| 30 |
-
|
| 31 |
-
response = client.chat_completion(
|
| 32 |
-
messages=messages,
|
| 33 |
-
max_tokens=1800,
|
| 34 |
-
temperature=0.2
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
return response.choices[0].message.content
|
|
|
|
| 1 |
+
from transformers import pipeline
|
|
|
|
| 2 |
|
| 3 |
+
# Load once (cached by HF Spaces)
|
| 4 |
+
generator = pipeline(
|
| 5 |
+
"text2text-generation",
|
| 6 |
+
model="google/flan-t5-base",
|
| 7 |
+
max_length=1024
|
|
|
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
|
| 11 |
def run_agent(system_prompt: str, user_input: str) -> str:
|
| 12 |
+
prompt = f"""
|
| 13 |
+
{system_prompt}
|
| 14 |
+
|
| 15 |
+
USER INPUT:
|
| 16 |
+
{user_input}
|
| 17 |
+
"""
|
| 18 |
+
output = generator(prompt, do_sample=False)[0]["generated_text"]
|
| 19 |
+
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|