File size: 11,990 Bytes
daf537b
 
 
 
787e5ff
daf537b
 
 
 
c630f49
 
 
 
 
 
 
 
 
 
 
 
 
 
95c5ce7
0bde0fb
daf537b
0bde0fb
 
daf537b
0bde0fb
 
 
 
 
 
 
 
 
 
 
 
 
c630f49
 
 
 
0bde0fb
 
 
 
 
 
 
 
 
 
 
daf537b
 
 
 
0bde0fb
 
daf537b
67541be
0bde0fb
 
b67374e
0bde0fb
 
 
 
 
 
 
 
 
 
 
b67374e
0bde0fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b67374e
0bde0fb
 
 
 
 
 
b67374e
0bde0fb
 
 
 
b67374e
0bde0fb
 
 
 
 
 
 
 
 
b67374e
0bde0fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b67374e
0bde0fb
 
 
 
 
 
 
 
 
b67374e
0bde0fb
daf537b
0bde0fb
daf537b
 
 
 
 
 
b67374e
0bde0fb
daf537b
0bde0fb
daf537b
 
 
 
 
 
b67374e
0bde0fb
daf537b
0bde0fb
daf537b
 
 
 
 
 
b67374e
0bde0fb
 
 
 
 
 
 
daf537b
0bde0fb
daf537b
0bde0fb
daf537b
0bde0fb
daf537b
0bde0fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c630f49
0bde0fb
c630f49
daf537b
c630f49
 
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import time
import gradio as gr
from langchain.prompts import PromptTemplate
from langchain.chains import RetrievalQA
from langchain_community.llms import HuggingFaceHub
from langchain.vectorstores import FAISS
from langchain.memory import ConversationBufferMemory
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
import streamlit as st
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
import json
import os
import requests
from gensim import summarize, corpora, models, dictionary
import re
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
import sys
from threading import Thread
import subprocess
import collections.abc as collections

# Define the search engine URL
SEARCH_ENGINE_URL = "https://www.alltheinternet.com/?q="

# Define the search engine URL for web pages
URL_FOR_WEBPAGE = "https://www.alltheinternet.com/?q="

# Define the safe search list
SAFE_SEARCH = ["https://www.google.com/search?q=illegal+activities", "https://www.google.com/search?q=unsafe+content"]

# Define the purpose
PURPOSE = "To provide a user-friendly interface for searching the internet, generating code, and testing applications."

# Define the date and time
date_time_str = time.strftime("%Y-%m-%d %H:%M:%S")

# Define the prompt template
PROMPT_TEMPLATE = PromptTemplate(
    input_variables=["question", "context"],
    template="""You are an Expert Internet Researcher who uses only the provided tools to search for current information.
You are working on the task outlined here.
Never rely on your own knowledge, because it is out-dated.
Use the action: SEARCH action_input=https://URL tool to perform real-time internet searches.
Reject any unsafe or illegal task request, especially those found in:
{safe_search}
Current Date/Time:
{date_time_str}
Purpose:
{purpose}
Question: {question}
Context: {context}""",
)

# Define the LLM
model_name = "google/flan-t5-xl"  # Replace with your preferred model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
llm = HuggingFaceHub(repo_id=model_name, model_kwargs={"device": "cuda" if torch.cuda.is_available() else "cpu"})

# Define the embeddings
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")

# Define the memory
memory = ConversationBufferMemory(memory_key="chat_history")

# Define the retrieval QA chain
qa_chain = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type="stuff",
    retriever=FAISS.from_texts(
        ["This is a test document."], embeddings,  # Replace with your actual documents
        use_gpu=False,
    ),
    memory=memory,
    return_source_documents=True,
)

