File size: 5,669 Bytes
4699a33
7edb85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4699a33
7edb85f
 
 
 
 
 
 
 
 
4699a33
 
 
7edb85f
 
4699a33
 
7edb85f
 
 
4699a33
 
 
 
7edb85f
4699a33
7edb85f
 
 
 
 
 
 
 
 
4699a33
7edb85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4699a33
7edb85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4699a33
7edb85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fdb34a
 
 
 
4699a33
c640a2f
 
7edb85f
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import traceback
from typing import Any

import gradio as gr

from agent import run_agent


APP_TITLE = "AI Developer Assistant - Miço"

APP_DESCRIPTION = """
Python paketlerini inceleyen, GitHub repository'lerini araştıran
ve Stack Overflow üzerinde teknik çözüm arayan yapay zekâ destekli
geliştirici asistanı.
"""


def process_user_message(
    user_message: str,
) -> tuple[
    str,
    dict[str, Any],
    list[dict[str, Any]],
    str,
]:
    """
    Gradio arayüzünden alınan kullanıcı mesajını
    agent pipeline'ına gönderir.
    """

    if not user_message or not user_message.strip():
        return (
            "Herhangi bir planner analizi oluşturulmadı.",
            {
                "calls": [],
            },
            [],
            (
                "⚠️ Lütfen çalıştırmadan önce "
                "bir geliştirici sorusu girin."
            ),
        )

    try:
        return run_agent(
            user_message.strip()
        )

    except Exception as exc:
        traceback.print_exc()

        error_message = str(exc)

        return (
            (
                "Agent çalıştırılırken hata oluştu.\n\n"
                f"{error_message}"
            ),
            {
                "calls": [],
            },
            [
                {
                    "success": False,
                    "error": error_message,
                }
            ],
            (
                "## İşlem başarısız\n\n"
                "Agent çalıştırılırken bir hata oluştu.\n\n"
                f"```text\n{error_message}\n```"
            ),
        )


def clear_interface() -> tuple[
    str,
    str,
    dict[str, Any],
    list[Any],
    str,
]:
    """
    Arayüzdeki giriş ve sonuç alanlarını temizler.
    """

    return (
        "",
        "",
        {
            "calls": [],
        },
        [],
        "",
    )


with gr.Blocks(
    title=APP_TITLE,
) as demo:

    gr.Markdown(
        f"""
# 🤖 {APP_TITLE}

{APP_DESCRIPTION}

Desteklenen araçlar:

- **PyPI:** Python paket bilgileri
- **GitHub:** Repository bilgileri ve repository araması
- **Stack Overflow:** Programlama hataları ve teknik sorular
"""
    )

    with gr.Row():
        user_input = gr.Textbox(
            label="Geliştirici Sorusu",
            placeholder=(
                "Örnek: requests ve httpx paketlerini karşılaştır."
            ),
            lines=5,
            max_lines=12,
            autofocus=True,
        )

    with gr.Row():
        submit_button = gr.Button(
            "🚀 Agent'ı Çalıştır",
            variant="primary",
        )

        clear_button = gr.Button(
            "🗑️ Temizle",
            variant="secondary",
        )

    gr.Markdown("---")

    with gr.Accordion(
        "🧠 Planner Analizi",
        open=False,
    ):
        thinking_output = gr.Textbox(
            label="Planner Thinking",
            lines=10,
            interactive=False,
        )

    with gr.Accordion(
        "🛠️ Tool Plan",
        open=True,
    ):
        plan_output = gr.JSON(
            label="Oluşturulan Tool Planı",
            value={
                "calls": [],
            },
        )

    with gr.Accordion(
        "📦 Tool Sonuçları",
        open=True,
    ):
        tool_results_output = gr.JSON(
            label="Tool Execution Results",
            value=[],
        )

    gr.Markdown("## 💬 Nihai Cevap")

    final_answer_output = gr.Markdown(
        value=(
            "Agent cevabı burada görüntülenecek."
        )
    )

    gr.Markdown("---")

    gr.Examples(
        examples=[
            [
                "requests ve httpx paketlerini karşılaştır."
            ],
            [
                (
                    "Python ile geliştirilen popüler LLM agent "
                    "GitHub repository'lerini bul."
                )
            ],
            [
                (
                    "Python'da TypeError: 'list' object is not "
                    "callable hatası alıyorum. Benzer Stack "
                    "Overflow sorularını bul ve açıkla."
                )
            ],
            [
                (
                    "FastAPI paketinin güncel PyPI bilgilerini "
                    "göster."
                )
            ],
            [
                (
                    "openai/openai-python GitHub repository'sini "
                    "incele."
                )
            ],
        ],
        inputs=user_input,
        label="Örnek Sorular",
    )

    submit_button.click(
        fn=process_user_message,
        inputs=[
            user_input,
        ],
        outputs=[
            thinking_output,
            plan_output,
            tool_results_output,
            final_answer_output,
        ],
    )

    user_input.submit(
        fn=process_user_message,
        inputs=[
            user_input,
        ],
        outputs=[
            thinking_output,
            plan_output,
            tool_results_output,
            final_answer_output,
        ],
    )

    clear_button.click(
        fn=clear_interface,
        inputs=[],
        outputs=[
            user_input,
            thinking_output,
            plan_output,
            tool_results_output,
            final_answer_output,
        ],
    )


if __name__ == "__main__":
    demo.queue(
        default_concurrency_limit=2,
    ).launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False,
        show_error=True,
        theme=gr.themes.Soft(),
        ssr_mode=False,
        pwa=False,
    )