Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Oct 11, 2023
1 parent 8208558 commit 9f1ba5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions faststream_gen/_code_generator/app_skeleton_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/App_Skeleton_Generator.ipynb.

# %% auto 0
__all__ = ['logger', 'CODE_CONTAINS_IMPLEMENTATION_ERROR', 'has_function_implementation', 'generate_app_skeleton']
__all__ = ['logger', 'CODE_CONTAINS_IMPLEMENTATION_ERROR', 'generate_app_skeleton']

# %% ../../nbs/App_Skeleton_Generator.ipynb 1
from typing import *
Expand Down Expand Up @@ -34,7 +34,7 @@
CODE_CONTAINS_IMPLEMENTATION_ERROR = "Error: The response contains code implementation. Rewrite the skeleton code without implementing the business logic for the functions. Ensure the new code has only google styled docstring describing the business logic step by step and raise NotImplementedError()"

# %% ../../nbs/App_Skeleton_Generator.ipynb 6
def has_function_implementation(
def _has_function_implementation(
node: Union[ast.AsyncFunctionDef, ast.FunctionDef]
) -> bool:
return len(node.body) == 2 and isinstance(node.body[-1], ast.Raise)
Expand All @@ -49,7 +49,7 @@ def _check_response_for_implementation(response: str) -> List[str]:
]
ret_val = (
[]
if all(has_function_implementation(node) for node in function_nodes)
if all(_has_function_implementation(node) for node in function_nodes)
else [CODE_CONTAINS_IMPLEMENTATION_ERROR]
)
return ret_val
Expand Down
6 changes: 3 additions & 3 deletions faststream_gen/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
'faststream_gen/_code_generator/app_skeleton_generator.py'),
'faststream_gen._code_generator.app_skeleton_generator._generate': ( 'app_skeleton_generator.html#_generate',
'faststream_gen/_code_generator/app_skeleton_generator.py'),
'faststream_gen._code_generator.app_skeleton_generator._has_function_implementation': ( 'app_skeleton_generator.html#_has_function_implementation',
'faststream_gen/_code_generator/app_skeleton_generator.py'),
'faststream_gen._code_generator.app_skeleton_generator._validate_response': ( 'app_skeleton_generator.html#_validate_response',
'faststream_gen/_code_generator/app_skeleton_generator.py'),
'faststream_gen._code_generator.app_skeleton_generator.generate_app_skeleton': ( 'app_skeleton_generator.html#generate_app_skeleton',
'faststream_gen/_code_generator/app_skeleton_generator.py'),
'faststream_gen._code_generator.app_skeleton_generator.has_function_implementation': ( 'app_skeleton_generator.html#has_function_implementation',
'faststream_gen/_code_generator/app_skeleton_generator.py')},
'faststream_gen/_code_generator/app_skeleton_generator.py')},
'faststream_gen._code_generator.chat': { 'faststream_gen._code_generator.chat.CustomAIChat': ( 'chat.html#customaichat',
'faststream_gen/_code_generator/chat.py'),
'faststream_gen._code_generator.chat.CustomAIChat.__call__': ( 'chat.html#customaichat.__call__',
Expand Down
8 changes: 4 additions & 4 deletions nbs/App_Skeleton_Generator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"# | export\n",
"\n",
"\n",
"def has_function_implementation(\n",
"def _has_function_implementation(\n",
" node: Union[ast.AsyncFunctionDef, ast.FunctionDef]\n",
") -> bool:\n",
" return len(node.body) == 2 and isinstance(node.body[-1], ast.Raise)\n",
Expand All @@ -130,7 +130,7 @@
" ]\n",
" ret_val = (\n",
" []\n",
" if all(has_function_implementation(node) for node in function_nodes)\n",
" if all(_has_function_implementation(node) for node in function_nodes)\n",
" else [CODE_CONTAINS_IMPLEMENTATION_ERROR]\n",
" )\n",
" return ret_val"
Expand Down Expand Up @@ -2308,7 +2308,7 @@
"[INFO] faststream_gen._code_generator.chat: Validation failed, trying again...Errors:\n",
"SyntaxError: invalid syntax (application.py, line 1)\n",
"[INFO] faststream_gen._code_generator.helper: Attempt 1 failed. Restarting step.\n",
" Generating FastStream app skeleton code (usually takes around 15 to 45 seconds)... [INFO] faststream_gen._code_generator.chat: \n",
" Generating FastStream app skeleton code (usually takes around 15 to 45 seconds)... [INFO] faststream_gen._code_generator.chat: \n",
"\n",
"Prompt to the model: \n",
"\n",
Expand Down Expand Up @@ -2612,7 +2612,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[INFO] faststream_gen._code_generator.chat: Validation failed, trying again...Errors:\n",
"⠴ Generating FastStream app skeleton code (usually takes around 15 to 45 seconds)... [INFO] faststream_gen._code_generator.chat: Validation failed, trying again...Errors:\n",
"SyntaxError: invalid syntax (application.py, line 1)\n",
"[INFO] faststream_gen._code_generator.helper: Attempt 2 failed. Restarting step.\n",
" ✘ Error: Failed to generate a valid application skeleton code. \n",
Expand Down

0 comments on commit 9f1ba5e

Please sign in to comment.