-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (33 loc) · 1.29 KB
/
app.py
File metadata and controls
39 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
import os
from dotenv import load_dotenv
from temporalio.client import Client, TLSConfig
from temporalio.worker import Worker
from activites import say_hello, get_model_output, measure_meaning_similarity, measure_latency, measure_structure_similarity
from workflows import HelloWorkflow, EvaluatorWorkflow
async def main():
# Load environment variables from .env file
load_dotenv()
# Get TLS certificates from environment variables
client_cert = "\n".join(os.getenv("TEMPORAL_MTLS_TLS_CERT").split("\\n"))
client_key = "\n".join(os.getenv("TEMPORAL_MTLS_TLS_KEY").split("\\n"))
# Create a Temporal client with TLS configuration
client = await Client.connect(
os.getenv("TEMPORAL_HOST_URL"),
namespace=os.getenv("TEMPORAL_NAMESPACE"),
tls=TLSConfig(
client_cert=client_cert.encode(),
client_private_key=client_key.encode(),
),
)
# Create a Temporal worker
worker = Worker(
client,
task_queue="main-queue",
workflows=[HelloWorkflow, EvaluatorWorkflow],
activities=[say_hello, get_model_output, measure_meaning_similarity, measure_latency, measure_structure_similarity],
)
# Run the worker
await worker.run()
if __name__ == "__main__":
asyncio.run(main())