Update multiagents.py
Browse files- multiagents.py +19 -8
multiagents.py
CHANGED
@@ -51,28 +51,39 @@ class GrokApiAgent:
|
|
51 |
# You could keep this for backward compatibility if needed
|
52 |
return self.generate(prompt, **kwargs)
|
53 |
|
54 |
-
def generate(self,
|
55 |
"""
|
56 |
Generate method compatible with smolagents framework.
|
57 |
|
58 |
Args:
|
59 |
-
|
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
|
|
|
51 |
# You could keep this for backward compatibility if needed
|
52 |
return self.generate(prompt, **kwargs)
|
53 |
|
54 |
+
def generate(self, messages=None, stop_sequences=None, max_tokens=None, temperature=None, **kwargs):
|
55 |
"""
|
56 |
Generate method compatible with smolagents framework.
|
57 |
|
58 |
Args:
|
59 |
+
messages: Can be a string prompt or list of messages
|
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 |
+
# Handle different input formats that smolagents might send
|
67 |
+
if messages is None:
|
68 |
+
# If no messages provided, check if prompt is in kwargs
|
69 |
+
prompt = kwargs.get('prompt', '')
|
70 |
+
elif isinstance(messages, str):
|
71 |
+
# If messages is a string, use it as prompt
|
72 |
+
prompt = messages
|
73 |
+
elif isinstance(messages, list) and len(messages) > 0:
|
74 |
+
# If messages is a list, extract the content from the last message
|
75 |
+
last_message = messages[-1]
|
76 |
+
if isinstance(last_message, dict):
|
77 |
+
prompt = last_message.get('content', str(last_message))
|
78 |
+
else:
|
79 |
+
prompt = str(last_message)
|
80 |
+
else:
|
81 |
+
prompt = str(messages) if messages else ''
|
82 |
+
|
83 |
# Call your GrokApi with the prompt
|
|
|
|
|
84 |
response = GrokApi(
|
85 |
system_prompt="You are a helpful assistant.",
|
86 |
user_input=prompt
|
|
|
|
|
|
|
|
|
87 |
)
|
88 |
|
89 |
# Convert response to string and handle stop_sequences if needed
|