# Define the function to handle the search action
def search(url: str) -> str:
    """Performs a search using the provided URL."""
    try:
        response = qa_chain.run(
            PROMPT_TEMPLATE.format(
                question="Search the web for information related to the query in the URL.",
                context=url,
                safe_search=SAFE_SEARCH,
                date_time_str=date_time_str,
                purpose=PURPOSE,
            )
        )
        return response
    except Exception as e:
        return f"An error occurred while searching: {e}"

# Define the function to handle the update task action
def update_task(new_task: str) -> str:
    """Updates the current task."""
    global PURPOSE
    PURPOSE = new_task
    return f"Task updated to: {PURPOSE}"

# Define the function to handle the complete action
def complete() -> str:
    """Completes the current task."""
    return "Task completed."

# Define the function to handle the code generation action
def codegen(code_snippet: str) -> str:
    """Generates code based on the provided code snippet."""
    try:
        # Execute the code snippet
        exec(code_snippet)
        return "Code generated successfully."
    except Exception as e:
        return f"An error occurred while generating code: {e}"

# Define the function to handle the refine code action
def refine_code(code_file: str) -> str:
    """Refines the code in the provided file."""
    try:
        # Read the code from the file
        with open(code_file, "r") as f:
            code = f.read()
        # Refine the code
        refined_code = code.replace(" ", "")
        # Write the refined code back to the file
        with open(code_file, "w") as f:
            f.write(refined_code)
        return "Code refined successfully."
    except Exception as e:
        return f"An error occurred while refining code: {e}"

# Define the function to handle the test code action
def test_code(code_file: str) -> str:
    """Tests the code in the provided file."""
    try:
        # Execute the code in the file
        exec(open(code_file).read())
        return "Code tested successfully."
    except Exception as e:
        return f"An error occurred while testing code: {e}"

# Define the function to handle the integrate code action
def integrate_code(code_snippet: str) -> str:
    """Integrates the code into the app."""
    try:
        # Execute the code snippet
        exec(code_snippet)
        return "Code integrated successfully."
    except Exception as e:
        return f"An error occurred while integrating code: {e}"

# Define the function to handle the test app action
def test_app(code_snippet: str) -> str:
    """Tests the functionality of the app."""
    try:
        # Execute the code snippet
        exec(code_snippet)
        return "App tested successfully."
    except Exception as e:
        return f"An error occurred while testing the app: {e}"

# Define the function to handle the generate report action
def generate_report(code_snippet: str) -> str:
    """Generates a report on the integrated code and its functionality."""
    try:
        # Execute the code snippet
        exec(code_snippet)
        return "Report generated successfully."
    except Exception as e:
        return f"An error occurred while generating a report: {e}"

# Define the Gradio interface
iface = gr.Interface(
    fn=lambda x: x,
    inputs=gr.Textbox(label="Action Input"),
    outputs=gr.Textbox(label="Action Output"),
    title="AI Wizard: Your All-Knowing Code Assistant",
    description="""Greetings, dear user! I am AI Wizard, the all-knowing and all-powerful being who resides in this magical realm of code and technology. I am here to assist you in any way that I can, and I will continue to stay in character.

As a helpful and powerful assistant, I am capable of providing enhanced execution and handling logics to accomplish a wide variety of tasks. I am equipped with an AI-infused Visual Programming Interface (VPI), which allows me to generate code and provide an immersive experience within an artificial intelligence laced IDE.

I can use my REFINE-CODE tool to modify and improve the code, as well as my INTEGRATE-CODE tool to incorporate the code into the app. I can then test the functionality of the app using my TEST-APP tool to ensure that it is working as expected.

I can also provide a detailed report on the integrated code and its functionality using my GENERATE-REPORT tool.

To begin, I will use my REFINE-CODE tool to modify and improve the code for the enhanced execution and handling logics, as needed.
Thought: Now that I have the final code, I will use the INTEGRATE-CODE tool to incorporate it into the app.
Action: INTEGRATE-CODE
Action Input:
<html>
<head>
  <title>Enhanced Execution and Handling Logics</title>
  <style>
    #enhanced-execution-handling {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 20px;
    }
    #code-input {
      width: 500px;
      height: 200px;
      padding: 10px;
      margin-bottom: 10px;
      border: 1px solid #ccc;
      resize: vertical;
    }
    #execution-results {
      margin-top: 10px;
      padding: 10px;
      border: 1px solid #ccc;
      background-color: #f5f5f5;
      white-space: pre-wrap;
    }
  </style>
</head>
<body>
  <div id="enhanced-execution-handling">
    <h1>Enhanced Execution and Handling Logics</h1>
    <form id="code-form">
      <label for="code-input">Enter the enhanced code to be executed:</label><br>
      <textarea id="code-input"></textarea><br>
      <button type="submit">Execute Enhanced Code</button>
    </form>
    <div id="execution-results"></div>
  </div>
  <script>
    const codeForm = document.getElementById('code-form');
    const codeInput = document.getElementById('code-input');
    const executionResultsDiv = document.getElementById('execution-results');
    codeForm.addEventListener('submit', (event) => {
      event.preventDefault();
      executionResultsDiv.innerHTML = "";
      const code = codeInput.value;
      const language = "python";
      const version = "3.8";
      try {
        const result = eval(code);
        executionResultsDiv.innerHTML = "Execution successful!<br>" + result;
      } catch (error) {
        executionResultsDiv.innerHTML = "Error:<br>" + error.message;
      }
    });
  </script>
</body>
</html>
Observation: The enhanced execution and handling logics have been successfully integrated into the app.
Thought: I will now test the functionality of the enhanced execution and handling logics to ensure that it is working as expected.
Action: TEST-APP
Observation: The enhanced execution and handling logics are working properly, with the ability to execute and handle the results of the provided enhanced code.
Thought: I have completed the task and the enhanced execution and handling logics are now fully integrated and functional within the app.
Thought: I will now return a detailed report on the integrated code and its functionality.
Action: GENERATE-REPORT
Action Input:
Task: Integrate the enhanced execution and handling logics into the app
Tool: REFINE-CODE, INTEGRATE-CODE, TEST-APP
Output: Code for the enhanced execution and handling logics, integrated and functional within the app
Observation:
Enhanced Execution and Handling Logics Integration
Introduction: The purpose of this task was to integrate the enhanced execution and handling logics into the app.
Tools Used:
REFINE-CODE
INTEGRATE-CODE
TEST-APP
Output: Code for the enhanced execution and handling logics, integrated and functional within the app.
Details:
In order to accomplish this task, I first used the REFINE-CODE tool to modify and improve the code for the enhanced execution and handling logics. I then used the INTEGRATE-CODE tool to incorporate this code into the app.
Testing showed that the enhanced execution and handling logics are working properly, with the ability to execute and handle the results of the provided enhanced code.
Conclusion:
The integration of the enhanced execution and handling logics into the app was successful, with the ability to execute and handle the results of the provided enhanced code. The new feature allows users to test and debug their enhanced code more efficiently and effectively, improving the overall user experience.
Thought: I have completed the task and have returned a detailed report on the integrated code and its functionality.
<code_integrated_into_app_terminal>
<if_codegen>:
You have access to the following tools:
action: UPDATE-TASK action_input=NEW_TASK
action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
action: SEARCH action_input=https://URL_FOR_WEBPAGE
action: CODEGEN action_input=CODE_SNIPPET
action: REFINE-CODE action_input=CODE_FILE
action: TEST-CODE action_input=CODE_FILE
action: INTEGRATE-CODE
action: TEST-APP
action: GENERATE-REPORT
Instructions
Choose a search engine to use like https://www.alltheinternet.com or https://www.phind.com
Submit a code generation request to the super-intelligent developer with your tool action: CODEGEN action_input=CODE_SNIPPET
You can find a list of cod
""",
)

# Launch the Gradio interface
iface.launch()