euriai 0.4__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
euriai/__init__.py CHANGED
@@ -1,21 +1,18 @@
1
1
  from .client import EuriaiClient
2
- from .langchain_llm import EuriaiLangChainLLM
2
+ from .langchain import EuriaiChatModel, EuriaiEmbeddings, EuriaiLLM
3
3
  from .embedding import EuriaiEmbeddingClient
4
- from .langchain_embed import EuriaiEmbeddings
5
4
  from .euri_chat import EuriaiLlamaIndexLLM
6
5
  from .euri_embed import EuriaiLlamaIndexEmbedding
7
- from .euri_crewai import EuriaiCrewAI
8
- from .euri_autogen import EuriaiAutoGen
9
- from .euri_llamaindex import EuriaiLlamaIndex
10
- from .euri_langgraph import EuriaiLangGraph
11
- from .euri_smolagents import EuriaiSmolAgent
12
- from .euri_n8n import EuriaiN8N
6
+ from .crewai import EuriaiCrewAI
7
+ from .autogen import EuriaiAutoGen
8
+ from .llamaindex import EuriaiLlamaIndex
9
+ from .langgraph import EuriaiLangGraph
10
+ from .smolagents import EuriaiSmolAgent
11
+ from .n8n import EuriaiN8N
13
12
 
