| import gradio as gr | |
| from agent.core import run_agent | |
| async def respond_to_issue(issue_url, branch_name): | |
| logs = [] | |
| try: | |
| async for log_msg in run_agent(issue_url, branch_name): | |
| logs.append(str(log_msg)) | |
| collapsible_logs = "<details><summary>Click to view agent's used tool logs</summary>\n\n" | |
| for log in logs: | |
| collapsible_logs += f"- {log}\n" | |
| collapsible_logs += "</details>\n\n" | |
| final_message = f"{collapsible_logs} Agent has successfully processed the issue and posted an update in the comments. Check the GitHub issue for updates." | |
| return [{"role": "assistant", "content": final_message}] | |
| except Exception as e: | |
| error_message = str(e).lower() | |
| if "429" in error_message: | |
| return [{"role": "assistant", "content": f"🚫 Too many requests at the moment. Please try again after some time."}] | |
| else: | |
| return [{"role": "assistant", "content": f"🚫 Error: {str(e)}"}] | |
| theme = gr.themes.Soft( | |
| primary_hue="orange", | |
| secondary_hue="yellow", | |
| neutral_hue="zinc", | |
| ).set( | |
| button_secondary_background_fill_hover='*neutral_100', | |
| button_secondary_background_fill_hover_dark='*neutral_700', | |
| ) | |
| with gr.Blocks(title="OpenSorus – AI Maintainer Agent", theme=theme) as demo: | |
| gr.Markdown(""" | |
| # OpenSorus – AI Maintainer Agent for GitHub Issues | |
| **Reads the issue. Understands your repo. Replies in seconds.** - _Powered by Mistral AI 🧡 & LlamaIndex 🦙_ | |
| Let OpenSorus handle your first-level triage by autonomously pulling context from your codebase and commenting with a helpful fix/suggestion to help your contributors/customers. | |
| **Note**: Please [install the agent](https://github.com/apps/opensorus) as a GitHub app for a particular repository before using this tool. | |
| - **Quickest way to assign issues to OpenSorus**: Just mention @opensorus in the GitHub issue comments. | |
| - Alternatively, use this space to assign the issue by pasting the issue URL below & specifying the primary branch name of your codebase (e.g., main, master, etc.). | |
| _(Drop a ❤️ here & a ⭐️ on [GitHub](https://github.com/aditi-dsi/opensorus) if this tool made your day a little easier!)_ | |
| --- | |
| """) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| issue_url = gr.Textbox(label="🔗 GitHub Issue URL", placeholder="https://github.com/user/repo/issues/123") | |
| branch_name = gr.Textbox(label="🌿 Branch Name", placeholder="main or dev or feature/xyz") | |
| with gr.Row(): | |
| clear_btn = gr.Button("Clear", variant="secondary") | |
| submit_btn = gr.Button("Run Agent 🚀", variant="primary") | |
| with gr.Column(scale=1): | |
| chatbot = gr.Chatbot( | |
| label="Task Status", | |
| type="messages", | |
| avatar_images=( | |
| None, | |
| "https://res.cloudinary.com/ivolve/image/upload/v1749307354/OpenSorus-logo_r2bfzw.jpg", | |
| ), | |
| height=250, | |
| resizable=True, | |
| max_height=400 | |
| ) | |
| submit_btn.click( | |
| fn=respond_to_issue, | |
| inputs=[issue_url, branch_name], | |
| outputs=chatbot, | |
| queue=True, | |
| ) | |
| def clear_workspace(): | |
| return gr.update(value=""), gr.update(value=""), [] | |
| clear_btn.click( | |
| fn=clear_workspace, | |
| inputs=[], | |
| outputs=[issue_url, branch_name, chatbot], | |
| ) | |
| gr.Markdown(""" | |
| --- | |
| ### 🛠 How It Works | |
| 1. [Install OpenSorus](https://github.com/apps/opensorus) as a GitHub App. | |
| 2. Configure the app to have access to your particular repository. | |
| 3. Mention @opensorus in any issue's comments. | |
| 4. Alternatively, use this space to paste the issue URL and specify the branch name (e.g., main, master, etc.). | |
| 5. Click Run Agent and OpenSorus will fetch issue details, read your code, and post a helpful comment. | |
| **🎥 Watch the [Demo Video here](https://www.loom.com/share/d39697a60b944dbb938c3952d66cdc62?sid=1e730996-c912-4089-b717-a42ac9fbfe25).** | |
| > ### _OpenSorus is just like an L1 dev support assistant of your project that never sleeps — and knows your codebase ✨._ | |
| --- | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch() |