mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
mock knowledge query to not spin up db
This commit is contained in:
@@ -1578,13 +1578,6 @@ def test_agent_execute_task_with_ollama():
|
|||||||
assert "AI" in result or "artificial intelligence" in result.lower()
|
assert "AI" in result or "artificial intelligence" in result.lower()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def reset_knowledge_storage():
|
|
||||||
"""Fixture to reset knowledge storage before each test."""
|
|
||||||
Knowledge().storage.reset()
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
def test_agent_with_knowledge_sources():
|
def test_agent_with_knowledge_sources():
|
||||||
# Create a knowledge source with some content
|
# Create a knowledge source with some content
|
||||||
@@ -1592,25 +1585,33 @@ def test_agent_with_knowledge_sources():
|
|||||||
string_source = StringKnowledgeSource(
|
string_source = StringKnowledgeSource(
|
||||||
content=content, metadata={"preference": "personal"}
|
content=content, metadata={"preference": "personal"}
|
||||||
)
|
)
|
||||||
Knowledge(sources=[string_source])
|
|
||||||
|
|
||||||
# Create an agent with the knowledge source
|
with patch('crewai.knowledge.storage.knowledge_storage.KnowledgeStorage') as MockKnowledge:
|
||||||
agent = Agent(
|
mock_knowledge_instance = MockKnowledge.return_value
|
||||||
role="Information Agent",
|
mock_knowledge_instance.sources = [string_source]
|
||||||
goal="Provide information based on knowledge sources",
|
mock_knowledge_instance.query.return_value = [{
|
||||||
backstory="You have access to specific knowledge sources.",
|
"content": content,
|
||||||
llm=LLM(model="gpt-4o-mini"),
|
"metadata": {"preference": "personal"}
|
||||||
)
|
}]
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
role="Information Agent",
|
||||||
|
goal="Provide information based on knowledge sources",
|
||||||
|
backstory="You have access to specific knowledge sources.",
|
||||||
|
llm=LLM(model="gpt-4o-mini"),
|
||||||
|
)
|
||||||
|
|
||||||
# Create a task that requires the agent to use the knowledge
|
# Create a task that requires the agent to use the knowledge
|
||||||
task = Task(
|
task = Task(
|
||||||
description="What is Brandon's favorite color?",
|
description="What is Brandon's favorite color?",
|
||||||
expected_output="Brandon's favorite color.",
|
expected_output="Brandon's favorite color.",
|
||||||
agent=agent,
|
agent=agent,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Execute the task
|
crew = Crew(agents=[agent], tasks=[task])
|
||||||
result = agent.execute_task(task)
|
result = crew.kickoff()
|
||||||
|
|
||||||
|
# Assert that the agent provides the correct information
|
||||||
|
assert "blue" in result.raw.lower()
|
||||||
|
|
||||||
# Assert that the agent provides the correct information
|
|
||||||
assert "blue" in result.lower()
|
|
||||||
|
|||||||
@@ -44,27 +44,25 @@ interactions:
|
|||||||
x-stainless-runtime:
|
x-stainless-runtime:
|
||||||
- CPython
|
- CPython
|
||||||
x-stainless-runtime-version:
|
x-stainless-runtime-version:
|
||||||
- 3.12.5
|
- 3.11.9
|
||||||
method: POST
|
method: POST
|
||||||
uri: https://api.openai.com/v1/chat/completions
|
uri: https://api.openai.com/v1/chat/completions
|
||||||
response:
|
response:
|
||||||
content: "{\n \"id\": \"chatcmpl-AVNRSfYiY3uAvBKIE5yPlxcmHF8hg\",\n \"object\":
|
body:
|
||||||
\"chat.completion\",\n \"created\": 1732041642,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
|
string: !!binary |
|
||||||
\ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\":
|
H4sIAAAAAAAAA4xSQW7bMBC86xULXnqxAtmxI1e3FEWBtJekCXJpC4GmVhIdapcgqbhN4L8HlB1L
|
||||||
\"assistant\",\n \"content\": \"I now can give a great answer \\nFinal
|
QVOgFwGa2RnOLPmcAAhdiQKEamVQnTXp5f3d9lsdbndh++C+757Or6/bm6uvn59WH/FGzKKCN1tU
|
||||||
Answer: Brandon's favorite color is blue.\",\n \"refusal\": null\n },\n
|
4VV1prizBoNmOtDKoQwYXef5+SK7WK3ny4HouEITZY0N6ZLTTpNOF9limWZ5Ol8f1S1rhV4U8CMB
|
||||||
\ \"logprobs\": null,\n \"finish_reason\": \"stop\"\n }\n ],\n
|
AHgevjEnVfhbFJDNXpEOvZcNiuI0BCAcm4gI6b32QVIQs5FUTAFpiH4FxDtQkqDRjwgSmhgbJPkd
|
||||||
\ \"usage\": {\n \"prompt_tokens\": 167,\n \"completion_tokens\": 18,\n
|
OoCf9EWTNHA5/BfwyUmqmD54qOUjOx0QFBt2oD1sTI9n02Mc1r2XsSr1xhzx/Sm34cY63vgjf8Jr
|
||||||
\ \"total_tokens\": 185,\n \"prompt_tokens_details\": {\n \"cached_tokens\":
|
Tdq3pUPpmWJGH9iKgd0nAL+G/fRvKgvruLOhDPyAFA3nF/nBT4zXMmHXRzJwkGaKr2bv+JUVBqmN
|
||||||
0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n
|
n2xYKKlarEbpeB2yrzRPiGTS+u8073kfmmtq/sd+JJRCG7AqrcNKq7eNxzGH8dX+a+y05SGw8H98
|
||||||
\ \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
|
wK6sNTXorNOHN1PbMsuz1aZe5yoTyT55AQAA//8DAPaYLdRBAwAA
|
||||||
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"system_fingerprint\":
|
|
||||||
\"fp_0705bf87c0\"\n}\n"
|
|
||||||
headers:
|
headers:
|
||||||
CF-Cache-Status:
|
CF-Cache-Status:
|
||||||
- DYNAMIC
|
- DYNAMIC
|
||||||
CF-RAY:
|
CF-RAY:
|
||||||
- 8e5254865d47680c-SJC
|
- 8e54a2a7d81467f7-SJC
|
||||||
Connection:
|
Connection:
|
||||||
- keep-alive
|
- keep-alive
|
||||||
Content-Encoding:
|
Content-Encoding:
|
||||||
@@ -72,14 +70,14 @@ interactions:
|
|||||||
Content-Type:
|
Content-Type:
|
||||||
- application/json
|
- application/json
|
||||||
Date:
|
Date:
|
||||||
- Tue, 19 Nov 2024 18:40:42 GMT
|
- Wed, 20 Nov 2024 01:23:34 GMT
|
||||||
Server:
|
Server:
|
||||||
- cloudflare
|
- cloudflare
|
||||||
Set-Cookie:
|
Set-Cookie:
|
||||||
- __cf_bm=WAd8fO8QSWocATajhCTglnUAXkZag7ld.Vvm.Ams__4-1732041642-1.0.1.1-nmO.TcMZYj2VLQlxzUEcktcauU.oPPtPX6qR9sxIzHzK2w9lBIlrTxTMe5_VwCe1bGWpX.6U02mrLHPf3N6UBw;
|
- __cf_bm=DoHo1Z11nN9bxkwZmJGnaxRhyrWE0UfyimYuUVRU6A4-1732065814-1.0.1.1-JVRvFrIJLHEq9OaFQS0qcgYcawE7t2XQ4Tpqd58n2Yfx3mvEqD34MJmooi1LtvdvjB2J8x1Rs.rCdXD.msLlKw;
|
||||||
path=/; expires=Tue, 19-Nov-24 19:10:42 GMT; domain=.api.openai.com; HttpOnly;
|
path=/; expires=Wed, 20-Nov-24 01:53:34 GMT; domain=.api.openai.com; HttpOnly;
|
||||||
Secure; SameSite=None
|
Secure; SameSite=None
|
||||||
- _cfuvid=lNGPBYkRBbMGmmOXUkbBEMiRUIkqgUvHTFPPUTgpFY8-1732041642465-0.0.1.1-604800000;
|
- _cfuvid=n3RrNhFMqC3HtJ7n3e3agyxnM1YOQ6eKESz_eeXLtZA-1732065814630-0.0.1.1-604800000;
|
||||||
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
|
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
|
||||||
Transfer-Encoding:
|
Transfer-Encoding:
|
||||||
- chunked
|
- chunked
|
||||||
@@ -92,7 +90,7 @@ interactions:
|
|||||||
openai-organization:
|
openai-organization:
|
||||||
- crewai-iuxna1
|
- crewai-iuxna1
|
||||||
openai-processing-ms:
|
openai-processing-ms:
|
||||||
- '433'
|
- '344'
|
||||||
openai-version:
|
openai-version:
|
||||||
- '2020-10-01'
|
- '2020-10-01'
|
||||||
strict-transport-security:
|
strict-transport-security:
|
||||||
@@ -110,7 +108,8 @@ interactions:
|
|||||||
x-ratelimit-reset-tokens:
|
x-ratelimit-reset-tokens:
|
||||||
- 0s
|
- 0s
|
||||||
x-request-id:
|
x-request-id:
|
||||||
- req_1db7656143a6fe8ae6334797387b1172
|
- req_8f1622677c64913753a595f679596614
|
||||||
http_version: HTTP/1.1
|
status:
|
||||||
status_code: 200
|
code: 200
|
||||||
|
message: OK
|
||||||
version: 1
|
version: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user