sunbal7 commited on
Commit
ed3bcaa
·
verified ·
1 Parent(s): f741627

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +14 -32
agents.py CHANGED
@@ -1,37 +1,19 @@
1
- import os
2
- from huggingface_hub import InferenceClient
3
 
4
- HF_TOKEN = os.getenv("HF_TOKEN")
5
-
6
- MODEL_NAME = "google/gemma-2-2b-it"
7
-
8
- client = InferenceClient(
9
- model=MODEL_NAME,
10
- token=HF_TOKEN
11
  )
12
 
13
 
14
  def run_agent(system_prompt: str, user_input: str) -> str:
15
- """
16
- Runs a conversational LLM call.
17
- This is REQUIRED for Gemma instruction models.
18
- """
19
-
20
- messages = [
21
- {
22
- "role": "system",
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