parent
d797909643
commit
f554b299ac
@ -0,0 +1,78 @@
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
from swarms.models import OpenAIChat
|
||||
from swarms.prompts.code_interpreter import CODE_INTERPRETER
|
||||
from swarms.structs import Agent
|
||||
|
||||
|
||||
class AgentInput(BaseModel):
|
||||
feature: str
|
||||
codebase: str
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Load the environment variables
|
||||
api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
# Initialize the language agent
|
||||
llm = OpenAIChat(
|
||||
model_name="gpt-4",
|
||||
openai_api_key=api_key,
|
||||
temperature=0.5,
|
||||
max_tokens=2000,
|
||||
)
|
||||
|
||||
# Product Manager Agent init
|
||||
product_manager_agent = Agent(
|
||||
llm=llm, max_loops=1, sop=CODE_INTERPRETER, autosave=True
|
||||
)
|
||||
|
||||
# Initialize the agent with the language agent
|
||||
feature_implementer_frontend = Agent(
|
||||
llm=llm, max_loops=1, sop=CODE_INTERPRETER, autosave=True
|
||||
)
|
||||
|
||||
# Create another agent for a different task
|
||||
feature_implementer_backend = Agent(
|
||||
llm=llm, max_loops=1, sop=CODE_INTERPRETER, autosave=True
|
||||
)
|
||||
|
||||
|
||||
# ##################### FastAPI #####################
|
||||
|
||||
|
||||
def feature_codebase_product_agentprompt(
|
||||
feature: str, codebase: str
|
||||
) -> str:
|
||||
prompt = (
|
||||
"Create an algorithmic pseudocode for an all-new feature:"
|
||||
f" {feature} based on this codebase: {codebase}"
|
||||
)
|
||||
return prompt
|
||||
|
||||
|
||||
# @app.post("/agent/")
|
||||
# async def run_feature_implementer_frontend(item: AgentInput):
|
||||
# agent1_out = feature_implementer_frontend.run(
|
||||
# f"Create the backend code for {item.feature} in markdown"
|
||||
# " based off of this algorithmic pseudocode:"
|
||||
# f" {product_manager_agent.run(feature_codebase_product_agentprompt(item.feature, item.codebase))} write"
|
||||
# f" the logic based on the following codebase: {item.codebase}"
|
||||
# )
|
||||
# return {"output": agent1_out}
|
||||
|
||||
def software_gpt(feature: str, codebase: str) -> str:
|
||||
agent1_out = feature_implementer_frontend.run(
|
||||
f"Create the backend code for {feature} in markdown"
|
||||
" based off of this algorithmic pseudocode:"
|
||||
f" {product_manager_agent.run(feature_codebase_product_agentprompt(feature, codebase))} write"
|
||||
f" the logic based on the following codebase: {codebase}"
|
||||
)
|
||||
print(agent1_out)
|
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define the base URL
|
||||
base_url="http://localhost:8000"
|
||||
|
||||
# Define the JSON payload
|
||||
payload='{"feature": "login system", "codebase": "existing codebase here"}'
|
||||
|
||||
# Send POST request
|
||||
echo "Sending request to /agent/ endpoint..."
|
||||
response=$(curl -s -X POST "$base_url/agent/" -H "Content-Type: application/json" -d "$payload")
|
||||
|
||||
echo "Response: $response"
|
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define the base URL
|
||||
base_url="http://localhost:8000"
|
||||
|
||||
# Define the JSON payload
|
||||
payload='{"feature": "login system", "codebase": "existing codebase here"}'
|
||||
|
||||
# Send POST request
|
||||
echo "Sending request to /agent/ endpoint..."
|
||||
response=$(curl -s -X POST "$base_url/agent/" -H "Content-Type: application/json" -d "$payload")
|
||||
|
||||
echo "Response: $response"
|
@ -1,15 +1,31 @@
|
||||
import re
|
||||
|
||||
# def extract_code_in_backticks_in_string(s: str) -> str:
|
||||
# """
|
||||
# Extracts code blocks from a markdown string.
|
||||
|
||||
def extract_code_in_backticks_in_string(message: str) -> str:
|
||||
# Args:
|
||||
# s (str): The markdown string to extract code from.
|
||||
|
||||
# Returns:
|
||||
# list: A list of tuples. Each tuple contains the language of the code block (if specified) and the code itself.
|
||||
# """
|
||||
# pattern = r"```([\w\+\#\-\.\s]*)\n(.*?)```"
|
||||
# matches = re.findall(pattern, s, re.DOTALL)
|
||||
# out = [(match[0], match[1].strip()) for match in matches]
|
||||
# print(out)
|
||||
|
||||
|
||||
def extract_code_in_backticks_in_string(s: str) -> str:
|
||||
"""
|
||||
To extract code from a string in markdown and return a string
|
||||
Extracts code blocks from a markdown string.
|
||||
|
||||
Args:
|
||||
s (str): The markdown string to extract code from.
|
||||
|
||||
Returns:
|
||||
str: A string containing all the code blocks.
|
||||
"""
|
||||
pattern = ( # Non-greedy match between six backticks
|
||||
r"`` ``(.*?)`` "
|
||||
)
|
||||
match = re.search(
|
||||
pattern, message, re.DOTALL
|
||||
) # re.DOTALL to match newline chars
|
||||
return match.group(1).strip() if match else None
|
||||
pattern = r"```([\w\+\#\-\.\s]*)(.*?)```"
|
||||
matches = re.findall(pattern, s, re.DOTALL)
|
||||
return "\n".join(match[1].strip() for match in matches)
|
||||
|
Loading…
Reference in new issue