mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
fix: address lint issues in streaming implementation
- Remove whitespace from blank lines - Refactor try-except out of loop for better performance - Use list() instead of append in loop for better performance Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -792,7 +792,7 @@ class Crew(FlowTrackable, BaseModel):
|
||||
def event_generator():
|
||||
for event in crew.kickoff_stream(inputs={"topic": "AI"}):
|
||||
yield f"data: {json.dumps(event)}\\n\\n"
|
||||
|
||||
|
||||
return StreamingResponse(
|
||||
event_generator(),
|
||||
media_type="text/event-stream"
|
||||
@@ -868,15 +868,13 @@ class Crew(FlowTrackable, BaseModel):
|
||||
|
||||
try:
|
||||
while not completion_event.is_set() or not event_queue.empty():
|
||||
try:
|
||||
event = event_queue.get(timeout=0.1)
|
||||
event = event_queue.get(timeout=0.1) if not event_queue.empty() else None
|
||||
if event is not None:
|
||||
yield event
|
||||
except queue.Empty:
|
||||
continue
|
||||
|
||||
|
||||
if exception_holder["exception"]:
|
||||
raise exception_holder["exception"]
|
||||
|
||||
|
||||
finally:
|
||||
thread.join(timeout=1)
|
||||
|
||||
|
||||
@@ -4757,9 +4757,7 @@ def test_crew_kickoff_stream(researcher):
|
||||
|
||||
crew = Crew(agents=[researcher], tasks=[task])
|
||||
|
||||
events = []
|
||||
for event in crew.kickoff_stream():
|
||||
events.append(event)
|
||||
events = list(crew.kickoff_stream())
|
||||
|
||||
assert len(events) > 0
|
||||
|
||||
@@ -4784,9 +4782,7 @@ def test_crew_kickoff_stream_with_inputs(researcher):
|
||||
|
||||
crew = Crew(agents=[researcher], tasks=[task])
|
||||
|
||||
events = []
|
||||
for event in crew.kickoff_stream(inputs={"topic": "machine learning"}):
|
||||
events.append(event)
|
||||
events = list(crew.kickoff_stream(inputs={"topic": "machine learning"}))
|
||||
|
||||
assert len(events) > 0
|
||||
|
||||
@@ -4806,9 +4802,7 @@ def test_crew_kickoff_stream_includes_llm_chunks(researcher):
|
||||
|
||||
crew = Crew(agents=[researcher], tasks=[task])
|
||||
|
||||
events = []
|
||||
for event in crew.kickoff_stream():
|
||||
events.append(event)
|
||||
events = list(crew.kickoff_stream())
|
||||
|
||||
event_types = [event["type"] for event in events]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user