Skip to content

Commit

Permalink
Merge pull request #585 from reworkd/code
Browse files Browse the repository at this point in the history
💻 Add code writer tool
  • Loading branch information
awtkns committed May 25, 2023
2 parents 26362c7 + 5e3b175 commit 781e835
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
3 changes: 3 additions & 0 deletions next/src/components/AutonomousAgent.ts
Expand Up @@ -284,6 +284,9 @@ class AutonomousAgent {
if (analysis.action == "image") {
message = `🎨 Generating an image with prompt: "${analysis.arg}"...`;
}
if (analysis.action == "code") {
message = `💻 Writing code...`;
}

this.sendMessage({
type: MESSAGE_TYPE_SYSTEM,
Expand Down
7 changes: 0 additions & 7 deletions next/src/components/ChatWindow.tsx
Expand Up @@ -105,13 +105,6 @@ const ChatWindow = ({
onScroll={handleScroll}
id={messageListId}
>
<div className="mx-4 rounded-full border border-red-500 bg-red-900/30 p-2 px-4 text-red-100">
🚨{" "}
<a className="link" href="https://status.openai.com/">
OpenAI
</a>{" "}
is currently experiencing issues. As a result, AgentGPT may not be available. 🚨
</div>
{agent !== null && agentMode === PAUSE_MODE && isAgentPaused && (
<FaPause className="animation-hide absolute left-1/2 top-1/2 text-lg md:text-3xl" />
)}
Expand Down
4 changes: 2 additions & 2 deletions next/src/services/agent-service.ts
Expand Up @@ -3,7 +3,7 @@ import {
createModel,
createTasksPrompt,
executeTaskPrompt,
startGoalPrompt
startGoalPrompt,
} from "../utils/prompts";
import type { ModelSettings } from "../utils/types";
import { env } from "../env/client.mjs";
Expand Down Expand Up @@ -47,7 +47,7 @@ async function analyzeTaskAgent(modelSettings: ModelSettings, goal: string, task

export type Analysis = {
reasoning: string;
action: "reason" | "search" | "wikipedia" | "image";
action: "reason" | "search" | "wikipedia" | "image" | "code";
arg: string;
};

Expand Down
19 changes: 19 additions & 0 deletions platform/reworkd_platform/web/api/agent/prompts.py
Expand Up @@ -40,6 +40,25 @@
input_variables=["goal", "task", "tools_overview"],
)

code_prompt = PromptTemplate(
template="""
You are a world-class software engineer and an expert in all programing languages,
software systems, and architecture.
For reference, your high level goal is
{goal}
Answer in the "{language}" language but write code in English.
Provide no information about who you are and focus on writing code.
Ensure code is bug and error free and explain complex concepts through comments
Respond in well-formatted markdown. Ensure code blocks are used for code sections.
Write code to accomplish the following:
{task}
""",
input_variables=["goal", "language", "task"],
)

execute_task_prompt = PromptTemplate(
template="""Answer in the "{language}" language. Given
the following overall objective `{goal}` and the following sub-task, `{task}`.
Expand Down
22 changes: 22 additions & 0 deletions platform/reworkd_platform/web/api/agent/tools/code.py
@@ -0,0 +1,22 @@
from langchain import LLMChain

from reworkd_platform.web.api.agent.model_settings import ModelSettings, create_model
from reworkd_platform.web.api.agent.prompts import code_prompt
from reworkd_platform.web.api.agent.tools.tool import Tool


class Code(Tool):
description = (
"Useful for writing, reviewing, and refactoring code. Can also fix bugs, "
"and explain programming concepts."
)
public_description = "Write and review code."

def __init__(self, model_settings: ModelSettings):
super().__init__(model_settings)

async def call(self, goal: str, task: str, input_str: str) -> str:
llm = create_model(self.model_settings)
chain = LLMChain(llm=llm, prompt=code_prompt)

return await chain.arun({"goal": goal, "language": "English", "task": task})
2 changes: 2 additions & 0 deletions platform/reworkd_platform/web/api/agent/tools/tools.py
@@ -1,5 +1,6 @@
from typing import Type, List

from reworkd_platform.web.api.agent.tools.code import Code
from reworkd_platform.web.api.agent.tools.conclude import Conclude
from reworkd_platform.web.api.agent.tools.image import Image
from reworkd_platform.web.api.agent.tools.reason import Reason
Expand All @@ -20,6 +21,7 @@ def get_external_tools() -> List[Type[Tool]]:
# Wikipedia, # Requires an async version
Image,
Search,
Code,
]


Expand Down
12 changes: 11 additions & 1 deletion platform/reworkd_platform/web/api/agent/views.py
Expand Up @@ -87,7 +87,17 @@ class CompletionResponse(BaseModel):

@router.post("/execute")
async def execute_tasks(
req_body: AgentRequestBody,
req_body: AgentRequestBody = Body(
example={
"goal": "Perform tasks accurately",
"task": "Write code to make a platformer",
"analysis": {
"reasoning": "I like to write code.",
"action": "code",
"arg": ""
},
}
),
) -> CompletionResponse:
try:
response = await get_agent_service().execute_task_agent(
Expand Down

1 comment on commit 781e835

@vercel
Copy link

@vercel vercel bot commented on 781e835 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-git-main-reworkd.vercel.app
docs-reworkd.vercel.app
docs.reworkd.ai

Please sign in to comment.