mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
activity init function to load llm client only once
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user