Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
the-praxs committed Nov 18, 2024
1 parent 9ddf42c commit 2a615fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions taskweaver/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ExtLLMModuleConfig,
LLMModuleConfig,
LLMServiceConfig,
AgentOpsModuleConfig,
)
from taskweaver.llm.google_genai import GoogleGenAIService
from taskweaver.llm.groq import GroqService, GroqServiceConfig
Expand Down Expand Up @@ -48,11 +49,13 @@ def __init__(
config: LLMModuleConfig,
injector: Injector,
ext_llms_config: Optional[ExtLLMModuleConfig] = None,
agentops_config: Optional[AgentOpsModuleConfig] = None,
):
self.config = config
self.injector = injector
self.ext_llm_injector = Injector([])
self.ext_llms = {} # extra llm models
self.agentops_config = agentops_config

if self.config.api_type in ["openai", "azure", "azure_ad"]:
self._set_completion_service(OpenAIService)
Expand Down Expand Up @@ -115,6 +118,25 @@ def __init__(
llm_completion_service = self._get_completion_service(config)
self.ext_llms[key] = llm_completion_service

if self.agentops_config.enabled:
try:
from agentops import Client
from agentops.llms import LlmTracker

if Client().is_initialized:
self.agentops_client = Client().current_client
else:
self.agentops_client = Client()
self.agentops_client.configure(api_key=self.agentops_config.api_key, default_tags=self.agentops_config.default_tags)

self.llm_tracker = LlmTracker(self.agentops_client)
self.llm_tracker.override_api()
except ImportError as exc:
raise ImportError(
"AgentOps is not installed. Please install it with 'pip install agentops' "
"to use AgentOps tracking features."
) from exc

def _set_completion_service(self, svc: Type[CompletionService]) -> None:
self.completion_service: CompletionService = self.injector.get(svc)
self.injector.binder.bind(svc, to=self.completion_service)
Expand Down
15 changes: 15 additions & 0 deletions taskweaver/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ def _set_name(self, name: str) -> None:
self.name = f"llm.{name}"


class AgentOpsModuleConfig(ModuleConfig):
def _configure(self) -> None:
self._set_name("agentops")
self.enabled: bool = self._get_bool("enabled", False)
self.api_key: Optional[str] = self._get_str(
"api_key",
None,
required=False,
)
self.default_tags: Optional[List[str]] = self._get_list(
"default_tags",
["taskweaver"],
)


class CompletionService(abc.ABC):
@abc.abstractmethod
def chat_completion(
Expand Down

0 comments on commit 2a615fb

Please sign in to comment.