Skip to content

Commit

Permalink
forge.llm.providers.schema + code_flow_executor lint-fix and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Jun 8, 2024
1 parent 6dd0975 commit e264bf7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
6 changes: 3 additions & 3 deletions forge/forge/components/code_flow_executor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .code_flow_executor import (
CodeFlowExecutionComponent
)
from .code_flow_executor import CodeFlowExecutionComponent

__all__ = ["CodeFlowExecutionComponent"]
48 changes: 26 additions & 22 deletions forge/forge/llm/providers/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,38 +144,42 @@ def fmt_line(self) -> str:
)
return f"{self.name}: {self.description}. Params: ({params})"

def fmt_header(self, impl="pass", force_async=False) -> str:
def fmt_function_stub(self, impl: str = "pass") -> str:
"""
Formats and returns the function header as a string with types and descriptions.
Formats and returns a function stub as a string with types and descriptions.
Returns:
str: The formatted function header.
"""
def indent(content: str, spaces: int = 4):
return " " * spaces + content.replace("\n", "\n" + " " * spaces)
from forge.llm.prompting.utils import indent

params = ", ".join(
f"{name}: {p.python_type}{f'= {str(p.default)}' if p.default else ' = None' if not p.required else ''}"
f"{name}: {p.python_type}"
+ (
f" = {str(p.default)}"
if p.default
else " = None"
if not p.required
else ""
)
for name, p in self.parameters.items()
)
func = "async def" if self.is_async or force_async else "def"
return_str = f" -> {self.return_type}" if self.return_type else ""
return f"{func} {self.name}({params}){return_str}:\n" + indent(
(
'"""\n'
f"{self.description}\n\n"
"Params:\n"
+ indent(
"\n".join(
f"{name}: {param.description}"
for name, param in self.parameters.items()
if param.description
)
_def = "async def" if self.is_async else "def"
_return = f" -> {self.return_type}" if self.return_type else ""
return f"{_def} {self.name}({params}){_return}:\n" + indent(
'"""\n'
f"{self.description}\n\n"
"Params:\n"
+ indent(
"\n".join(
f"{name}: {param.description}"
for name, param in self.parameters.items()
if param.description
)
+ "\n"
'"""\n'
f"{impl}"
),
)
+ "\n"
'"""\n'
f"{impl}"
)

def validate_call(
Expand Down

0 comments on commit e264bf7

Please sign in to comment.