activity init function to load llm client only once

This commit is contained in:
Steve Androulakis
2025-02-28 07:08:18 -06:00
parent 6fc43a4593
commit 71fe9925a8
3 changed files with 99 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
import asyncio
import concurrent.futures
import os
from dotenv import load_dotenv
from temporalio.worker import Worker
@@ -11,10 +12,19 @@ from shared.config import get_temporal_client, TEMPORAL_TASK_QUEUE
async def main():
# Load environment variables
load_dotenv(override=True)
# Print LLM configuration info
llm_provider = os.environ.get("LLM_PROVIDER", "openai").lower()
print(f"Worker will use LLM provider: {llm_provider}")
# Create the client
client = await get_temporal_client()
# Initialize the activities class once with the specified LLM provider
activities = ToolActivities()
print(f"ToolActivities initialized with LLM provider: {llm_provider}")
# Run the worker
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as activity_executor: