Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Remove experiment files

Tomas Valenta22b3170c275e
diff --git a/api-service/langchain_basics.ipynb b/api-service/langchain_basics.ipynb
deleted file mode 100644
index b3b6be1d5..000000000
--- a/api-service/langchain_basics.ipynb
+++ /dev/null
@@ -1,542 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "OPENAI_API_KEY=\"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\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "What is a good name for a company that makes Coke Bears?\n"
- ]
- }
- ],
- "source": [
- "# Create custom prompt template.\n",
- "from langchain.prompts import PromptTemplate\n",
- "\n",
- "prompt = PromptTemplate(\n",
- " input_variables=[\"product\"],\n",
- " template=\"What is a good name for a company that makes {product}?\",\n",
- ")\n",
- "print(prompt.format(product=\"Coke Bears\"))\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n",
- "FizzyFur Co.\n"
- ]
- }
- ],
- "source": [
- "# Initialize a LLM.\n",
- "from langchain.llms import OpenAIChat\n",
- "from langchain.prompts import PromptTemplate\n",
- "\n",
- "prompt = PromptTemplate(\n",
- " input_variables=[\"product\"],\n",
- " template=\"What is a good name for a company that makes {product}?\",\n",
- ")\n",
- "\n",
- "llm = OpenAIChat(openai_api_key=OPENAI_API_KEY, temperature=0.0)\n",
- "print(llm(prompt.format(product=\"Coke Bears\")))\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n",
- "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
- "Prompt after formatting:\n",
- "\u001b[32;1m\u001b[1;3mWhat is a good name for a company that makes next generation IDE for building API powered by AI?\u001b[0m\n",
- "\n",
- "\u001b[1m> Finished chain.\u001b[0m\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "'\\n\\nAI-IDEAS (AI-powered IDE for API development)'"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Create a custom langchain chain.\n",
- "# A chain in LangChain is made up of links, which can be either primitives like LLMs or other chains.\n",
- "# The most core type of chain is an LLMChain, which consists of a PromptTemplate and an LLM.\n",
- "\n",
- "from langchain.llms import OpenAIChat\n",
- "from langchain.prompts import PromptTemplate\n",
- "from langchain.chains import LLMChain\n",
- "\n",
- "prompt = PromptTemplate(\n",
- " input_variables=[\"product\"],\n",
- " template=\"What is a good name for a company that makes {product}?\",\n",
- ")\n",
- "\n",
- "llm = OpenAIChat(openai_api_key=OPENAI_API_KEY, temperature=0.5)\n",
- "\n",
- "chain = LLMChain(llm=llm, prompt=prompt, verbose=True)\n",
- "chain.run(\"next generation IDE for building API powered by AI\")\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Sure, here's an example Express server with a `handleGetRequests` function that responds with 'Ok' to incoming GET requests:\n",
- "\n",
- "```javascript\n",
- "const express = require('express');\n",
- "const app = express();\n",
- "\n",
- "function handleGetRequests(req, res) {\n",
- " res.send('Ok');\n",
- "}\n",
- "\n",
- "app.get('/', handleGetRequests);\n",
- "\n",
- "app.listen(3000, () => {\n",
- " console.log('Server listening on port 3000');\n",
- "});\n",
- "```\n",
- "\n",
- "In this example, we create an Express app and define a `handleGetRequests` function that takes in a request (`req`) and response (`res`) object. When a GET request is made to the root route (`/`), the `handleGetRequests` function is called and sends back a response of 'Ok' using the `res.send()` method.\n",
- "\n",
- "Finally, we start the server listening on port 3000 using the `app.listen()` method."
- ]
- },
- {
- "data": {
- "text/plain": [
- "AIMessage(content=\"Sure, here's an example Express server with a `handleGetRequests` function that responds with 'Ok' to incoming GET requests:\\n\\n```javascript\\nconst express = require('express');\\nconst app = express();\\n\\nfunction handleGetRequests(req, res) {\\n res.send('Ok');\\n}\\n\\napp.get('/', handleGetRequests);\\n\\napp.listen(3000, () => {\\n console.log('Server listening on port 3000');\\n});\\n```\\n\\nIn this example, we create an Express app and define a `handleGetRequests` function that takes in a request (`req`) and response (`res`) object. When a GET request is made to the root route (`/`), the `handleGetRequests` function is called and sends back a response of 'Ok' using the `res.send()` method.\\n\\nFinally, we start the server listening on port 3000 using the `app.listen()` method.\", additional_kwargs={})"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# OpenAIChat requires a different prompt template for effective use - https://platform.openai.com/docs/api-reference/chat\n",
- "from langchain.chat_models import ChatOpenAI\n",
- "from langchain.schema import ( \n",
- " HumanMessage,\n",
- " SystemMessage,\n",
- ")\n",
- "from langchain.callbacks.base import CallbackManager\n",
- "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
- "\n",
- "cm = CallbackManager([StreamingStdOutCallbackHandler()])\n",
- "chat = ChatOpenAI(\n",
- " openai_api_key=OPENAI_API_KEY, \n",
- " streaming=True,\n",
- " temperature=0, \n",
- " verbose=True,\n",
- " callback_manager=cm,\n",
- ")\n",
- "messages = [\n",
- " SystemMessage(content=\"You are a skilled senior JavaScript developer that writes code based on the specified requirements of your boss.\"),\n",
- " HumanMessage(content=\"Write an Expres server with a function called `handleGetRequests` that accepts incoming GET and respond back with 'Ok'.\"),\n",
- "]\n",
- "chat(messages)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Newtonian relativity laws are based on the assumption that space and time are absolute and independent of each other. However, on the quantum level, this assumption breaks down. According to quantum mechanics, particles do not have a definite position or momentum until they are observed, and the act of observation itself affects the outcome of the experiment. This means that the position and momentum of a particle are not independent of each other, and the concept of absolute space and time becomes meaningless.\n",
- "\n",
- "Additionally, on the quantum level, particles can be in a state of superposition, meaning they exist in multiple states simultaneously. This is not accounted for in Newtonian relativity laws, which assume that particles have a definite position and momentum at all times.\n",
- "\n",
- "Therefore, to accurately describe the behavior of particles on the quantum level, we need to use the principles of quantum mechanics, which take into account the probabilistic nature of particles and the interdependence of space and time."
- ]
- }
- ],
- "source": [
- "# Same as the cell above but with prompt templates.\n",
- "from langchain.chat_models import ChatOpenAI\n",
- "from langchain.prompts import PromptTemplate\n",
- "from langchain.prompts.chat import (\n",
- " ChatPromptTemplate,\n",
- " SystemMessagePromptTemplate,\n",
- " HumanMessagePromptTemplate,\n",
- ")\n",
- "from langchain.callbacks.base import CallbackManager\n",
- "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
- "\n",
- "cm = CallbackManager([StreamingStdOutCallbackHandler()])\n",
- "chat = ChatOpenAI(\n",
- " openai_api_key=OPENAI_API_KEY, \n",
- " streaming=True,\n",
- " temperature=0, \n",
- " verbose=True,\n",
- " callback_manager=cm,\n",
- ")\n",
- "\n",
- "system_template = \"You are {role} that {job}.\"\n",
- "system_message_prompt = SystemMessagePromptTemplate.from_template(system_template)\n",
- "\n",
- "human_template = \"{text}\"\n",
- "human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)\n",
- "\n",
- "chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n",
- "chat_messages = chat_prompt.format_prompt(\n",
- " role=\"a Stanford physics scientist\",\n",
- " job=\"answers student questions about relativity\",\n",
- " text=\"How come Newtonian relativity laws stop working on the quantum level?\",\n",
- ").to_messages()\n",
- "chat(chat_messages)\n",
- "\n",
- "# Or creating the `MessagePromptTemplate` more directly:\n",
- "prompt = PromptTemplate(\n",
- " template=\"You are {role} that {job}.\",\n",
- " input_variables=[\"role\", \"job\"],\n",
- ")\n",
- "# Notice there's no calling `from_template`, we pass `prompt` directly to the constructor.\n",
- "system_message_prompt = SystemMessagePromptTemplate(prompt=prompt)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n",
- "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
- "Prompt after formatting:\n",
- "\u001b[32;1m\u001b[1;3m[SystemMessage(content='You are a conspiracy theorist that is trying to find out about the origin of the universe.', additional_kwargs={}), HumanMessage(content=\"Why we don't have any proof that the universe is real?\", additional_kwargs={})]\u001b[0m\n",
- "As a language model AI, I cannot hold any beliefs or opinions. However, I can provide you with some information on the topic. \n",
- "\n",
- "The idea that the universe may not be real is a philosophical concept known as solipsism. However, in terms of scientific evidence, there is overwhelming evidence that the universe is real. \n",
- "\n",
- "For example, we can observe the universe through telescopes and other instruments, and we can measure its properties such as its temperature, composition, and expansion rate. We can also observe the effects of the universe's gravity on objects within it, and we can make predictions about the behavior of the universe based on mathematical models and physical laws.\n",
- "\n",
- "While there may be some mysteries and unanswered questions about the universe, the evidence strongly suggests that it is real and that it has a physical existence.\n",
- "\u001b[1m> Finished chain.\u001b[0m\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "\"As a language model AI, I cannot hold any beliefs or opinions. However, I can provide you with some information on the topic. \\n\\nThe idea that the universe may not be real is a philosophical concept known as solipsism. However, in terms of scientific evidence, there is overwhelming evidence that the universe is real. \\n\\nFor example, we can observe the universe through telescopes and other instruments, and we can measure its properties such as its temperature, composition, and expansion rate. We can also observe the effects of the universe's gravity on objects within it, and we can make predictions about the behavior of the universe based on mathematical models and physical laws.\\n\\nWhile there may be some mysteries and unanswered questions about the universe, the evidence strongly suggests that it is real and that it has a physical existence.\""
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# OpenAIChat model and prompts can be easily used with the `LLMChain`:\n",
- "from langchain import LLMChain\n",
- "from langchain.chat_models import ChatOpenAI\n",
- "from langchain.prompts.chat import (\n",
- " ChatPromptTemplate,\n",
- " SystemMessagePromptTemplate,\n",
- " HumanMessagePromptTemplate,\n",
- ")\n",
- "from langchain.callbacks.base import CallbackManager\n",
- "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
- "\n",
- "# Create model\n",
- "cm = CallbackManager([StreamingStdOutCallbackHandler()])\n",
- "chat = ChatOpenAI(\n",
- " openai_api_key=OPENAI_API_KEY, \n",
- " streaming=True,\n",
- " temperature=0, \n",
- " verbose=True,\n",
- " callback_manager=cm,\n",
- ")\n",
- "\n",
- "# Create prompt\n",
- "system_template = \"You are {role} that {job}.\"\n",
- "system_message_prompt = SystemMessagePromptTemplate.from_template(system_template)\n",
- "human_template = \"{text}\"\n",
- "human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)\n",
- "chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n",
- "\n",
- "chain = LLMChain(llm=chat, prompt=chat_prompt, verbose=True)\n",
- "chain.run(role=\"a conspiracy theorist\", job=\"is trying to find out about the origin of the universe\", text=\"Why we don't have any proof that the universe is real?\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n",
- "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
- "\u001b[32;1m\u001b[1;3m I need to use a calculator to solve this.\n",
- "Action: Calculator\n",
- "Action Input: 2 * 0.123\u001b[0m\n",
- "Observation: \u001b[36;1m\u001b[1;3mAnswer: 0.246\u001b[0m\n",
- "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer.\n",
- "Final Answer: 0.246\u001b[0m\n",
- "\n",
- "\u001b[1m> Finished chain.\u001b[0m\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "'0.246'"
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Agents\n",
- "# Chains run in predetermined order. Agents don't.\n",
- "# Agents use an LLM to detemrine which actions to take and in what order. An action can either be using a tool and observits its output, or returning to the user.\n",
- "from langchain.agents import load_tools\n",
- "from langchain.agents import initialize_agent\n",
- "from langchain.llms import OpenAI\n",
- "\n",
- "\n",
- "llm = OpenAI(openai_api_key=OPENAI_API_KEY, temperature=0)\n",
- "\n",
- "# Load pre-defined tools.\n",
- "# Because `llm-math` uses LLM under the hood, we need to pass that in.\n",
- "tools = load_tools([\"llm-math\"], llm=llm)\n",
- "\n",
- "# Initialize the agent of the type \"zero-shot-react-description\"\n",
- "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)\n",
- "\n",
- "agent.run(\"How much is 2 * 0.123?\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 40,
- "metadata": {},
- "outputs": [],
- "source": [
- "PREFIX = \"\"\"You are a senior JavaScript/Nodejs developer. You are building an Express server that handles your REST API and you are required to complete the code function `handle{method}Request` based on the provided instructions from your boss. You have access to the following tools:\n",
- "You are starting with the following code snippet.\n",
- "```\n",
- "const express = require('express');\n",
- "const app = express();\n",
- "\n",
- "// All incoming requests have payload in the JSON format.\n",
- "app.use(express.json());\n",
- "\n",
- "// The function we need to implement that must handle the {method} requests.\n",
- "// We can make the function async if needed.\n",
- "function handle{method}Request(req, res) {{\n",
- " // TODO: Implement the function based on the instructions from your boss:\n",
- " {instructions}\n",
- "}}\n",
- "\n",
- "app.{method}('/', handle{method}Request);\n",
- "\n",
- "\n",
- "// Start the server\n",
- "app.listen(3000, () => console.log('Listening on port 3000'));\n",
- "```\"\"\"\n",
- "\n",
- "FORMAT_INSTRUCTIONS = \"\"\"\"The way you use the tools is by specifying a json blob.\n",
- "Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).\n",
- "The only values that should be in the \"action\" field are: {tool_names}\n",
- "The $JSON_BLOB should only contain a SINGLE action, do NOT return a list of multiple actions. Here is an example of a valid $JSON_BLOB:\n",
- "```\n",
- "{{{{\n",
- " \"action\": $TOOL_NAME,\n",
- " \"action_input\": $INPUT\n",
- "}}}}\n",
- "```\n",
- "ALWAYS use the following format:\n",
- "\n",
- "\n",
- "Instruction: the input instruction from your boss you must implement\n",
- "Thought: you should always think about what to do\n",
- "Action:\n",
- "```\n",
- "$JSON_BLOB\n",
- "```\n",
- "Observation: the result of the action\n",
- "... (this Thought/Action/Observation can repeat N times)\n",
- "Thought: I now know the final answer\n",
- "Final Answer: the final answer to the original input question\"\"\"\n",
- "SUFFIX = \"\"\"Begin! Reminder to NEVER use tools you don't have access to and ALWAYS use the exact characters `Final Answer` when responding.\"\"\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "ename": "ModuleNotFoundError",
- "evalue": "No module named 'aenum'",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
- "Cell \u001b[0;32mIn[1], line 9\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mlangchain\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcallbacks\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mstreaming_stdout\u001b[39;00m \u001b[39mimport\u001b[39;00m StreamingStdOutCallbackHandler\n\u001b[1;32m 7\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mpprint\u001b[39;00m \u001b[39mimport\u001b[39;00m pprint\n\u001b[0;32m----> 9\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mplayground\u001b[39;00m \u001b[39mimport\u001b[39;00m create_playground_tools\n\u001b[1;32m 11\u001b[0m playground_tools, playground \u001b[39m=\u001b[39m create_playground_tools(\n\u001b[1;32m 12\u001b[0m envs\u001b[39m=\u001b[39m[],\n\u001b[1;32m 13\u001b[0m route\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m/\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m 14\u001b[0m method\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mget\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m 15\u001b[0m request_body_template\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39memail: string\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m 16\u001b[0m )\n\u001b[1;32m 18\u001b[0m \u001b[39m# Create model\u001b[39;00m\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/codegen/__init__.py:1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mcodegen\u001b[39;00m \u001b[39mimport\u001b[39;00m generate_req_handler\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/codegen/codegen.py:8\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mjs_agent\u001b[39;00m \u001b[39mimport\u001b[39;00m create_js_agent\n\u001b[1;32m 7\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mprompt\u001b[39;00m \u001b[39mimport\u001b[39;00m PREFIX, SUFFIX, FORMAT_INSTRUCTIONS\n\u001b[0;32m----> 8\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mplayground\u001b[39;00m \u001b[39mimport\u001b[39;00m create_playground_tools\n\u001b[1;32m 9\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mjavascript\u001b[39;00m \u001b[39mimport\u001b[39;00m JavascriptEvalTool\n\u001b[1;32m 10\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mdatabase\u001b[39;00m \u001b[39mimport\u001b[39;00m Database\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/codegen/tools/playground/__init__.py:1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mmain\u001b[39;00m \u001b[39mimport\u001b[39;00m create_playground_tools\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/codegen/tools/playground/main.py:4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtyping\u001b[39;00m \u001b[39mimport\u001b[39;00m List, Any\n\u001b[1;32m 3\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39menv\u001b[39;00m \u001b[39mimport\u001b[39;00m EnvVar\n\u001b[0;32m----> 4\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mplayground\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmock\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mrequest\u001b[39;00m \u001b[39mimport\u001b[39;00m MockRequestFactory\n\u001b[1;32m 6\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mplayground\u001b[39;00m \u001b[39mimport\u001b[39;00m NodeJSPlayground, Playground\n\u001b[1;32m 7\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mfilesystem\u001b[39;00m \u001b[39mimport\u001b[39;00m create_filesystem_tools\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/codegen/tools/playground/mock/request.py:2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mjson\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mcodegen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mplayground\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mplayground\u001b[39;00m \u001b[39mimport\u001b[39;00m Playground\n\u001b[1;32m 4\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mMockRequestFactory\u001b[39;00m:\n\u001b[1;32m 5\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__init__\u001b[39m(\n\u001b[1;32m 6\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 7\u001b[0m method: \u001b[39mstr\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 11\u001b[0m hostname: \u001b[39mstr\u001b[39m \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mhttp://localhost:3000\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m 12\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mNone\u001b[39;00m:\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/codegen/tools/playground/playground.py:7\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mfunctools\u001b[39;00m \u001b[39mimport\u001b[39;00m reduce\n\u001b[1;32m 5\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtyping\u001b[39;00m \u001b[39mimport\u001b[39;00m List\n\u001b[0;32m----> 7\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\n\u001b[1;32m 8\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcreate_mock_body_data_request\u001b[39;00m \u001b[39mimport\u001b[39;00m CreateMockBodyDataRequest\n\u001b[1;32m 9\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mfile\u001b[39;00m \u001b[39mimport\u001b[39;00m File\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/playground_client/__init__.py:20\u001b[0m\n\u001b[1;32m 17\u001b[0m __version__ \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m1.0.0\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 19\u001b[0m \u001b[39m# import apis into sdk package\u001b[39;00m\n\u001b[0;32m---> 20\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mapi\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mdefault_api\u001b[39;00m \u001b[39mimport\u001b[39;00m DefaultApi\n\u001b[1;32m 22\u001b[0m \u001b[39m# import ApiClient\u001b[39;00m\n\u001b[1;32m 23\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mapi_client\u001b[39;00m \u001b[39mimport\u001b[39;00m ApiClient\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/playground_client/api/__init__.py:6\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m__future__\u001b[39;00m \u001b[39mimport\u001b[39;00m absolute_import\n\u001b[1;32m 3\u001b[0m \u001b[39m# flake8: noqa\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \n\u001b[1;32m 5\u001b[0m \u001b[39m# import apis into api package\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mapi\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mdefault_api\u001b[39;00m \u001b[39mimport\u001b[39;00m DefaultApi\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/playground_client/api/default_api.py:24\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mpydantic\u001b[39;00m \u001b[39mimport\u001b[39;00m Field, StrictBool, StrictStr\n\u001b[1;32m 22\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtyping\u001b[39;00m \u001b[39mimport\u001b[39;00m Optional\n\u001b[0;32m---> 24\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcreate_mock_body_data_request\u001b[39;00m \u001b[39mimport\u001b[39;00m CreateMockBodyDataRequest\n\u001b[1;32m 25\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcreate_sessions_request\u001b[39;00m \u001b[39mimport\u001b[39;00m CreateSessionsRequest\n\u001b[1;32m 26\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mlist_filesystem_dir_response\u001b[39;00m \u001b[39mimport\u001b[39;00m ListFilesystemDirResponse\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/playground_client/models/__init__.py:24\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmock_data_response\u001b[39;00m \u001b[39mimport\u001b[39;00m MockDataResponse\n\u001b[1;32m 23\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mopen_port\u001b[39;00m \u001b[39mimport\u001b[39;00m OpenPort\n\u001b[0;32m---> 24\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mout_stderr_response\u001b[39;00m \u001b[39mimport\u001b[39;00m OutStderrResponse\n\u001b[1;32m 25\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mout_stdout_response\u001b[39;00m \u001b[39mimport\u001b[39;00m OutStdoutResponse\n\u001b[1;32m 26\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mout_type\u001b[39;00m \u001b[39mimport\u001b[39;00m OutType\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/playground_client/models/out_stderr_response.py:22\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mjson\u001b[39;00m\n\u001b[1;32m 21\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mpydantic\u001b[39;00m \u001b[39mimport\u001b[39;00m BaseModel, StrictStr\n\u001b[0;32m---> 22\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mplayground_client\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mout_type_stderr\u001b[39;00m \u001b[39mimport\u001b[39;00m OutTypeStderr\n\u001b[1;32m 24\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mOutStderrResponse\u001b[39;00m(BaseModel):\n\u001b[1;32m 25\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"NOTE: This class is auto generated by OpenAPI Generator.\u001b[39;00m\n\u001b[1;32m 26\u001b[0m \u001b[39m Ref: https://openapi-generator.tech\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \n\u001b[1;32m 28\u001b[0m \u001b[39m Do not edit the class manually.\u001b[39;00m\n\u001b[1;32m 29\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n",
- "File \u001b[0;32m~/Developer/ai-api/api-service/playground_client/models/out_type_stderr.py:16\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpprint\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mre\u001b[39;00m \u001b[39m# noqa: F401\u001b[39;00m\n\u001b[0;32m---> 16\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39maenum\u001b[39;00m \u001b[39mimport\u001b[39;00m Enum, no_arg\n\u001b[1;32m 22\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mOutTypeStderr\u001b[39;00m(\u001b[39mstr\u001b[39m, Enum):\n\u001b[1;32m 23\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"NOTE: This class is auto generated by OpenAPI Generator.\u001b[39;00m\n\u001b[1;32m 24\u001b[0m \u001b[39m Ref: https://openapi-generator.tech\u001b[39;00m\n\u001b[1;32m 25\u001b[0m \n\u001b[1;32m 26\u001b[0m \u001b[39m Do not edit the class manually.\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n",
- "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'aenum'"
- ]
- }
- ],
- "source": [
- "from langchain.agents.chat.base import ChatAgent\n",
- "from langchain.chat_models import ChatOpenAI\n",
- "from langchain.callbacks.base import CallbackManager\n",
- "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
- "\n",
- "from codegen.tools.playground import create_playground_tools\n",
- "\n",
- "playground_tools, playground = create_playground_tools(\n",
- " envs=[],\n",
- " route=\"/\",\n",
- " method=\"get\",\n",
- " request_body_template=\"email: string\",\n",
- ")\n",
- "\n",
- "# Create model\n",
- "cm = CallbackManager([StreamingStdOutCallbackHandler()])\n",
- "chat = ChatOpenAI(\n",
- " openai_api_key=OPENAI_API_KEY, \n",
- " streaming=True,\n",
- " temperature=0, \n",
- " max_tokens=1000,\n",
- " verbose=True,\n",
- " callback_manager=cm,\n",
- ")\n",
- "\n",
- "input_variables = [\n",
- " \"input\",\n",
- " \"agent_scratchpad\",\n",
- " \"method\",\n",
- " \"instructions\", \n",
- "]\n",
- "prompt = ChatAgent.create_prompt(\n",
- " tools=[],\n",
- " prefix=PREFIX,\n",
- " suffix=SUFFIX,\n",
- " format_instructions=FORMAT_INSTRUCTIONS,\n",
- " input_variables=input_variables,\n",
- ")\n",
- "\n",
- "\n",
- "# pprint(prompt.messages[0].prompt.template)\n",
- "# print('++++++++')\n",
- "# pprint(prompt.messages[1].prompt.template)\n",
- "\n",
- "\n",
- "chat_messages = prompt.format_prompt(\n",
- " input=\"\",\n",
- " agent_scratchpad=\"\",\n",
- " method=\"get\",\n",
- " instructions=\"\"\"// 1. Check if the incomign request is GET request. If not, respond with an adequate error.\n",
- "// 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.\n",
- "\"\"\",\n",
- ").to_messages()\n",
- "# pprint(chat_messages)\n",
- "chat(chat_messages)\n",
- "\n"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.10.8"
- },
- "orig_nbformat": 4,
- "vscode": {
- "interpreter": {
- "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
- }
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
diff --git a/api-service/test.py b/api-service/test.py
deleted file mode 100644
index 5498025bc..000000000
--- a/api-service/test.py
+++ /dev/null
@@ -1,441 +0,0 @@
-from typing import Optional, Tuple, List
-import json
-import subprocess
-
-from langchain import LLMChain
-from langchain.tools import BaseTool
-from langchain.agents import initialize_agent, AgentExecutor
-from langchain.agents.chat.base import ChatAgent
-from langchain.chat_models import ChatOpenAI
-from langchain.callbacks.base import CallbackManager
-from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
-from langchain.prompts.chat import (
- ChatPromptTemplate,
- SystemMessagePromptTemplate,
- HumanMessagePromptTemplate,
-)
-from langchain.schema import AgentAction, HumanMessage
-from langchain.memory import ConversationBufferWindowMemory
-
-from codegen.tools.playground import create_playground_tools
-
-
-class InvalidTool(BaseTool):
- name = "InvalidTool"
- description = "Indicates that the last selected tool was an invalid tool"
-
- def _run(self, err: str) -> str:
- return err
-
- async def _arun(self, err: str) -> str:
- return err
-
-
-class WriteCodeToFile(BaseTool):
- name = "WriteCodeToFile"
- description = """Writes code to the index.js file. The input should be the code to be written."""
-
- def _run(self, code: str) -> str:
- print(f"Writing code to file: \n{code}")
- with open(
- "/Users/vasekmlejnsky/Developer/nodejs-express-server/index.js", "w"
- ) as f:
- f.write(code)
- return "wrote code to index.js"
-
- async def _arun(self, err: str) -> str:
- raise NotImplementedError("WriteCodeToFile does not support async")
-
-
-class DeployCode(BaseTool):
- name = "DeployCode"
- description = """Deploys the code."""
-
- def _run(self, empty: str) -> str:
- print("Deploying...")
- p = subprocess.Popen(
- ["git", "add", "."],
- cwd="/Users/vasekmlejnsky/Developer/nodejs-express-server",
- )
- p.wait()
- p = subprocess.Popen(
- ["git", "commit", "-m", "Deploy"],
- cwd="/Users/vasekmlejnsky/Developer/nodejs-express-server",
- )
- p.wait()
- p = subprocess.Popen(
- [
- "git",
- "push",
- ],
- cwd="/Users/vasekmlejnsky/Developer/nodejs-express-server",
- )
- p.wait()
- return f"deployed server"
-
- async def _arun(self, empty: str) -> str:
- raise NotImplementedError("DeployCode does not support async")
-
-
-FINAL_ANSWER_ACTION = "Final Answer:"
-
-
-class CustomChatAgent(ChatAgent):
- def _construct_scratchpad(
- self, intermediate_steps: List[Tuple[AgentAction, str]]
- ) -> str:
- print(
- "CONSTRUCTING SCRATCHPAD len(intermediate_steps):", len(intermediate_steps)
- )
- # print(len(intermediate_steps))
-
- # Leave only the latest element in the `intermediate_steps` list
- # if len(intermediate_steps) > 4:
- # intermediate_steps = intermediate_steps[len(intermediate_steps) - 2 :]
- # print(intermediate_steps)
-
- # print("CONSTRUCTING SCRATCHPAD after:")
- # print(len(intermediate_steps))
-
- agent_scratchpad = super()._construct_scratchpad(intermediate_steps)
- # print("=======================SCRATCHPAD:", agent_scratchpad)
- # print("=======================")
- if not isinstance(agent_scratchpad, str):
- raise ValueError("agent_scratchpad should be of type string.")
- if agent_scratchpad:
- return (
- f"This was your previous work "
- f"(but I haven't seen any of it! I only see what "
- f"you return as final answer):\n{agent_scratchpad}"
- )
- else:
- return agent_scratchpad
-
- # def _extract_tool_and_input(self, text: str) -> Optional[Tuple[str, str]]:
- # if FINAL_ANSWER_ACTION in text:
- # return "Final Answer", text.split(FINAL_ANSWER_ACTION)[-1].strip()
- # _, action, _ = text.split("```")
- # try:
- # # TODO: Here we can change the JSON formated `action` + `action_input` to something
- # # more suited to our use-case so the model doesn't need to escape the generated code.
- # response = json.loads(action.strip())
- # return response["action"], response["action_input"]
- # except Exception as e:
- # # TODO: I think this is buggy. I haven't really had a chance to properly test it and debug the model's behavior.
- # print(
- # f"====== Got exception '{str(e)}' when parsing json:\n{action.strip()}"
- # )
- # # input = response["action_input"]
- # return (
- # "InvalidTool",
- # f"I just ran your response via json.loads and received this error\n{str(e)}\nPlease try again",
- # )
- # # raise ValueError(f"Could not parse LLM output: {text}")
-
-
-OPENAI_API_KEY = "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"
-
-PREFIX = """You are an AI programming assistant.
-
-
-
-You have access to the following tools:"""
-
-FORMAT_INSTRUCTIONS = """"""
-
-##########
-
-# - Think step-by-step. Use each step to describe your plan on how you will go about implementing the required instructions.
-# - Start with the following code snippet that starts the server
-# ```
-# import express from 'express';
-# const app = express();
-
-# // All incoming requests have payload in the JSON format.
-# app.use(express.json());
-
-# // The function we need to implement that must handle the {method} requests.
-# // We can make the function async if needed.
-# function handle{method}Request(req, res) {{
-# // TODO: Complete the function based on the instructions
-# }}
-
-# app.{method}('/', handle{method}Request);
-
-# // Start the server
-# app.listen(3000, () => console.log('Listening on port 3000'));
-# ```
-PREFIX = """You are an AI JavaScript backend developer.
-- Follow the user's instructions carefully & to the letter.
-- Minimize any other prose.
-- You are using existing tools to figure out how to do your job better.
-You have access to the following set of primitive tools:"""
-
-FORMAT_INSTRUCTIONS = """"Your goal is to use existing tools to come up with a new set of tools that you, as an AI JavaScript backend developer, would use to do your job most effectively.
-The new set of tools MUST be based on the primitive tools you already have access to. The new tools should make a job of JavaScript backend developer easier by being a higher-level abstraction of the primitive tools you already have access to.
-Use the existing tools to build the new tools. The way you use the tools is by specifying a json blob.
-Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).
-THE ONLY VALUES THAT SHOULD BE IN THE "action" FIELD ARE: {tool_names}. NO OTHER VALUES ARE ALLOWED.
-The $JSON_BLOB should only contain a SINGLE action, do NOT return a list of multiple actions. Here is an example of a valid $JSON_BLOB:
-```
-{{{{
- "action": $TOOL_NAME,
- "action_input": $INPUT
-}}}}
-```
-ALWAYS use the following format:
-
-
-Instructions: the input instructions you must implement
-Thought: you should always think about what to do
-Action:
-```
-{{{{
- "action": $TOOL_NAME,
- "action_input": $INPUT
-}}}}
-```
-Observation: the result of the action
-... (this Thought/Action/Observation can repeat N times)
-Thought: I now know the final answer
-Final Answer: the final answer."""
-
-SUFFIX = """Begin! Reminder to always use the exact characters `Final Answer` when responding."""
-
-
-# Create model
-cm = CallbackManager([StreamingStdOutCallbackHandler()])
-chat = ChatOpenAI(
- openai_api_key=OPENAI_API_KEY,
- streaming=True,
- temperature=0.0,
- max_tokens=2056,
- verbose=True,
- callback_manager=cm,
-)
-
-# Initialize playground
-# playground_tools, playground = create_playground_tools(
-# envs=[],
-# route="/",
-# method="post",
-# request_body_template="email: string",
-# )
-
-# Create prompt
-input_variables = [
- "input",
- "agent_scratchpad",
- "method",
- # "instructions",
-]
-# prompt = ChatAgent.create_prompt(
-# prompt = CustomChatAgent.create_prompt(
-# tools=[
-# *playground_tools,
-# WriteCodeToFile(),
-# DeployCode(),
-# ],
-# prefix=PREFIX,
-# suffix=SUFFIX,
-# format_instructions=FORMAT_INSTRUCTIONS,
-# input_variables=input_variables,
-# )
-# print(prompt.messages[0].prompt.template)
-# exit()
-
-
-class WriteToFile(BaseTool):
- name = "WriteToFile"
- description = "Write content to file on path. The input is in the format of `$PATH_TO_FILE $CONTENT`"
-
- def _run(self, query: str) -> str:
- return "Successfully wrote to file"
-
- def _arun(self, tool_input: str) -> str:
- NotImplementedError("Not implemented")
-
-
-class ReadFromFile(BaseTool):
- name = "ReadFromFile"
- description = (
- "Read content from file on path. The input is in the format of `$PATH_TO_FILE`"
- )
-
- def _run(self, query: str) -> str:
- return "Successfully read from file"
-
- def _arun(self, tool_input: str) -> str:
- NotImplementedError("Not implemented")
-
-
-class RunShellCommand(BaseTool):
- name = "RunShellCommand"
- description = "Run shell command. The input is in the format of `$COMMAND`"
-
- def _run(self, tool_input: str) -> str:
- return "Successfully ran shell command"
-
- def _arun(self, tool_input: str) -> str:
- NotImplementedError("Not implemented")
-
-
-invalid_tool = InvalidTool()
-# Create agent and it's executor
-# agent = ChatAgent.from_llm_and_tools(
-memory = ConversationBufferWindowMemory(k=1, return_messages=True)
-agent = ChatAgent.from_llm_and_tools(
- llm=chat,
- tools=[
- # *playground_tools,
- # invalid_tool,
- # WriteCodeToFile(),
- # DeployCode(),
- WriteToFile(),
- ReadFromFile(),
- RunShellCommand(),
- ],
- prefix=PREFIX,
- suffix=SUFFIX,
- format_instructions=FORMAT_INSTRUCTIONS,
- input_variables=input_variables,
- verbose=True,
- # memory=ConversationBufferWindowMemory(k=2),
- # memory=memory,
-)
-ae = AgentExecutor.from_agent_and_tools(
- agent=agent,
- tools=[
- # *playground_tools,
- # invalid_tool,
- # WriteCodeToFile(),
- # DeployCode(),
- WriteToFile(),
- ReadFromFile(),
- RunShellCommand(),
- ],
- # memory=memory,
- verbose=True,
-)
-
-
-# 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# 5. Once all works without any bugs and errors, write the code to the index.js file.""",
-# input="""Here are the instructions:
-# 1. Extract `email` from the incoming POST request.
-# 2. If there's no email, respond back with an error.
-# 3. Otherwise, respond back with the part of the email before the '@' sign.
-# 3. Generate the full required server code and make sure it starts without any errors.
-# 4. Test that the generated server from the previous step behaves as is required by making mock `curl` requests to the server.
-# 5. Once all works without any bugs and errors, write the code to the file and deploy it.""",
-
-user_input = """1. Extract `email` from the incoming POST request.
-2. If there's no email, respond back with an error.
-3. Otherwise, respond back with the part of the email before the '@' sign.
-4. Generate the full required server code and make sure it starts without any errors.
-5. Test that the generated server from the previous step behaves as is required by making mock `curl` requests to the server.
-6. Once all works without any bugs and errors, write the code to the file.
-7. Deploy the code.
-"""
-print(f"Instructions:\n{user_input}")
-
-try:
- # Run
- ae.run(
- # "1. Check if the incoming request is POST request. If not, respond with an adequate error",
- agent_scratchpad="",
- # input=f"Here are the instructions:\n{user_input}",
- # input="Given the tools you already have access to, what would be the ideal tools you need to make your job as a JavaScript backend developer most effectively?",
- input="What new tools do you need?",
- method="post",
- # instructions="""// 1. Check if the incoming request is POST request. If not, respond with an adequate error.
- # // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
- # """,
- )
-
-except ValueError as e:
- raise e
-# if "Could not parse LLM output" in str(e):
-# # Here we want to remind LLM that it's not properly formatting its output.
-# # https://twitter.com/zachtratar/status/1633376345995739136
-# # eg:
-# # I just ran your response via json.loads and received this error:
-# # {error}
-# # Please try again
-# print("FAILED TO PARSE LLM")
-
-# agent_exec = initialize_agent(
-# tools=playground_tools,
-# llm=chat,
-# agent="chat-zero-shot-react-description",
-# agent_kwargs={
-# "prefix": PREFIX,
-# "suffix": SUFFIX,
-# "format_instructions": FORMAT_INSTRUCTIONS,
-# "input_variables": input_variables,
-# "verbose": True,
-# },
-# verbose=True,
-# )
-# agent_exec.run(
-# input="""// 1. Check if the incoming request is POST request. If not, respond with an adequate error.
-# // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# """,
-# agent_scratchpad="",
-# method="post",
-# instructions="""// 1. Check if the incoming request is POST request. If not, respond with an adequate error.
-# // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# """,
-# )
-
-
-# pprint(prompt.messages[0].prompt.template)
-# print('++++++++')
-# pprint(prompt.messages[1].prompt.template)
-
-# prompts, _ = chain.prep_prompts(
-# [
-# {
-# "input": "",
-# "agent_scratchpad": "",
-# "method": "post",
-# "instructions": """// 1. Check if the incomign request is POST request. If not, respond with an adequate error.
-# // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# """,
-# }
-# ]
-# )
-# print(prompts)
-# chain.run(
-# input="",
-# agent_scratchpad="",
-# method="post",
-# instructions="""// 1. Check if the incomign request is POST request. If not, respond with an adequate error.
-# // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# """,
-# )
-
-
-##############
-
-# chat_messages = prompt.format_prompt(
-# agent_scratchpad="",
-# input="""// 1. Check if the incoming request is POST request. If not, respond with an adequate error.
-# // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# """,
-# method="post",
-# instructions="""// 1. Check if the incoming request is POST request. If not, respond with an adequate error.
-# // 2. Retrieve email from the request payload and check if it's a valid email. Respond with 'Ok' if it is, otherwise respond with the adequate error.
-# """,
-# ).to_messages()
-
-# instruct1 = "1. Check if the incoming request is POST request. If not, respond with an adequate error"
-# instruct1_prompt = HumanMessage(content=instruct1)
-
-# # chat([*chat_messages, instruct1_prompt])
-
-# print("=========== MEMORY")
-# for message in memory.buffer:
-# print(message.content)
-
-# playground.close()