Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove function calling #102

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ on:
pull_request:
branches:
- main
- debugging_ipc

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
# 3.10 - 04 Oct 2021
# 3.11 - 24 Oct 2022
python-version: ['3.10', '3.11']

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
Expand All @@ -41,4 +45,4 @@ jobs:
run: |
pip install pytest
cd pilot
PYTHONPATH=. pytest
PYTHONPATH=. pytest -m "not slow and not uses_tokens"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ https://github.com/Pythagora-io/gpt-pilot/assets/10895136/0495631b-511e-451b-93d
# 🔌 Requirements


- **Python**
- **Python >= 3.10**
Copy link
Member

Choose a reason for hiding this comment

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

why python 3.10? I am using 3.9.6 on my current macbook and it works fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into an (minor) issue with typing and figured that Python 3.10 came out in 2021 so it would not be likely to be used anymore.

utils/function_calling.py:5: in <module>
    JsonType = str | int | float | bool | None | list["JsonType"] | dict[str, "JsonType"]
E   TypeError: unsupported operand type(s) for |: 'type' and 'type'

- **PostgreSQL** (optional, projects default is SQLite)
- DB is needed for multiple reasons like continuing app development if you had to stop at any point or app crashed, going back to specific step so you can change some later steps in development, easier debugging, for future we will add functionality to update project (change some things in existing project or add new features to the project and so on)...

