Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ Copy `.env.example` to `.env` and set your API credentials:
COGSOL_ENV=local
COGSOL_API_BASE=https://api.cogsol.ai/cognitive/
COGSOL_CONTENT_API_BASE=https://api.cogsol.ai/content/
COGSOL_API_TOKEN=your-api-token
COGSOL_
COGSOL_API_KEY=your-api-key
# Optional: Azure AD B2C client credentials for JWT
# If not provided, the Auth will be skipped
COGSOL_AUTH_CLIENT_ID=your-client-id
COGSOL_AUTH_SECRET=your-client-secret
```

### 4. Create Migrations
Expand Down Expand Up @@ -667,8 +672,15 @@ from cogsol.content import BaseRetrieval, ReorderingStrategy
|----------|----------|-------------|
| `COGSOL_API_BASE` | Yes | Base URL for the CogSol Cognitive API |
| `COGSOL_CONTENT_API_BASE` | No | Base URL for the CogSol Content API (defaults to `COGSOL_API_BASE`) |
| `COGSOL_API_TOKEN` | Yes | API authentication token |
| `COGSOL_API_KEY` | Yes | API Key authentication |
| `COGSOL_ENV` | No | Environment name (e.g., `local`, `production`) |
| `COGSOL_AUTH_CLIENT_ID` | No | Client Id provided for adminitrators |
| `COGSOL_AUTH_SECRET` | No | Auth Secret provided for adminitrators |

# Optional: Azure AD B2C client credentials for JWT\
# If not provided, the Auth will be skipped
COGSOL_AUTH_CLIENT_ID=your-client-id
COGSOL_AUTH_SECRET=your-client-secret

### Project Settings (`settings.py`)

Expand Down
62 changes: 31 additions & 31 deletions cogsol/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Optional
from typing import Any

from cogsol.core.api import CogSolAPIError, CogSolClient
from cogsol.core.env import load_dotenv
Expand All @@ -23,18 +23,18 @@ class BaseAgent:
"""

system_prompt: Any = None
initial_message: Optional[str] = None
forced_termination_message: Optional[str] = None
no_information_message: Optional[str] = None
initial_message: str | None = None
forced_termination_message: str | None = None
no_information_message: str | None = None
pregeneration_config: Any = None
generation_config: Any = None
pretools: list[Any] = []
tools: list[Any] = []
temperature: Optional[float] = None
max_interactions: Optional[int] = None
user_message_length: Optional[int] = None
consecutive_tool_calls_limit: Optional[int] = None
user_interactions_window: Optional[int] = None
temperature: float | None = None
max_interactions: int | None = None
user_message_length: int | None = None
consecutive_tool_calls_limit: int | None = None
user_interactions_window: int | None = None
token_optimization: Any = None
streaming: bool = False
self_improvement_mode: bool = False
Expand All @@ -44,27 +44,27 @@ class BaseAgent:
fixed_responses: list[Any] = []

class Meta:
name: Optional[str] = None
chat_name: Optional[str] = None
logo_url: Optional[str] = None
assistant_name_color: Optional[str] = None
primary_color: Optional[str] = None
secondary_color: Optional[str] = None
border_color: Optional[str] = None
name: str | None = None
chat_name: str | None = None
logo_url: str | None = None
assistant_name_color: str | None = None
primary_color: str | None = None
secondary_color: str | None = None
border_color: str | None = None

def __init__(
self,
*,
assistant_id: Optional[int] = None,
chat_id: Optional[int] = None,
api_base: Optional[str] = None,
api_token: Optional[str] = None,
project_path: Optional[Path] = None,
assistant_id: int | None = None,
chat_id: int | None = None,
api_base: str | None = None,
api_key: str | None = None,
project_path: Path | None = None,
) -> None:
self._assistant_id = assistant_id
self._chat_id = chat_id
self._api_base = api_base
self._api_token = api_token
self._api_key = api_key
self._project_path = project_path

def reset(self) -> None:
Expand All @@ -76,10 +76,10 @@ def run(
message: str,
*,
reset: bool = False,
assistant_id: Optional[int] = None,
api_base: Optional[str] = None,
api_token: Optional[str] = None,
project_path: Optional[Path] = None,
assistant_id: int | None = None,
api_base: str | None = None,
api_key: str | None = None,
project_path: Path | None = None,
async_mode: bool = False,
streaming: bool = False,
**params: Any,
Expand All @@ -101,7 +101,7 @@ def run(
base_url = api_base or self._api_base or os.environ.get("COGSOL_API_BASE")
if not base_url:
raise CogSolAPIError("COGSOL_API_BASE is required to run agents.")
token = api_token or self._api_token or os.environ.get("COGSOL_API_TOKEN")
token = api_key or self._api_key or os.environ.get("COGSOL_API_KEY")

assistant_id = assistant_id or self._assistant_id
if assistant_id is None:
Expand All @@ -118,7 +118,7 @@ def run(
continue
payload[key] = self._normalize_payload_value(value)

client = CogSolClient(base_url, token=token)
client = CogSolClient(base_url, api_key=token)
if self._chat_id is None:
chat = client.create_chat(
assistant_id,
Expand Down Expand Up @@ -155,7 +155,7 @@ def definition(cls) -> dict[str, Any]:
},
}

def _resolve_project_path(self, project_path: Optional[Path]) -> Optional[Path]:
def _resolve_project_path(self, project_path: Path | None) -> Path | None:
if project_path is not None:
return project_path
if self._project_path is not None:
Expand All @@ -169,7 +169,7 @@ def _resolve_project_path(self, project_path: Optional[Path]) -> Optional[Path]:
return parent.parent
return None

def _resolve_assistant_id(self, project_path: Optional[Path]) -> Optional[int]:
def _resolve_assistant_id(self, project_path: Path | None) -> int | None:
if project_path is None:
project_path = Path.cwd()
state_path = project_path / "agents" / "migrations" / ".state.json"
Expand All @@ -192,7 +192,7 @@ def _resolve_assistant_id(self, project_path: Optional[Path]) -> Optional[int]:
return int(value)
return None

def _chat_id_from_response(self, chat_obj: Any) -> Optional[int]:
def _chat_id_from_response(self, chat_obj: Any) -> int | None:
if isinstance(chat_obj, dict):
value = chat_obj.get("id")
if isinstance(value, int):
Expand Down
48 changes: 24 additions & 24 deletions cogsol/content/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys
from enum import Enum
from pathlib import Path
from typing import Any, Optional
from typing import Any

from cogsol.core.api import CogSolAPIError, CogSolClient
from cogsol.core.env import load_dotenv
Expand Down Expand Up @@ -89,7 +89,7 @@ class Meta:
delete_orphaned_metadata: bool = False

class Meta:
description: Optional[str] = None
description: str | None = None

def __repr__(self) -> str:
return f"<Topic {getattr(self, 'name', self.__class__.__name__)}>"
Expand Down Expand Up @@ -121,8 +121,8 @@ class AuthorMetadata(BaseMetadataConfig):

# Value constraints
possible_values: list[str] = []
default_value: Optional[str] = None
format: Optional[str] = None # Required for DATE type (e.g., "YYYY-MM-DD")
default_value: str | None = None
format: str | None = None # Required for DATE type (e.g., "YYYY-MM-DD")

# Behavior flags
filtrable: bool = False
Expand Down Expand Up @@ -176,7 +176,7 @@ class StandardPDFIngestion(BaseIngestionConfig):
"""

name: str
default_topic: Optional[type[BaseTopic]] = None
default_topic: type[BaseTopic] | None = None

# PDF parsing options
pdf_parsing_mode: PDFParsingMode = PDFParsingMode.BOTH
Expand Down Expand Up @@ -221,17 +221,17 @@ class ProductDocsRetrieval(BaseRetrieval):
"""

name: str
topic: Optional[type[BaseTopic]] = None
topic: type[BaseTopic] | None = None

# Result configuration
num_refs: int = 10
max_msg_length: int = 570

# Reordering options
reordering: bool = False
strategy_reordering: Optional[ReorderingStrategy] = None
strategy_reordering: ReorderingStrategy | None = None
retrieval_window: int = 20
reordering_metadata: Optional[str] = None
reordering_metadata: str | None = None
fixed_blocks_reordering: int = 3

# Context blocks
Expand All @@ -251,28 +251,28 @@ class ProductDocsRetrieval(BaseRetrieval):
def __init__(
self,
*,
retrieval_id: Optional[int] = None,
api_base: Optional[str] = None,
api_token: Optional[str] = None,
content_api_base: Optional[str] = None,
project_path: Optional[Path] = None,
retrieval_id: int | None = None,
api_base: str | None = None,
api_key: str | None = None,
content_api_base: str | None = None,
project_path: Path | None = None,
) -> None:
self._retrieval_id = retrieval_id
self._api_base = api_base
self._api_token = api_token
self._api_key = api_key
self._content_api_base = content_api_base
self._project_path = project_path

def run(
self,
question: str,
*,
doc_type: Optional[str | DocType] = None,
retrieval_id: Optional[int] = None,
api_base: Optional[str] = None,
api_token: Optional[str] = None,
content_api_base: Optional[str] = None,
project_path: Optional[Path] = None,
doc_type: str | DocType | None = None,
retrieval_id: int | None = None,
api_base: str | None = None,
api_key: str | None = None,
content_api_base: str | None = None,
project_path: Path | None = None,
**params: Any,
) -> Any:
"""
Expand All @@ -292,7 +292,7 @@ def run(
base_url = api_base or self._api_base or os.environ.get("COGSOL_API_BASE") or content_base
if not content_base:
raise CogSolAPIError("COGSOL_CONTENT_API_BASE is required to run retrievals.")
token = api_token or self._api_token or os.environ.get("COGSOL_API_TOKEN")
token = api_key or self._api_key or os.environ.get("COGSOL_API_KEY")

retrieval_id = retrieval_id or self._retrieval_id
if retrieval_id is None:
Expand All @@ -312,7 +312,7 @@ def run(
payload[key] = self._normalize_payload_value(value)

if base_url:
client = CogSolClient(base_url, token=token, content_base_url=content_base)
client = CogSolClient(base_url, api_key=token, content_base_url=content_base)
else:
raise CogSolAPIError("COGSOL_CONTENT_API_BASE is required to run retrievals.")
return client.request(
Expand All @@ -322,7 +322,7 @@ def run(
use_content_api=True,
)

def _resolve_project_path(self, project_path: Optional[Path]) -> Optional[Path]:
def _resolve_project_path(self, project_path: Path | None) -> Path | None:
if project_path is not None:
return project_path
if self._project_path is not None:
Expand All @@ -336,7 +336,7 @@ def _resolve_project_path(self, project_path: Optional[Path]) -> Optional[Path]:
return parent.parent
return None

def _resolve_retrieval_id(self, project_path: Optional[Path]) -> Optional[int]:
def _resolve_retrieval_id(self, project_path: Path | None) -> int | None:
if project_path is None:
project_path = Path.cwd()
state_path = project_path / "data" / "migrations" / ".state.json"
Expand Down
Loading