euriai 0.4__py3-none-any.whl → 1.0.1__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/crewai.py ADDED
@@ -0,0 +1,229 @@
1
+ import os
2
+ from typing import Optional, Dict, Any, List, Union
3
+ from euriai.client import EuriaiClient
4
+
5
+ # CrewAI imports (user must install crewai)
6
+ try:
7
+ from crewai import Agent, Crew, Task, Process
8
+ from crewai.llm import LLM
9
+ CREWAI_AVAILABLE = True
10
+ except ImportError:
11
+ CREWAI_AVAILABLE = False
12
+ # Fallback base classes for when CrewAI is not available
13
+ class Agent:
14
+ pass
15
+ class Crew:
16
+ pass
17
+ class Task:
18
+ pass
19
+ class Process:
20
+ pass
21
+ class LLM:
22
+ pass
23
+
24
+ class EuriaiLLM(LLM):
25
+ """Custom LLM that uses Euri API for CrewAI agents"""
26
+
27
+ def __init__(self, api_key: str, model: str = "gpt-4.1-nano", temperature: float = 0.7, max_tokens: int = 1000):
28
+ if not CREWAI_AVAILABLE:
29
+ raise ImportError(
30
+ "CrewAI is not installed. Please install with: "
31
+ "pip install crewai"
32
+ )
33
+
34
+ self.client = EuriaiClient(api_key=api_key, model=model)
35
+ self.model = model
36
+ self.temperature = temperature
37
+ self.max_tokens = max_tokens
38
+
39
+ def call(self, prompt: str, **kwargs) -> str:
40
+ """Make a call to the Euri API"""
41
+ try:
42
+ response = self.client.generate_completion(
43
+ prompt=prompt,
44
+ temperature=self.temperature,
45
+ max_tokens=self.max_tokens
46
+ )
47
+ return response.get("choices", [{}])[0].get("message", {}).get("content", "")
48
+ except Exception as e:
49
+ return f"Error calling Euri API: {str(e)}"
50
+
51
+ class EuriaiCrewAI:
52
+ """
53
+ Enhanced CrewAI integration that uses Euri API for LLM calls.
54
+ """
55
+
56
+ def __init__(
57
+ self,
58
+ api_key: str,
59
+ default_model: str = "gpt-4.1-nano",
60
+ agents: Optional[Dict[str, Any]] = None,
61
+ tasks: Optional[Dict[str, Any]] = None,
62
+ process: str = "sequential",
63
+ verbose: bool = True
64
+ ):
65
+ """
66
+ Initialize the CrewAI wrapper with Euri API integration.
67
+
68
+ Args:
69
+ api_key: Your Euri API key
70
+ default_model: Default model to use (e.g., 'gpt-4.1-nano', 'claude-3-5-sonnet')
71
+ agents: Dict of agent configs
72
+ tasks: Dict of task configs
73
+ process: 'sequential' or 'parallel'
74
+ verbose: Print detailed logs
75
+ """
76
+ if Agent is None:
77
+ raise ImportError("CrewAI is not installed. Please install with `pip install crewai`.")
78
+
79
+ self.api_key = api_key
80
+ self.default_model = default_model
81
+ self.agents_config = agents or {}
82
+ self.tasks_config = tasks or {}
83
+ self.process = Process.sequential if process == "sequential" else Process.parallel
84
+ self.verbose = verbose
85
+ self._agents: List[Agent] = []
86
+ self._tasks: List[Task] = []
87
+ self._crew: Optional[Crew] = None
88
+
89
+ def _create_euri_llm(self, model: str = None, temperature: float = 0.7, max_tokens: int = 1000) -> EuriaiLLM:
90
+ """Create an EuriaiLLM instance"""
91
+ return EuriaiLLM(
92
+ api_key=self.api_key,
93
+ model=model or self.default_model,
94
+ temperature=temperature,
95
+ max_tokens=max_tokens
96
+ )
97
+
98
+ def add_agent(self, name: str, config: Dict[str, Any]) -> None:
99
+ """
100
+ Add an agent with Euri API integration.
101
+
102
+ Args:
103
+ name: Agent name
104
+ config: Agent configuration. Can include:
105
+ - model: Euri model to use (e.g., 'gpt-4.1-nano', 'claude-3-5-sonnet')
106
+ - temperature: Model temperature
107
+ - max_tokens: Max tokens for responses
108
+ - role: Agent role
109
+ - goal: Agent goal
110
+ - backstory: Agent backstory
111
+ """
112
+ # Extract LLM config
113
+ model = config.pop('model', self.default_model)
114
+ temperature = config.pop('temperature', 0.7)
115
+ max_tokens = config.pop('max_tokens', 1000)
116
+
117
+ # Create Euri LLM instance
118
+ euri_llm = self._create_euri_llm(model, temperature, max_tokens)
119
+
120
+ # Add LLM to agent config
121
+ config['llm'] = euri_llm
122
+
123
+ # Create agent
124
+ agent = Agent(**config)
125
+ self._agents.append(agent)
126
+ self.agents_config[name] = config
127
+
128
+ def add_task(self, name: str, config: Dict[str, Any]) -> None:
129
+ """Add a task by config."""
130
+ # Handle agent reference
131
+ if 'agent' in config and isinstance(config['agent'], str):
132
+ # Find agent by name
133
+ agent_name = config['agent']
134
+ for i, agent_config in enumerate(self.agents_config.values()):
135
+ if i == list(self.agents_config.keys()).index(agent_name):
136
+ config['agent'] = self._agents[i]
137
+ break
138
+
139
+ task = Task(**config)
140
+ self._tasks.append(task)
141
+ self.tasks_config[name] = config
142
+
143
+ def build_crew(self) -> Crew:
144
+ """Build the Crew object from current agents and tasks."""
145
+ if not self._agents:
146
+ for name, cfg in self.agents_config.items():
147
+ self.add_agent(name, cfg.copy())
148
+ if not self._tasks:
149
+ for name, cfg in self.tasks_config.items():
150
+ self.add_task(name, cfg.copy())
151
+
152
+ self._crew = Crew(
153
+ agents=self._agents,
154
+ tasks=self._tasks,
155
+ process=self.process,
156
+ verbose=self.verbose
157
+ )
158
+ return self._crew
159
+
160
+ def run(self, inputs: Optional[Dict[str, Any]] = None) -> Any:
161
+ """
162
+ Run the crew workflow with Euri API integration.
163
+ Returns the final result or report.
164
+ """
165
+ if self._crew is None:
166
+ self.build_crew()
167
+ return self._crew.kickoff(inputs=inputs or {})
168
+
169
+ @classmethod
170
+ def from_yaml(
171
+ cls,
172
+ agents_yaml: str,
173
+ tasks_yaml: str,
174
+ api_key: str,
175
+ default_model: str = "gpt-4.1-nano",
176
+ process: str = "sequential",
177
+ verbose: bool = True
178
+ ):
179
+ """
180
+ Create a CrewAI wrapper from YAML config files with Euri API integration.
181
+
182
+ Args:
183
+ agents_yaml: Path to agents.yaml
184
+ tasks_yaml: Path to tasks.yaml
185
+ api_key: Your Euri API key
186
+ default_model: Default model to use
187
+ """
188
+ import yaml
189
+ with open(agents_yaml, "r") as f:
190
+ agents = yaml.safe_load(f)
191
+ with open(tasks_yaml, "r") as f:
192
+ tasks = yaml.safe_load(f)
193
+ return cls(
194
+ api_key=api_key,
195
+ default_model=default_model,
196
+ agents=agents,
197
+ tasks=tasks,
198
+ process=process,
199
+ verbose=verbose
200
+ )
201
+
202
+ def get_agents(self) -> List[Agent]:
203
+ return self._agents
204
+
205
+ def get_tasks(self) -> List[Task]:
206
+ return self._tasks
207
+
208
+ def get_crew(self) -> Optional[Crew]:
209
+ return self._crew
210
+
211
+ def reset(self):
212
+ """Reset agents, tasks, and crew."""
213
+ self._agents = []
214
+ self._tasks = []
215
+ self._crew = None
216
+
217
+ def list_available_models(self) -> List[str]:
218
+ """List available Euri models"""
219
+ return [
220
+ "gpt-4.1-nano",
221
+ "gpt-4.1-mini",
222
+ "gemini-2.5-flash",
223
+ "gemini-2.5-pro",
224
+ "gemini-2.0-flash",
225
+ "gemini-2.5-pro-preview-06-05",
226
+ "gemini-2.5-flash-preview-05-20",
227
+ "gemini-2.5-flash-lite-preview-06-17",
228
+ "gemma2-9b-it"
229
+ ]