bwilkie commited on
Commit
ba3c8ba
·
verified ·
1 Parent(s): 8e30455

Update multiagents.py

Browse files
Files changed (1) hide show
  1. multiagents.py +43 -11
multiagents.py CHANGED
@@ -42,22 +42,54 @@ dotenv.load_dotenv()
42
  # api_key=os.environ["OPENAI_API_KEY"],
43
  # )
44
  # --- Agent wrappers ---
 
45
  class GrokApiAgent:
46
  def __init__(self):
47
  pass # No setup needed for API-based agent
48
 
49
- def __call__(self, prompt):
50
  # You could keep this for backward compatibility if needed
51
- return self.generate(prompt)
52
-
53
- def generate(self, prompt):
54
- response = GrokApi(
55
- system_prompt="You are a helpful assistant.",
56
- user_input=prompt
57
- )
58
- # Assuming GrokApi returns a string or has a property with the answer text
59
- # Adjust this depending on the actual return type of GrokApi
60
- return str(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  # Pick your agent here (just change one line to test different ones)
63
  # My_Agent = BasicAgent
 
42
  # api_key=os.environ["OPENAI_API_KEY"],
43
  # )
44
  # --- Agent wrappers ---
45
+ # Fixed GrokApiAgent class
46
  class GrokApiAgent:
47
  def __init__(self):
48
  pass # No setup needed for API-based agent
49
 
50
+ def __call__(self, prompt, **kwargs):
51
  # You could keep this for backward compatibility if needed
52
+ return self.generate(prompt, **kwargs)
53
+
54
+ def generate(self, prompt, stop_sequences=None, max_tokens=None, temperature=None, **kwargs):
55
+ """
56
+ Generate method compatible with smolagents framework.
57
+
58
+ Args:
59
+ prompt: The input prompt
60
+ stop_sequences: List of strings where generation should stop (optional)
61
+ max_tokens: Maximum number of tokens to generate (optional)
62
+ temperature: Sampling temperature (optional)
63
+ **kwargs: Other parameters that might be passed by the framework
64
+ """
65
+ try:
66
+ # Call your GrokApi with the prompt
67
+ # Note: You might need to adjust this based on how GrokApi actually works
68
+ # and whether it supports the additional parameters
69
+ response = GrokApi(
70
+ system_prompt="You are a helpful assistant.",
71
+ user_input=prompt
72
+ # Add other parameters here if GrokApi supports them:
73
+ # max_tokens=max_tokens,
74
+ # temperature=temperature,
75
+ # etc.
76
+ )
77
+
78
+ # Convert response to string and handle stop_sequences if needed
79
+ response_text = str(response)
80
+
81
+ # If stop_sequences are provided, truncate the response at the first occurrence
82
+ if stop_sequences:
83
+ for stop_seq in stop_sequences:
84
+ if stop_seq in response_text:
85
+ response_text = response_text.split(stop_seq)[0]
86
+ break
87
+
88
+ return response_text
89
+
90
+ except Exception as e:
91
+ print(f"Error in GrokApiAgent.generate: {e}")
92
+ return f"Error generating response: {e}"
93
 
94
  # Pick your agent here (just change one line to test different ones)
95
  # My_Agent = BasicAgent