mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
Enhance regex pattern with expanded CJK character support and fix import sorting
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -140,7 +140,10 @@ class Agent(BaseAgent):
|
|||||||
self.embedder = crew_embedder
|
self.embedder = crew_embedder
|
||||||
|
|
||||||
if self.knowledge_sources:
|
if self.knowledge_sources:
|
||||||
full_pattern = re.compile(r"[^a-zA-Z0-9\u4e00-\u9fa5\-_\r\n]|(\.\.)")
|
# Unicode ranges for CJK characters:
|
||||||
|
# \u4e00-\u9fff: Common Chinese characters
|
||||||
|
# \u3400-\u4dbf: Extended CJK characters
|
||||||
|
full_pattern = re.compile(r"[^\w\u4e00-\u9fff\u3400-\u4dbf\-_\r\n]|(\.\.)")
|
||||||
knowledge_agent_name = f"{re.sub(full_pattern, '_', self.role)}"
|
knowledge_agent_name = f"{re.sub(full_pattern, '_', self.role)}"
|
||||||
if isinstance(self.knowledge_sources, list) and all(
|
if isinstance(self.knowledge_sources, list) and all(
|
||||||
isinstance(k, BaseKnowledgeSource) for k in self.knowledge_sources
|
isinstance(k, BaseKnowledgeSource) for k in self.knowledge_sources
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import pytest
|
|
||||||
import re
|
import re
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from crewai.agent import Agent
|
from crewai.agent import Agent
|
||||||
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
|
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
|
||||||
|
|
||||||
|
|
||||||
def test_agent_with_chinese_role_name():
|
def test_agent_with_chinese_role_name():
|
||||||
"""Test that an agent with a Chinese role name works correctly with the updated regex pattern."""
|
"""Test that an agent with a Chinese role name works correctly with the updated regex pattern."""
|
||||||
# Create a knowledge source with some content
|
# Create a knowledge source with some content
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import pytest
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from crewai.agent import Agent
|
from crewai.agent import Agent
|
||||||
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
|
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
|
||||||
|
|
||||||
|
|
||||||
def test_agent_with_chinese_role_name():
|
def test_agent_with_chinese_role_name():
|
||||||
"""Test that an agent with a Chinese role name works correctly."""
|
"""Test that an agent with a Chinese role name works correctly."""
|
||||||
# Create a knowledge source with some content
|
# Create a knowledge source with some content
|
||||||
|
|||||||
Reference in New Issue
Block a user