Expand Down
2 changes: 1 addition & 1 deletion pilot/const/function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def return_array_from_prompt(name_plural, name_singular, return_var_name):
"properties": {
f"{return_var_name}": {
"type": "array",
"description": f"List of {name_plural} that are created in a list.",
"description": f"List of {name_plural}.",
"items": {
"type": "string",
"description": f"{name_singular}"
Expand Down
2 changes: 1 addition & 1 deletion pilot/database/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from playhouse.shortcuts import model_to_dict
from peewee import *
from fabulous.color import yellow, red
from utils.style import yellow, red
from functools import reduce
import operator
import psycopg2
Expand Down
38 changes: 9 additions & 29 deletions pilot/helpers/AgentConvo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import re
import subprocess
import uuid
from fabulous.color import yellow, bold
from utils.style import yellow, yellow_bold

from database.database import get_saved_development_step, save_development_step, delete_all_subsequent_steps
from helpers.files import get_files_content
from const.common import IGNORE_FOLDERS
from helpers.exceptions.TokenLimitError import TokenLimitError
from utils.utils import array_of_objects_to_string
from utils.llm_connection import get_prompt, create_gpt_chat_completion
from utils.utils import get_sys_message, find_role_from_step, capitalize_first_word_with_underscores
from utils.function_calling import parse_agent_response
from utils.llm_connection import create_gpt_chat_completion
from utils.utils import array_of_objects_to_string, get_prompt, get_sys_message, capitalize_first_word_with_underscores
from logger.logger import logger
from prompts.prompts import ask_user
from const.llm import END_RESPONSE
Expand All @@ -23,7 +21,8 @@ class AgentConvo:
agent: An instance of the agent participating in the conversation.
"""
def __init__(self, agent):
self.messages = []
# [{'role': 'system'|'user'|'assistant', 'content': ''}, ...]
self.messages: list[dict] = []
self.branches = {}
self.log_to_user = True
self.agent = agent
Expand Down Expand Up @@ -83,7 +82,7 @@ def send_message(self, prompt_path=None, prompt_data=None, function_calls=None):
if response == {}:
raise Exception("OpenAI API error happened.")

response = self.postprocess_response(response, function_calls)
response = parse_agent_response(response, function_calls)

# TODO remove this once the database is set up properly
message_content = response[0] if type(response) == tuple else response
Expand Down Expand Up @@ -126,7 +125,7 @@ def continuous_conversation(self, prompt_path, prompt_data, function_calls=None)

# Continue conversation until GPT response equals END_RESPONSE
while response != END_RESPONSE:
print(yellow("Do you want to add anything else? If not, ") + yellow(bold('just press ENTER.')))
print(yellow("Do you want to add anything else? If not, ") + yellow_bold('just press ENTER.'))
user_message = ask_user(self.agent.project, response, False)

if user_message == "":
Expand Down Expand Up @@ -174,25 +173,6 @@ def replace_file_content(self, message, file_path, new_content):
def convo_length(self):
return len([msg for msg in self.messages if msg['role'] != 'system'])

def postprocess_response(self, response, function_calls):
"""
Post-processes the response from the agent.

Args:
response: The response from the agent.
function_calls: Optional function calls associated with the response.

Returns:
The post-processed response.
"""
if 'function_calls' in response and function_calls is not None:
if 'send_convo' in function_calls:
response['function_calls']['arguments']['convo'] = self
response = function_calls['functions'][response['function_calls']['name']](**response['function_calls']['arguments'])
elif 'text' in response:
response = response['text']

return response

def log_message(self, content):
"""
Expand All @@ -204,7 +184,7 @@ def log_message(self, content):
print_msg = capitalize_first_word_with_underscores(self.high_level_step)
if self.log_to_user:
if self.agent.project.checkpoints['last_development_step'] is not None:
print(yellow("\nDev step ") + yellow(bold(str(self.agent.project.checkpoints['last_development_step']))) + '\n', end='')
print(yellow("\nDev step ") + yellow_bold(str(self.agent.project.checkpoints['last_development_step'])) + '\n', end='')
print(f"\n{content}\n")
logger.info(f"{print_msg}: {content}\n")

Expand Down
12 changes: 6 additions & 6 deletions pilot/helpers/Project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from fabulous.color import bold, green, yellow, cyan, white
from utils.style import green_bold, yellow_bold, cyan, white_bold
from const.common import IGNORE_FOLDERS, STEPS
from database.database import delete_unconnected_steps_from, delete_all_app_development_data
from const.ipc import MESSAGE_TYPE
Expand Down Expand Up @@ -67,10 +67,10 @@ def __init__(self, args, name=None, description=None, user_stories=None, user_ta
# if development_plan is not None:
# self.development_plan = development_plan

print(green(bold('\n------------------ STARTING NEW PROJECT ----------------------')))
print(green_bold('\n------------------ STARTING NEW PROJECT ----------------------'))
print(f"If you wish to continue with this project in future run:")
print(green(bold(f'python main.py app_id={args["app_id"]}')))
print(green(bold('--------------------------------------------------------------\n')))
print(green_bold(f'python main.py app_id={args["app_id"]}'))
print(green_bold('--------------------------------------------------------------\n'))

def start(self):
"""
Expand Down Expand Up @@ -306,10 +306,10 @@ def ask_for_human_intervention(self, message, description=None, cbs={}, convo=No
reset_branch_id = convo.save_branch()

while answer != 'continue':
print(yellow(bold(message)))
print(yellow_bold(message))
if description is not None:
print('\n' + '-'*100 + '\n' +
white(bold(description)) +
white_bold(description) +
'\n' + '-'*100 + '\n')

answer = styled_text(
Expand Down
4 changes: 2 additions & 2 deletions pilot/helpers/agents/Architect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from utils.utils import step_already_finished
from helpers.Agent import Agent
import json
from fabulous.color import green, bold
from utils.style import green_bold
from const.function_calls import ARCHITECTURE

from utils.utils import should_execute_step, find_role_from_step, generate_app_data
Expand All @@ -28,7 +28,7 @@ def get_architecture(self):
return step['architecture']

# ARCHITECTURE
print(green(bold(f"Planning project architecture...\n")))
print(green_bold(f"Planning project architecture...\n"))
logger.info(f"Planning project architecture...")

self.convo_architecture = AgentConvo(self)
Expand Down
6 changes: 2 additions & 4 deletions pilot/helpers/agents/CodeMonkey.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from const.function_calls import GET_FILES, DEV_STEPS, IMPLEMENT_CHANGES, CODE_CHANGES
from database.models.files import File
from helpers.files import update_file
from helpers.AgentConvo import AgentConvo
from helpers.Agent import Agent


class CodeMonkey(Agent):
def __init__(self, project, developer):
super().__init__('code_monkey', project)
Expand All @@ -20,12 +19,11 @@ def implement_code_changes(self, convo, code_changes_description, step_index=0):
# "finished_steps": ', '.join(f"#{j}" for j in range(step_index))
# }, GET_FILES)


changes = convo.send_message('development/implement_changes.prompt', {
"step_description": code_changes_description,
"step_index": step_index,
"directory_tree": self.project.get_directory_tree(True),
"files": []#self.project.get_files(files_needed),
"files": [] # self.project.get_files(files_needed),
}, IMPLEMENT_CHANGES)
convo.remove_last_x_messages(1)

Expand Down
Loading