Skip to content
Prev Previous commit
Rename cognify_text to cognify and update response model class name t…
…o ResponseBody
  • Loading branch information
dm1tryG committed May 15, 2025
commit 688fd4e846c35d9dc092b8bf25bfaefaefba0dde
10 changes: 3 additions & 7 deletions cognee/api/v1/responses/default_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
{
"type": "function",
"name": "cognify_text",
"name": "cognify",
"description": "Convert text into a knowledge graph or process all added content",
"parameters": {
"type": "object",
Expand All @@ -46,13 +46,9 @@
"type": "string",
"description": "Text content to be converted into a knowledge graph",
},
"graph_model_name": {
"ontology_file_path": {
"type": "string",
"description": "Name of the graph model to use",
},
"graph_model_file": {
"type": "string",
"description": "Path to a custom graph model file",
"description": "Path to a custom ontology file",
},
},
"required": ["text"],
Expand Down
6 changes: 3 additions & 3 deletions cognee/api/v1/responses/dispatch_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def dispatch_function(tool_call: Union[ToolCall, Dict[str, Any]]) -> str:

if function_name == "search":
return await handle_search(arguments, user)
elif function_name == "cognify_text":
elif function_name == "cognify":
return await handle_cognify(arguments, user)
elif function_name == "prune":
return await handle_prune(arguments, user)
Expand Down Expand Up @@ -87,12 +87,12 @@ async def handle_search(arguments: Dict[str, Any], user) -> list:
async def handle_cognify(arguments: Dict[str, Any], user) -> str:
"""Handle cognify function call"""
text = arguments.get("text")
graph_model_file = arguments.get("graph_model_file")
ontology_file_path = arguments.get("ontology_file_path")

if text:
await add(data=text, user=user)

await cognify(user=user, ontology_file_path=graph_model_file if graph_model_file else None)
await cognify(user=user, ontology_file_path=ontology_file_path if ontology_file_path else None)

return (
"Text successfully converted into knowledge graph."
Expand Down
2 changes: 1 addition & 1 deletion cognee/api/v1/responses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ResponseToolCall(BaseModel):
output: Optional[ToolCallOutput] = None


class ResponseResponse(OutDTO):
class ResponseBody(OutDTO):
"""Response body for the new responses endpoint"""

id: str = Field(default_factory=lambda: f"resp_{uuid.uuid4().hex}")
Expand Down
2 changes: 1 addition & 1 deletion cognee/api/v1/responses/routers/default_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
{
"type": "function",
"name": "cognify_text",
"name": "cognify",
"description": "Convert text into a knowledge graph or process all added content",
"parameters": {
"type": "object",
Expand Down
8 changes: 4 additions & 4 deletions cognee/api/v1/responses/routers/get_responses_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fastapi import APIRouter, Depends
from cognee.api.v1.responses.models import (
ResponseRequest,
ResponseResponse,
ResponseBody,
ResponseToolCall,
ChatUsage,
FunctionCall,
Expand Down Expand Up @@ -68,11 +68,11 @@ async def call_openai_api_for_model(
logger.info(f"Response: {response}")
return response.model_dump()

@router.post("/", response_model=ResponseResponse)
@router.post("/", response_model=ResponseBody)
async def create_response(
request: ResponseRequest,
user: User = Depends(get_authenticated_user),
) -> ResponseResponse:
) -> ResponseBody:
"""
OpenAI-compatible responses endpoint with function calling support
"""
Expand Down Expand Up @@ -133,7 +133,7 @@ async def create_response(
usage = response.get("usage", {})

# Create the response object with all processed tool calls
response_obj = ResponseResponse(
response_obj = ResponseBody(
id=response_id,
model=request.model,
tool_calls=processed_tool_calls,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/cognee_openai_compatable_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{
"data": {
"text/plain": [
"Response(id='resp_6815e775ed1c8191a7c9e5cd7d18dd6d01678e9c98ad3fea', created_at=None, error=None, incomplete_details=None, instructions=None, metadata=None, model='cognee-v1', object='response', output=None, parallel_tool_calls=None, temperature=None, tool_choice=None, tools=None, top_p=None, max_output_tokens=None, previous_response_id=None, reasoning=None, status='completed', text=None, truncation=None, usage=ResponseUsage(input_tokens=None, output_tokens=None, output_tokens_details=None, total_tokens=242, prompt_tokens=207, completion_tokens=35), user=None, created=1746266008, toolCalls=[{'id': 'call_VPk6HLbJClOEeznVbLe5l5zJ', 'type': 'function', 'function': {'name': 'cognify_text', 'arguments': '{\"text\":\"Natural language processing (NLP) is an interdisciplinary subfield of computer science and information retrieval.\"}'}, 'output': {'status': 'success', 'data': {'result': 'Text successfully converted into knowledge graph.'}}}])"
"Response(id='resp_6815e775ed1c8191a7c9e5cd7d18dd6d01678e9c98ad3fea', created_at=None, error=None, incomplete_details=None, instructions=None, metadata=None, model='cognee-v1', object='response', output=None, parallel_tool_calls=None, temperature=None, tool_choice=None, tools=None, top_p=None, max_output_tokens=None, previous_response_id=None, reasoning=None, status='completed', text=None, truncation=None, usage=ResponseUsage(input_tokens=None, output_tokens=None, output_tokens_details=None, total_tokens=242, prompt_tokens=207, completion_tokens=35), user=None, created=1746266008, toolCalls=[{'id': 'call_VPk6HLbJClOEeznVbLe5l5zJ', 'type': 'function', 'function': {'name': 'cognify', 'arguments': '{\"text\":\"Natural language processing (NLP) is an interdisciplinary subfield of computer science and information retrieval.\"}'}, 'output': {'status': 'success', 'data': {'result': 'Text successfully converted into knowledge graph.'}}}])"
]
},
"execution_count": 29,
Expand Down
Loading