Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
commit
Vasek Mlejnsky1443a637e91b
diff --git a/PromptExperiments/langchain_basics.ipynb b/PromptExperiments/langchain_basics.ipynbnew file mode 100644index 000000000..7f62aa8f1--- /dev/null+++ b/PromptExperiments/langchain_basics.ipynb@@ -0,0 +1,401 @@+{+ "cells": [+ {+ "cell_type": "code",+ "execution_count": 3,+ "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": 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": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# Custom agent from scratch"+ ]+ }+ ],+ "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/cf-worker-template/index.js b/api-service/cf-worker-template/index.jsindex 507b15d8d..2fd2f6313 100644--- a/api-service/cf-worker-template/index.js+++ b/api-service/cf-worker-template/index.js@@ -1,31 +1 @@-import { Router } from 'itty-router'--const router = Router()--async function handlepostRequest(req, env) {- // DO NOT USE `process.env` TO ACCES ENVIRONMENT VARIABLES. Instead, you access environment variables through the `env` parameter like this: `const myEnv = env.MY_ENV`.- // You have access to the following environment variables:- // const SLACK_BOT_ACCESS_TOKEN = `env.SLACK_BOT_ACCESS_TOKEN`--- // The incoming request content-type is application/json. Make sure to correctly retrieve it.- const requestBody = req.json()- const botAccessToken = env.SLACK_BOT_ACCESS_TOKEN;- const SlackREST = require('@sagi.io/workers-slack')- const SlackAPI = new SlackREST({ botAccessToken })-- const data = {- channel: 'general',- text: `User '${requestBody.email}' selected pricing '${requestBody.selectedPricing.type}' for $${requestBody.selectedPricing.cost}`- }- const result = await SlackAPI.chat.postMessage(data)-- return new Response('Ok', { status: 200 })-}--router.post('/', handlepostRequest)-router.get('*', () => new Response('Not found', { status: 404 }))--export default {- fetch: router.handle-}\ No newline at end of file+The Node.js dependencies 'express' and 'body-parser' have been successfully installed and the server correctly handles requests.\ No newline at end of filediff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.pyindex a3b992951..07444dfc8 100644--- a/api-service/codegen/codegen.py+++ b/api-service/codegen/codegen.py@@ -4,7 +4,7 @@ from langchain.llms.openai import OpenAIChat, OpenAI# from codegen.tools.documentation import ReadDocumentationfrom codegen.env import EnvVarfrom codegen.js_agent import create_js_agent-from codegen.prompt import PREFIX, SUFFIX+from codegen.prompt import PREFIX, SUFFIX, FORMAT_INSTRUCTIONSfrom codegen.tools.playground import create_playground_toolsfrom codegen.tools.javascript import JavascriptEvalToolfrom database import Database@@ -21,7 +21,9 @@ def generate_req_handler(request_body_blocks = [block for block in blocks if block.get("type") == "RequestBody"]- request_body_template = request_body_blocks[0]["prompt"] if len(request_body_blocks) > 0 else None+ request_body_template = (+ request_body_blocks[0]["prompt"] if len(request_body_blocks) > 0 else None+ )playground_tools, playground = create_playground_tools(envs=envs,route=route,@@ -29,6 +31,20 @@ def generate_req_handler(request_body_template=request_body_template,)+ steps = ""+ for idx, block in enumerate(blocks):+ if block.get("type") == "Basic":+ steps = steps + "\n" + "{}. ".format(idx + 1) + block["prompt"] + "\n"+ tool_names = ["InstallNPMDependencies", "RunJavaScriptCode"]+ prefix = PREFIX.format(+ method=method,+ tool_names=tool_names,+ steps=steps,+ request_body=request_body_template,+ )+ format_instructions = FORMAT_INSTRUCTIONS.format(+ tool_names=tool_names,+ )executor = create_js_agent(db=db,run_id=run_id,@@ -41,25 +57,30 @@ def generate_req_handler(*playground_tools,],verbose=True,+ prefix=prefix,+ format_instructions=format_instructions,)# Convert env vars to Javascript comments, each on its on line for each env var.- envs_str = ""- for env in envs:- envs_str += f'// const {env["key"]} = `env.{env["key"]}`\n'+ # envs_str = ""+ # for env in envs:+ # envs_str += f'// const {env["key"]} = `env.{env["key"]}`\n'- prompt = PREFIX.format(- method=method, envs=envs_str, request_body=request_body_template- )+ # prompt = PREFIX.format(+ # method=method, envs=envs_str, request_body=request_body_template+ # )- for idx, block in enumerate(blocks):- if block.get("type") == "Basic":- prompt = prompt + "\n" + "{}. ".format(idx + 1) + block["prompt"] + "\n"+ # for idx, block in enumerate(blocks):+ # if block.get("type") == "Basic":+ # prompt = prompt + "\n" + "{}. ".format(idx + 1) + block["prompt"] + "\n"- prompt = prompt + "\n" + SUFFIX.format(method=method)+ # prompt = prompt + "\n" + SUFFIX.format(method=method)- handler_code = executor.run(prompt).strip("`").strip()+ # handler_code = executor.run(prompt).strip("`").strip()+ handler_code = executor.run(f"Requirement:").strip("`").strip()+ print("CODE")+ print(handler_code)playground.close()- return prompt, handler_code+ return "", handler_codediff --git a/api-service/codegen/js_agent/agent.py b/api-service/codegen/js_agent/agent.pyindex 05e84308f..32f06ba73 100644--- a/api-service/codegen/js_agent/agent.py+++ b/api-service/codegen/js_agent/agent.py@@ -4,28 +4,68 @@ from langchain.agents.agent import AgentExecutorfrom langchain.callbacks.base import BaseCallbackManagerfrom langchain.llms.base import BaseLLMfrom langchain.agents.mrkl.base import ZeroShotAgent+from langchain.agents.chat.base import ChatAgentfrom langchain.chains.llm import LLMChainfrom langchain.callbacks.shared import SharedCallbackManagerfrom langchain.tools.base import BaseTool+from langchain.agents import initialize_agent+from langchain.chat_models import ChatOpenAI-from codegen.js_agent.prompt import PREFIX+# from codegen.js_agent.prompt import PREFIX+from codegen.prompt import PREFIX, SUFFIX, FORMAT_INSTRUCTIONSfrom codegen.js_agent.callbacks.log import LoggerCallbackHandlerfrom database import Database-# from js_agent.prompt import PREFIX-def create_js_agent(db: Database,run_id: str,llm: BaseLLM,tools: List[BaseTool],+ prefix: str,+ format_instructions: str,callback_manager: Optional[BaseCallbackManager] = None,verbose: bool = False,- prefix: str = PREFIX,**kwargs: Any,) -> AgentExecutor:"""Construct a javascript agent that generates code from an LLM and tool."""++ print(prefix)+ print(format_instructions)++ # prompt = ChatAgent.create_prompt(+ # # tools=tools,+ # prefix=prefix,+ # format_instructions=format_instructions,+ # # suffix="MY_CUSTOM_SUFFIX",+ # )++ # llm = ChatOpenAI(temperature=0)+ # # llm1 = OpenAI(temperature=0)+ # llm_chain = LLMChain(+ # llm=llm,+ # verbose=verbose,+ # # prompt=prompt,+ # # callback_manager=callback_manager,+ # )++ mrkl_agent = initialize_agent(+ tools,+ llm=llm,+ # llm_chain=llm_chain,+ agent="chat-zero-shot-react-description",+ verbose=verbose,+ # prompt=prompt,+ prefix=PREFIX,+ format_instructions=FORMAT_INSTRUCTIONS,+ )+ return mrkl_agent+ # return AgentExecutor.from_agent_and_tools(+ # agent=mrkl_agent,+ # tools=tools,+ # verbose=verbose,+ # )+prompt = ZeroShotAgent.create_prompt(tools=tools, prefix=prefix)llm_chain = LLMChain(llm=llm,diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.pyindex ab73a427f..aa1fcc31d 100644--- a/api-service/codegen/prompt.py+++ b/api-service/codegen/prompt.py@@ -34,7 +34,7 @@ async function handle{method}Request(req, env) {{{envs}// The incoming request content-type is application/json. Make sure to correctly retrieve it.- const requestBody = req.json()+ const requestBody = await req.json()// TODO}}@@ -88,3 +88,112 @@ The code must perform the following logic:# """SUFFIX = ""++################## NEW FOR CHAT GPT++PREFIX = """You are a senior JavaScript developer and you have access to the following tools: {tool_names}.+You've been tasked to build the `handle{method}Request` function that handles incoming {method} requests for your REST API.+The incoming {method} request payload ALWAYS looks like this:+```+{{{{+ {request_body}+}}}}+```++The function `handle{method}Request` MUST do the following logic: {steps}"""++FORMAT_INSTRUCTIONS = """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}+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:+Requirement: the required logic from the code+Thought: you should always think about what to do+Action:+```+$JSON_BLOB+```+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 to the original input question"""++##########################++PREFIX = """You are a senior JavaScript developer and you have access to the following tools: {tool_names}.+You're buildiing a serverless API with Cloudflare Workers using the `itty-router` package. You've been tasked to build the `handlepostRequest` function that handles incoming POST requests for your REST API.+The incoming POST request payload ALWAYS looks like this:+```+{{+ email: string,+ userID: string,+ pricingType: string,+ pricingCost: number+}}+```++The code MUST do the following logic:+1. Use the following starting template. The part that must be completed is marked with the TODO comment+```+import {{ Router }} from 'itty-router'++const router = Router()++async function handlepostRequest(req, env) {{+ // DO NOT USE `process.env` TO ACCES ENVIRONMENT VARIABLES. Instead, you access environment variables through the `env` parameter like this: `const myEnv = env.MY_ENV`.+ // You have access to the following environment variables:+ // - env.SLACK_BOT_ACCESS_TOKEN++ // The incoming request content-type is application/json. Make sure to correctly retrieve it.+ const requestBody = await req.json()+ // TODO+}}++router.post('/', handlepostRequest)+router.get('*', () => new Response('Not found', {{ status: 404 }}))++export default {{+ fetch: router.handle+}}+```++2. Use the `@sagi.io/workers-slack` package to send a message to channel 'general' in the format: `User '<email>' selected pricing '<type>' for $<cost>''` based on the incoming request data. This is an example of how to send a Slack message using the `@sagi.io/workers-slack` message to channel 'general':+```+const botAccessToken = env.SLACK_BOT_ACCESS_TOKEN;+const SlackREST = require('@sagi.io/workers-slack')+const SlackAPI = new SlackREST({{ botAccessToken }})++const data = {{ channel: 'general', text: 'hello world' }}+const result = await SlackAPI.chat.postMessage(data)+```++3. Respond back with the message "Ok" if there wasn't any error+"""++FORMAT_INSTRUCTIONS = """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}+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:+Requirement: the required logic from the code+Thought: you should always think about what to do+Action:+```+$JSON_BLOB+```+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 to the original input question"""diff --git a/api-service/poetry.lock b/api-service/poetry.lockindex 8851a65dd..68229d3b4 100644--- a/api-service/poetry.lock+++ b/api-service/poetry.lock@@ -1,4 +1,4 @@-# This file is automatically @generated by Poetry and should not be changed by hand.+# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand.[[package]]name = "aenum"@@ -1006,14 +1006,14 @@ testing = ["flake8 (<5)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-chec[[package]]name = "langchain"-version = "0.0.107"+version = "0.0.108"description = "Building applications with LLMs through composability"category = "main"optional = falsepython-versions = ">=3.8.1,<4.0"files = [- {file = "langchain-0.0.107-py3-none-any.whl", hash = "sha256:161bfb185d7146d32f5483a134bfe353d98f1b383b637b31e45f234736500d5c"},- {file = "langchain-0.0.107.tar.gz", hash = "sha256:a6d2c7236c7cf0c2d437cf0bde0626d9b5849589680132fc271b53d01bd7df3b"},+ {file = "langchain-0.0.108-py3-none-any.whl", hash = "sha256:c653f2eb50cee09727fc54885b941303b9abbe58af80dcc8311b61ba60f6652b"},+ {file = "langchain-0.0.108.tar.gz", hash = "sha256:e0a80bfc4a5eb3805105bc13914a8a9832dde7da8183ba6c2ff31436e040af87"},][package.dependencies]@@ -1789,7 +1789,7 @@ files = [][package.dependencies]-greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"}+greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and platform_machine == \"aarch64\" or python_version >= \"3\" and platform_machine == \"ppc64le\" or python_version >= \"3\" and platform_machine == \"x86_64\" or python_version >= \"3\" and platform_machine == \"amd64\" or python_version >= \"3\" and platform_machine == \"AMD64\" or python_version >= \"3\" and platform_machine == \"win32\" or python_version >= \"3\" and platform_machine == \"WIN32\""}[package.extras]aiomysql = ["aiomysql", "greenlet (!=0.4.17)"]@@ -2230,4 +2230,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more[metadata]lock-version = "2.0"python-versions = ">=3.8.1,<4.0"-content-hash = "174f6946500c7a069df72512ff21df84850c20ecc7ea7a7f4826ce7dc369d209"+content-hash = "20c6b9ebdce19be71b4bf1f8588ae00815915a731f935860e3839432f43dfe2d"diff --git a/api-service/pyproject.toml b/api-service/pyproject.tomlindex 11d6afe99..129b3c483 100644--- a/api-service/pyproject.toml+++ b/api-service/pyproject.toml@@ -9,7 +9,7 @@ python = ">=3.8.1,<4.0"flask = "^2.2.3"gunicorn = "^20.1.0"openai = "^0.27.0"-langchain = "^0.0.107"+langchain = "^0.0.108"supabase = "^1.0.1"flask-cors = "^3.0.10"python-dateutil = "^2.8.2"diff --git a/package.json b/package.jsonindex 73ae633e3..ea06b67f1 100644--- a/package.json+++ b/package.json@@ -3,7 +3,7 @@"version": "0.1.0","private": true,"scripts": {- "dev": "npx concurrently \"next dev\" \"yarn start:api\" \"yarn start:playground\"",+ "dev": "npx concurrently -p none \"next dev\" \"yarn start:api\" \"yarn start:playground\"","dev:api-service": "npx concurrently \"yarn start:api\" \"yarn start:playground\"","build": "next build","start:api": "cd api-service && PYTHONUNBUFFERED=1 poetry run flask --app app.py --debug run",