-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:l3vels/L3AGI
- Loading branch information
Showing
63 changed files
with
22,241 additions
and
2,500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import List | ||
|
||
from fastapi import APIRouter | ||
|
||
from integrations.get_integrations import get_all_integration_providers | ||
from typings.integrations import IntegrationOutput | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("", response_model=List[IntegrationOutput]) | ||
def get_integrations() -> List[IntegrationOutput]: | ||
""" | ||
Get all integrations | ||
""" | ||
|
||
return get_all_integration_providers() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from abc import abstractmethod | ||
from enum import Enum | ||
from typing import Dict, List, Optional | ||
|
||
from pydantic import BaseModel, Field, validator | ||
|
||
from models.config import ConfigModel | ||
from typings.agent import AgentOutput, ConfigsOutput | ||
from typings.config import ConfigQueryParams | ||
|
||
|
||
class IntegrationEnvKeyType(Enum): | ||
STRING = "string" | ||
FILE = "file" | ||
INT = "int" | ||
|
||
def __str__(self): | ||
return self.value | ||
|
||
|
||
class IntegrationEnvKey(BaseModel): | ||
label: str = Field() | ||
key: str = Field() | ||
key_type: IntegrationEnvKeyType = Field(default=IntegrationEnvKeyType.STRING) | ||
is_required: bool = Field(default=False) | ||
is_secret: bool = Field(default=False) | ||
default_value: str = Field(default=None) | ||
|
||
@validator("is_secret", "is_required", pre=True, always=True) | ||
def check_bool(cls, v): | ||
"""Check if the value is a boolean.""" | ||
if v is None: | ||
return False | ||
elif isinstance(v, bool): | ||
return v | ||
else: | ||
raise ValueError("Value should be a boolean") | ||
|
||
@validator("key_type", pre=True, always=True) | ||
def check_key_type(cls, v): | ||
"""Check if the value is a boolean.""" | ||
if v is None: | ||
return IntegrationEnvKeyType.STRING | ||
elif isinstance(v, IntegrationEnvKeyType): | ||
return v | ||
else: | ||
raise ValueError("key_type should be string/file/integer") | ||
|
||
|
||
class BaseIntegrationTools: | ||
id: str | ||
configs: Dict[str, str] = {} | ||
settings: Optional[ConfigsOutput] = None | ||
voice_slug: Optional[str] = None | ||
agent: Optional[AgentOutput] = None | ||
|
||
def get_env_key(self, key: str): | ||
return self.configs.get(key) | ||
|
||
|
||
class BaseIntegration(BaseModel): | ||
id: str | ||
name: str | ||
description: str | ||
slug: str | ||
is_active: bool = Field(default=True) | ||
|
||
def get_tools_with_configs( | ||
self, db, account, settings, agent_with_configs | ||
) -> List[BaseIntegrationTools]: | ||
configs = ConfigModel.get_configs( | ||
db=db, query=ConfigQueryParams(toolkit_id=self.id), account=account | ||
) | ||
config_dict = {config.key: config.value for config in configs} | ||
tools = self.get_tools() | ||
|
||
for tool in tools: | ||
tool.configs = config_dict | ||
tool.voice_slug = self.slug | ||
tool.settings = settings | ||
tool.account = account | ||
|
||
return tools | ||
|
||
@abstractmethod | ||
def get_env_keys(self) -> List[IntegrationEnvKey]: | ||
# Add file related config keys here | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from typing import List | ||
|
||
from integrations.base import BaseIntegration | ||
from integrations.telegram.telegram_integration import TelegramIntegration | ||
from typings.integrations import IntegrationOutput | ||
|
||
INTEGRATIONS: List[BaseIntegration] = [ | ||
TelegramIntegration(), | ||
] | ||
|
||
|
||
COMING_SOON = [ | ||
{ | ||
"is_public": True, | ||
"is_active": False, | ||
"name": "WhatsApp", | ||
"description": "Connect L3AGI chat with WhatsApp for smooth communication between sessions.", | ||
}, | ||
{ | ||
"is_public": True, | ||
"is_active": False, | ||
"name": "Facebook Messenger", | ||
"description": "Connect L3AGI chat with Facebook's Messenger for smooth communication between sessions.", | ||
}, | ||
] | ||
|
||
|
||
def get_all_integration_providers(): | ||
"""Return a list of all integrations.""" | ||
result = [] | ||
|
||
for integration in INTEGRATIONS: | ||
result.append( | ||
IntegrationOutput( | ||
id=integration.id, | ||
is_public=True, | ||
is_active=integration.is_active, | ||
name=integration.name, | ||
slug=integration.slug, | ||
description=integration.description, | ||
fields=[ | ||
{ | ||
"label": env_key.label, | ||
"key": env_key.key, | ||
"type": str(env_key.key_type), | ||
"is_required": env_key.is_required, | ||
"is_secret": env_key.is_secret, | ||
"default_value": str(env_key.default_value) | ||
if env_key.default_value is not None | ||
else None, | ||
} | ||
for env_key in integration.get_env_keys() | ||
], | ||
# tools=[ | ||
# { | ||
# "tool_id": tool.tool_id, | ||
# "name": tool.name, | ||
# "description": tool.description, | ||
# } | ||
# for tool in voice.get_tools() | ||
# ], | ||
) | ||
) | ||
|
||
for integration in COMING_SOON: | ||
result.append( | ||
IntegrationOutput( | ||
id=None, # Update this if COMING_SOON has an 'id' field | ||
is_public=integration["is_public"], | ||
is_active=integration["is_active"], | ||
name=integration["name"], | ||
description=integration["description"], | ||
fields=[], # Update this if COMING_SOON has a 'fields' field | ||
) | ||
) | ||
|
||
return result |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from abc import ABC | ||
from typing import List | ||
|
||
from integrations.base import (BaseIntegration, IntegrationEnvKey, | ||
IntegrationEnvKeyType) | ||
|
||
|
||
class TelegramIntegration(BaseIntegration, ABC): | ||
name: str = "Telegram Bot" | ||
description: str = "Connect L3AGI chat with a Telegram bot for smooth communication between sessions." | ||
slug: str = "telegram" | ||
|
||
id = "2c2849ab-c74e-485c-9603-b8a18280c7b1" | ||
|
||
def get_env_keys(self) -> List[IntegrationEnvKey]: | ||
return [ | ||
IntegrationEnvKey( | ||
label="Bot API Token Key", | ||
key="TELEGRAM_BOT_API_KEY", | ||
key_type=IntegrationEnvKeyType.STRING, | ||
is_required=True, | ||
is_secret=True, | ||
), | ||
IntegrationEnvKey( | ||
label="Bot Username", | ||
key="TELEGRAM_BOT_USERNAME", | ||
key_type=IntegrationEnvKeyType.STRING, | ||
is_required=False, | ||
is_secret=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import List, Optional | ||
|
||
from pydantic import UUID4, BaseModel | ||
|
||
|
||
class IntegrationFieldOutput(BaseModel): | ||
label: str | ||
key: str | ||
type: str | ||
is_required: bool | ||
is_secret: bool | ||
default_value: Optional[str] = None | ||
|
||
|
||
class IntegrationOutput(BaseModel): | ||
id: Optional[UUID4] | ||
is_active: bool | ||
is_public: bool | ||
name: str | ||
description: Optional[str] | ||
slug: Optional[str] | ||
fields: Optional[List[IntegrationFieldOutput]] |
Oops, something went wrong.