14
13
  __all__ = [
15
14
  "EuriaiClient",
16
- "EuriaiLangChainLLM",
17
15
  "EuriaiEmbeddingClient",
18
- "EuriaiEmbeddings",
19
16
  "EuriaiLlamaIndexLLM",
20
17
  "EuriaiLlamaIndexEmbedding",
21
18
  "EuriaiCrewAI",
@@ -24,4 +21,7 @@ __all__ = [
24
21
  "EuriaiLangGraph",
25
22
  "EuriaiSmolAgent",
26
23
  "EuriaiN8N",
24
+ "EuriaiChatModel",
25
+ "EuriaiEmbeddings",
26
+ "EuriaiLLM",
27
27
  ]
euriai/autogen.py ADDED
@@ -0,0 +1,511 @@
1
+ from typing import Optional, Dict, Any, List, Union
2
+ from types import SimpleNamespace
3
+ from euriai.client import EuriaiClient
4
+
5
+ try:
6
+ import autogen
7
+ from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager
8
+ except ImportError:
9
+ autogen = None
10
+ AssistantAgent = UserProxyAgent = GroupChat = GroupChatManager = None
11
+
12
+ class EuriaiModelClient:
13
+ """
14
+ Custom model client that uses Euri API for AutoGen integration.
15
+ Implements the ModelClient protocol required by AutoGen.
16
+ """
17
+
18
+ def __init__(self, config: Dict[str, Any], **kwargs):
19
+ """
20
+ Initialize the Euri model client.
21
+
22
+ Args:
23
+ config: Configuration dictionary containing:
24
+ - model: Euri model name (e.g., 'gpt-4.1-nano', 'claude-3-5-sonnet')
25
+ - api_key: Euri API key
26
+ - temperature: Model temperature (optional)
27
+ - max_tokens: Maximum tokens (optional)
28
+ """
29
+ self.config = config
30
+ self.model = config["model"]
31
+ self.api_key = config.get("api_key")
32
+ self.temperature = config.get("temperature", 0.7)
33
+ self.max_tokens = config.get("max_tokens", 1000)
34
+
35
+ if not self.api_key:
36
+ raise ValueError("Euri API key is required in config")
37
+
38
+ # Initialize Euri client
39
+ self.client = EuriaiClient(
40
+ api_key=self.api_key,
41
+ model=self.model
42
+ )
43
+
44
+ print(f"EuriaiModelClient initialized with model: {self.model}")
45
+
46
+ def create(self, params: Dict[str, Any]) -> SimpleNamespace:
47
+ """
48
+ Create a response using the Euri API.
49
+
50
+ Args:
51
+ params: Parameters containing:
52
+ - messages: List of message dictionaries
53
+ - n: Number of responses (default 1)
54
+ - temperature: Temperature override
55
+ - max_tokens: Max tokens override
56
+
57
+ Returns:
58
+ Response object following AutoGen's ModelClientResponseProtocol
59
+ """
60
+ # Extract parameters
61
+ messages = params.get("messages", [])
62
+ n = params.get("n", 1)
63
+ temperature = params.get("temperature", self.temperature)
64
+ max_tokens = params.get("max_tokens", self.max_tokens)
65
+
66
+ # Convert messages to prompt format
67
+ prompt = self._convert_messages_to_prompt(messages)
68
+
69
+ # Create response object
70
+ response = SimpleNamespace()
71
+ response.choices = []
72
+ response.model = self.model
73
+ response.usage = SimpleNamespace()
74
+
75
+ # Generate responses
76
+ for _ in range(n):
77
+ try:
78
+ # Call Euri API
79
+ euri_response = self.client.generate_completion(
80
+ prompt=prompt,
81
+ temperature=temperature,
82
+ max_tokens=max_tokens
83
+ )
84
+
85
+ # Extract content
86
+ content = euri_response.get("choices", [{}])[0].get("message", {}).get("content", "")
87
+
88
+ # Create choice object
89
+ choice = SimpleNamespace()
90
+ choice.message = SimpleNamespace()
91
+ choice.message.content = content
92
+ choice.message.function_call = None
93
+ choice.finish_reason = "stop"
94
+
95
+ response.choices.append(choice)
96
+
97
+ # Add usage info if available
98
+ if "usage" in euri_response:
99
+ usage = euri_response["usage"]
100
+ response.usage.prompt_tokens = usage.get("prompt_tokens", 0)
101
+ response.usage.completion_tokens = usage.get("completion_tokens", 0)
102
+ response.usage.total_tokens = usage.get("total_tokens", 0)
103
+
104
+ except Exception as e:
105
+ print(f"Error calling Euri API: {e}")
106
+ # Create error response
107
+ choice = SimpleNamespace()
108
+ choice.message = SimpleNamespace()
109
+ choice.message.content = f"Error: {str(e)}"
110
+ choice.message.function_call = None
111
+ choice.finish_reason = "error"
112
+ response.choices.append(choice)
113
+
114
+ return response
115
+
116
+ def message_retrieval(self, response: SimpleNamespace) -> List[str]:
117
+ """
118
+ Retrieve messages from the response.
119
+
120
+ Args:
121
+ response: Response object from create()
122
+
123
+ Returns:
124
+ List of response strings
125
+ """
126
+ return [choice.message.content for choice in response.choices]
127
+
128
+ def cost(self, response: SimpleNamespace) -> float:
129
+ """
130
+ Calculate the cost of the response.
131
+
132
+ Args:
133
+ response: Response object from create()
134
+
135
+ Returns:
136
+ Cost of the response (0 for now)
137
+ """
138
+ return 0.0
139
+
140
+ @staticmethod
141
+ def get_usage(response: SimpleNamespace) -> Dict[str, Any]:
142
+ """
143
+ Get usage statistics from the response.
144
+
145
+ Args:
146
+ response: Response object from create()
147
+
148
+ Returns:
149
+ Usage statistics dictionary
150
+ """
151
+ usage = getattr(response, 'usage', SimpleNamespace())
152
+ return {
153
+ "prompt_tokens": getattr(usage, 'prompt_tokens', 0),
154
+ "completion_tokens": getattr(usage, 'completion_tokens', 0),
155
+ "total_tokens": getattr(usage, 'total_tokens', 0),
156
+ "cost": 0.0,
157
+ "model": response.model
158
+ }
159
+
160
+ def _convert_messages_to_prompt(self, messages: List[Dict[str, str]]) -> str:
161
+ """
162
+ Convert AutoGen messages to a prompt string.
163
+
164
+ Args:
165
+ messages: List of message dictionaries
166
+
167
+ Returns:
168
+ Formatted prompt string
169
+ """
170
+ prompt_parts = []
171
+
172
+ for message in messages:
173
+ role = message.get("role", "user")
174
+ content = message.get("content", "")
175
+
176
+ if role == "system":
177
+ prompt_parts.append(f"System: {content}")
178
+ elif role == "user":
179
+ prompt_parts.append(f"User: {content}")
180
+ elif role == "assistant":
181
+ prompt_parts.append(f"Assistant: {content}")
182
+ else:
183
+ prompt_parts.append(f"{role}: {content}")
184
+
185
+ return "\n".join(prompt_parts)
186
+
187
+ class EuriaiAutoGen:
188
+ """
189
+ Enhanced AutoGen integration that uses Euri API for all LLM calls.
190
+ """
191
+
192
+ def __init__(self, api_key: str, default_model: str = "gpt-4.1-nano"):
193
+ """
194
+ Initialize the EuriaiAutoGen wrapper.
195
+
196
+ Args:
197
+ api_key: Your Euri API key
198
+ default_model: Default model to use
199
+ """
200
+ if autogen is None:
201
+ raise ImportError("AutoGen is not installed. Please install with `pip install pyautogen`.")
202
+
203
+ self.api_key = api_key
204
+ self.default_model = default_model
205
+ self.agents: List[Any] = []
206
+ self.group_chat: Optional[GroupChat] = None
207
+ self.group_chat_manager: Optional[GroupChatManager] = None
208
+ self.history: List[Dict[str, Any]] = []
209
+
210
+ def create_assistant_agent(
211
+ self,
212
+ name: str,
213
+ system_message: Optional[str] = None,
214
+ model: Optional[str] = None,
215
+ temperature: float = 0.7,
216
+ max_tokens: int = 1000,
217
+ **kwargs
218
+ ) -> AssistantAgent:
219
+ """
220
+ Create an assistant agent with Euri API integration.
221
+
222
+ Args:
223
+ name: Agent name
224
+ system_message: System message for the agent
225
+ model: Euri model to use
226
+ temperature: Model temperature
227
+ max_tokens: Maximum tokens
228
+ **kwargs: Additional arguments for AssistantAgent
229
+
230
+ Returns:
231
+ Configured AssistantAgent
232
+ """
233
+ # Create config for Euri API
234
+ config_list = [{
235
+ "model": model or self.default_model,
236
+ "model_client_cls": "EuriaiModelClient",
237
+ "api_key": self.api_key,
238
+ "temperature": temperature,
239
+ "max_tokens": max_tokens
240
+ }]
241
+
242
+ # Create agent
243
+ agent = AssistantAgent(
244
+ name=name,
245
+ system_message=system_message,
246
+ llm_config={"config_list": config_list},
247
+ **kwargs
248
+ )
249
+
250
+ # Register the custom model client
251
+ agent.register_model_client(model_client_cls=EuriaiModelClient)
252
+
253
+ self.agents.append(agent)
254
+ return agent
255
+
256
+ def create_user_proxy_agent(
257
+ self,
258
+ name: str,
259
+ is_termination_msg: Optional[callable] = None,
260
+ code_execution_config: Optional[Dict[str, Any]] = None,
261
+ **kwargs
262
+ ) -> UserProxyAgent:
263
+ """
264
+ Create a user proxy agent.
265
+
266
+ Args:
267
+ name: Agent name
268
+ is_termination_msg: Termination message function
269
+ code_execution_config: Code execution configuration
270
+ **kwargs: Additional arguments for UserProxyAgent
271
+
272
+ Returns:
273
+ Configured UserProxyAgent
274
+ """
275
+ agent = UserProxyAgent(
276
+ name=name,
277
+ is_termination_msg=is_termination_msg,
278
+ code_execution_config=code_execution_config or {"use_docker": False},
279
+ **kwargs
280
+ )
281
+
282
+ self.agents.append(agent)
283
+ return agent
284
+
285
+ def create_group_chat(
286
+ self,
287
+ agents: List[Any],
288
+ messages: Optional[List[Dict[str, str]]] = None,
289
+ max_round: int = 10,
290
+ admin_name: str = "Admin",
291
+ speaker_selection_method: str = "auto",
292
+ **kwargs
293
+ ) -> GroupChat:
294
+ """
295
+ Create a group chat with multiple agents.
296
+
297
+ Args:
298
+ agents: List of agents for the group chat
299
+ messages: Initial messages
300
+ max_round: Maximum number of rounds
301
+ admin_name: Admin agent name
302
+ speaker_selection_method: Speaker selection method
303
+ **kwargs: Additional arguments for GroupChat
304
+
305
+ Returns:
306
+ Configured GroupChat
307
+ """
308
+ self.group_chat = GroupChat(
309
+ agents=agents,
310
+ messages=messages or [],
311
+ max_round=max_round,
312
+ admin_name=admin_name,
313
+ speaker_selection_method=speaker_selection_method,
314
+ **kwargs
315
+ )
316
+
317
+ return self.group_chat
318
+
319
+ def create_group_chat_manager(
320
+ self,
321
+ groupchat: GroupChat,
322
+ model: Optional[str] = None,
323
+ temperature: float = 0.7,
324
+ max_tokens: int = 1000,
325
+ **kwargs
326
+ ) -> GroupChatManager:
327
+ """
328
+ Create a group chat manager.
329
+
330
+ Args:
331
+ groupchat: GroupChat instance
332
+ model: Euri model to use
333
+ temperature: Model temperature
334
+ max_tokens: Maximum tokens
335
+ **kwargs: Additional arguments for GroupChatManager
336
+
337
+ Returns:
338
+ Configured GroupChatManager
339
+ """
340
+ # Create config for Euri API
341
+ config_list = [{
342
+ "model": model or self.default_model,
343
+ "model_client_cls": "EuriaiModelClient",
344
+ "api_key": self.api_key,
345
+ "temperature": temperature,
346
+ "max_tokens": max_tokens
347
+ }]
348
+
349
+ # Create manager
350
+ self.group_chat_manager = GroupChatManager(
351
+ groupchat=groupchat,
352
+ llm_config={"config_list": config_list},
353
+ **kwargs
354
+ )
355
+
356
+ # Register the custom model client
357
+ self.group_chat_manager.register_model_client(model_client_cls=EuriaiModelClient)
358
+
359
+ return self.group_chat_manager
360
+
361
+ def run_chat(
362
+ self,
363
+ agent1: Any,
364
+ agent2: Any,
365
+ message: str,
366
+ max_turns: int = 10,
367
+ **kwargs
368
+ ) -> Dict[str, Any]:
369
+ """
370
+ Run a chat between two agents.
371
+
372
+ Args:
373
+ agent1: First agent
374
+ agent2: Second agent
375
+ message: Initial message
376
+ max_turns: Maximum number of turns
377
+ **kwargs: Additional arguments for initiate_chat
378
+
379
+ Returns:
380
+ Chat result
381
+ """
382
+ try:
383
+ result = agent1.initiate_chat(
384
+ agent2,
385
+ message=message,
386
+ max_turns=max_turns,
387
+ **kwargs
388
+ )
389
+
390
+ # Store in history
391
+ self.history.append({
392
+ "type": "two_agent_chat",
393
+ "agent1": agent1.name,
394
+ "agent2": agent2.name,
395
+ "message": message,
396
+ "result": result
397
+ })
398
+
399
+ return result
400
+
401
+ except Exception as e:
402
+ print(f"Error in chat: {e}")
403
+ return {"error": str(e)}
404
+
405
+ def run_group_chat(
406
+ self,
407
+ message: str,
408
+ max_turns: int = 10,
409
+ **kwargs
410
+ ) -> Dict[str, Any]:
411
+ """
412
+ Run a group chat with multiple agents.
413
+
414
+ Args:
415
+ message: Initial message
416
+ max_turns: Maximum number of turns
417
+ **kwargs: Additional arguments for initiate_chat
418
+
419
+ Returns:
420
+ Group chat result
421
+ """
422
+ if not self.group_chat_manager:
423
+ raise ValueError("Group chat manager not created. Use create_group_chat_manager() first.")
424
+
425
+ try:
426
+ # Create a user proxy to start the conversation
427
+ user_proxy = self.create_user_proxy_agent(
428
+ name="User",
429
+ human_input_mode="NEVER",
430
+ max_consecutive_auto_reply=0
431
+ )
432
+
433
+ result = user_proxy.initiate_chat(
434
+ self.group_chat_manager,
435
+ message=message,
436
+ max_turns=max_turns,
437
+ **kwargs
438
+ )
439
+
440
+ # Store in history
441
+ self.history.append({
442
+ "type": "group_chat",
443
+ "message": message,
444
+ "result": result
445
+ })
446
+
447
+ return result
448
+
449
+ except Exception as e:
450
+ print(f"Error in group chat: {e}")
451
+ return {"error": str(e)}
452
+
453
+ def get_available_models(self) -> List[str]:
454
+ """
455
+ Get list of available Euri models.
456
+
457
+ Returns:
458
+ List of available models
459
+ """
460
+ return [
461
+ "gpt-4.1-nano",
462
+ "gpt-4.1-turbo",
463
+ "gpt-4.1-preview",
464
+ "claude-3-5-sonnet",
465
+ "claude-3-5-haiku",
466
+ "gemini-2.5-flash",
467
+ "gemini-2.5-pro"
468
+ ]
469
+
470
+ def get_history(self) -> List[Dict[str, Any]]:
471
+ """
472
+ Get chat history.
473
+
474
+ Returns:
475
+ List of chat history entries
476
+ """
477
+ return self.history
478
+
479
+ def reset(self):
480
+ """
481
+ Reset agents, group chat, and history.
482
+ """
483
+ self.agents = []
484
+ self.group_chat = None
485
+ self.group_chat_manager = None
486
+ self.history = []
487
+
488
+ def create_config_list(
489
+ self,
490
+ model: str,
491
+ temperature: float = 0.7,
492
+ max_tokens: int = 1000
493
+ ) -> List[Dict[str, Any]]:
494
+ """
495
+ Create a configuration list for manual agent creation.
496
+
497
+ Args:
498
+ model: Euri model name
499
+ temperature: Model temperature
500
+ max_tokens: Maximum tokens
501
+
502
+ Returns:
503
+ Configuration list for AutoGen
504
+ """
505
+ return [{
506
+ "model": model,
507
+ "model_client_cls": "EuriaiModelClient",
508
+ "api_key": self.api_key,
509
+ "temperature": temperature,
510
+ "max_tokens": max_tokens
511
+ }]