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

[AGPT-432] Provide Request & Response checking on Function Generation #64

Conversation

majdyz
Copy link
Contributor

@majdyz majdyz commented Feb 29, 2024

Changes:

Testing:

  • Fix bug on ./run benchmark due to the latest API change.
  • Add global option to mock ai_block LLM output + Add function generation tests (gen_test.py, testing without LLM call).
  • Add 1 simple seeded application (TicTacToe game).

Code:

  • Add strict checking on argument and return types for function generation.
  • Store created FunctionArgs & FunctionReturns for each function.
  • Add global assignments produced by LLM as part of the generated main code.
  • Fix the first function for the API generation prompt (provide function signature).

Out of scope:

  • Auto-detecting a new class type

deployment_id = deploy_data["deployment"]["id"]
deployment_file_name = deploy_data["deployment"]["file_name"]
deployment_id = deploy_data["id"]
deployment_file_name = deploy_data["file_name"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API is changed, this to make the benchmark work again.

@@ -44,6 +44,10 @@ class config:
arbitrary_types_allowed = True


# This can be used for synchronous testing without making an actual API call
MOCK_RESPONSE = ""
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'm adding this for testing without LLM call

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in discord, I think its a clear design to mock the openai class

data=model,
include={"FunctionArgs": True, "FunctionReturn": True},
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now we create the Function.Definition before recursing.

This simplifies a lot of stuff:

  • Develop AIBlock only do update, create_item and update_item can be merged.
  • Created the objectfields for args and return types before generation, so we can validate inside the AIblock

Copy link

linear bot commented Feb 29, 2024

AGPT-432

function_name (str): The name of the function to create.
function_id (str): The id of the function to create. If not provided, a new root-function will be created.
function_template (str): The docstring/template of the function to create.
function (Function): The function to develop.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's easier to group this to a single object

self.imports = []
self.pydantic_classes = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are tracking all classes, there is is_pydantic in self.objects

isinstance(node, ast.AnnAssign) or
isinstance(node, ast.AugAssign)
) and node.col_offset == 0:
self.globals.append(ast.unparse(node))
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'm tracking globals for now so that at least the generated code is working.

@@ -226,94 +250,6 @@ def validate(
async def create_item(
self, ids: Identifiers, validated_response: ValidatedResponse
) -> Function:
"""This is just a temporary that doesnt have a database model"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

merging this with update_item

function_code: str
function_template: str = None

def __generate_function_template(f) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be used only for the first function, we let llm output template for the rest to be used.

@@ -1,7 +1,7 @@
import ast

import pytest
from numpy import VisibleDeprecationWarning
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Boilerplate changes to make the test work

schema.prisma Show resolved Hide resolved
@majdyz majdyz requested a review from Swiftyos February 29, 2024 10:42
@majdyz majdyz enabled auto-merge (squash) March 1, 2024 05:04
description="Identifier for the user who is creating the invoice.",
),
Parameter(
name="items",
param_type="Array<InvoiceItemInput>",
param_type="List[InvoiceItemInput]",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

list with no capital?

@@ -2229,22 +2229,22 @@ def invoice_payment_tracking() -> ApplicationRequirements:
params=[
Parameter(
name="invoices",
param_type="Array<InvoiceSummary>",
param_type="List[InvoiceSummary]",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor

@Swiftyos Swiftyos left a comment

Choose a reason for hiding this comment

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

Nice work!

@@ -95,6 +96,8 @@ async def fetch_deliverable(session, user_id, app_id):
return deploy_data
except Exception as e:
click.echo(f"Error fetching deliverable: {e}")
print("Problematic URL: ", url)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use click.echo or logger instead of print here

@@ -44,6 +44,10 @@ class config:
arbitrary_types_allowed = True


# This can be used for synchronous testing without making an actual API call
MOCK_RESPONSE = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in discord, I think its a clear design to mock the openai class

…unction-generation-is-applying-strict-check-on-args-and
@Swiftyos Swiftyos disabled auto-merge March 1, 2024 13:47
@Swiftyos Swiftyos merged commit e95f544 into main Mar 1, 2024
1 check passed
@Swiftyos Swiftyos deleted the zamilmajdy/agpt-432-function-generation-is-applying-strict-check-on-args-and branch March 1, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants