-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (51 loc) · 2.18 KB
/
main.py
File metadata and controls
73 lines (51 loc) · 2.18 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import inspect
import json
import asyncio
import logging
import traceback
import uuid
from dotenv import load_dotenv
import ray
from agent.langgraph_agent_lats import WorkflowAgent
from type.issue import Issue
from langchain import hub
from utils.utils import post_sharable_url
# import nest_asyncio
# nest_asyncio.apply()
# load API keys from globally-availabe .env file
load_dotenv(dotenv_path='.env', override=True)
def main():
"""
Executes the main workflow of the application.
This function initializes the application, loads issue data from a JSON file, and processes it using a WorkflowAgent. If the issue data is valid, it runs the workflow to handle the issue. In case of any exceptions, it logs the error along with a traceback.
The function also generates a unique run ID for each execution to track the workflow process. It ensures that the application gracefully handles errors and provides detailed logs for debugging purposes.
Returns:
tuple: An empty string and HTTP status code 200, indicating successful execution.
"""
langsmith_run_id = str(uuid.uuid4())
try:
with open('issue.json') as f:
issue_data = json.load(f)
if issue_data:
issue: Issue = Issue.from_json(issue_data)
if not issue:
raise ValueError(f"Missing the body of the webhook response. Response is {issue}")
print("ABOUT TO CALL WORKFLOW AGENT on COMMENT OPENED")
bot = WorkflowAgent(langsmith_run_id=langsmith_run_id)
run_workflow(bot, issue)
except Exception as e:
logging.error(f"❌❌ Error in {inspect.currentframe().f_code.co_name}: {e}\nTraceback:\n", traceback.print_exc())
err_str = f"Error in {inspect.currentframe().f_code.co_name}: {e}" + "\nTraceback\n```\n" + str(
traceback.format_exc()) + "\n```"
print(err_str)
return '', 200
def run_workflow(bot: WorkflowAgent, issue: Issue):
# Create final prompt for user
prompt = f"""Here's your latest assignment: {issue.format_issue()}"""
# RUN BOT
result = bot.run(prompt)
# FIN: Conclusion & results comment
logging.info(f"✅✅ Successfully completed the issue: {issue}")
logging.info(f"Output: {result}")
if __name__ == '__main__':
bot = main()