mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
Move where goal is set, make dummy data default for create_invoice
This commit is contained in:
13
api/main.py
13
api/main.py
@@ -23,12 +23,21 @@ load_dotenv()
|
|||||||
|
|
||||||
def get_agent_goal():
|
def get_agent_goal():
|
||||||
"""Get the agent goal from environment variables."""
|
"""Get the agent goal from environment variables."""
|
||||||
goal_name = os.getenv("AGENT_GOAL", "goal_match_train_invoice")
|
|
||||||
goals = {
|
goals = {
|
||||||
"goal_match_train_invoice": goal_match_train_invoice,
|
"goal_match_train_invoice": goal_match_train_invoice,
|
||||||
"goal_event_flight_invoice": goal_event_flight_invoice,
|
"goal_event_flight_invoice": goal_event_flight_invoice,
|
||||||
}
|
}
|
||||||
return goals.get(goal_name, goal_event_flight_invoice)
|
# Agent Goal Configuration
|
||||||
|
#AGENT_GOAL=goal_event_flight_invoice
|
||||||
|
#AGENT_GOAL=goal_match_train_invoice
|
||||||
|
|
||||||
|
#goal_name = os.getenv("AGENT_GOAL")
|
||||||
|
goal_name = "goal_event_flight_invoice"
|
||||||
|
if goal_name is not None:
|
||||||
|
return goals.get(goal_name)
|
||||||
|
else:
|
||||||
|
#if no goal is set in the env file, default to event/flight use case
|
||||||
|
return goals.get("goal_event_flight_invoice", goal_event_flight_invoice)
|
||||||
|
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from dotenv import load_dotenv
|
|||||||
|
|
||||||
load_dotenv(override=True) # Load environment variables from a .env file
|
load_dotenv(override=True) # Load environment variables from a .env file
|
||||||
|
|
||||||
stripe.api_key = os.getenv("STRIPE_API_KEY", "YOUR_DEFAULT_KEY")
|
stripe.api_key = os.getenv("STRIPE_API_KEY")
|
||||||
|
|
||||||
|
|
||||||
def ensure_customer_exists(
|
def ensure_customer_exists(
|
||||||
@@ -26,7 +26,8 @@ def ensure_customer_exists(
|
|||||||
|
|
||||||
def create_invoice(args: dict) -> dict:
|
def create_invoice(args: dict) -> dict:
|
||||||
"""Create and finalize a Stripe invoice."""
|
"""Create and finalize a Stripe invoice."""
|
||||||
# Find or create customer
|
# If an API key exists in the env file, find or create customer
|
||||||
|
if stripe.api_key is not None:
|
||||||
customer_id = ensure_customer_exists(
|
customer_id = ensure_customer_exists(
|
||||||
args.get("customer_id"), args.get("email", "default@example.com")
|
args.get("customer_id"), args.get("email", "default@example.com")
|
||||||
)
|
)
|
||||||
@@ -60,7 +61,14 @@ def create_invoice(args: dict) -> dict:
|
|||||||
"invoiceURL": finalized_invoice.hosted_invoice_url,
|
"invoiceURL": finalized_invoice.hosted_invoice_url,
|
||||||
"reference": finalized_invoice.number,
|
"reference": finalized_invoice.number,
|
||||||
}
|
}
|
||||||
|
# if no API key is in the env file, return dummy info
|
||||||
|
else:
|
||||||
|
print("[CreateInvoice] Creating invoice with:", args)
|
||||||
|
return {
|
||||||
|
"invoiceStatus": "generated",
|
||||||
|
"invoiceURL": "https://pay.example.com/invoice/12345",
|
||||||
|
"reference": "INV-12345",
|
||||||
|
}
|
||||||
|
|
||||||
def create_invoice_example(args: dict) -> dict:
|
def create_invoice_example(args: dict) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ goal_match_train_invoice = AgentGoal(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# unused
|
|
||||||
goal_event_flight_invoice = AgentGoal(
|
goal_event_flight_invoice = AgentGoal(
|
||||||
tools=[
|
tools=[
|
||||||
find_events_tool,
|
find_events_tool,
|
||||||
|
|||||||
Reference in New Issue
Block a user