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