Skip to content

Commit

Permalink
add function call description to the standard components
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFerLo committed Oct 30, 2023
1 parent 40f56cc commit c43e922
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions synthetic/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .base import Component
from .load_components import load_components
from .function_description import FunctionDescriptions
from .funation_call_description import FunctionCallDescription
9 changes: 9 additions & 0 deletions synthetic/components/funation_call_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Any
from .base import Component

class FunctionCallDescription (Component) :
name = "FunctionCallDescription"
def format(self, **kwargs: Any) -> str:
signature = kwargs["signature"]

return signature
2 changes: 1 addition & 1 deletion synthetic/components/function_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class FunctionDescriptions (Component) :
name = "FunctionDescriptions"

def format(self, **kwargs: Any) -> str:
functions: List[Function] = kwargs.get("functions")
functions: List[Function] = kwargs["functions"]

return "\n".join([ f"-{f.name}: {f.description}" for f in functions ])
4 changes: 3 additions & 1 deletion synthetic/components/load_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

from .base import Component
from .function_description import FunctionDescriptions
from .funation_call_description import FunctionCallDescription

import synthetic
import synthetic.re as re
from synthetic.errors import LoadComponentsError

_BASE_COMPONENTS = {
"FunctionDescriptions": FunctionDescriptions
"FunctionDescriptions": FunctionDescriptions,
"FunctionCallDescription": FunctionCallDescription
}

def load_components (string: Optional[str] = None, names: Optional[List[str]] = None) -> List[Type[Component]] :
Expand Down
11 changes: 10 additions & 1 deletion test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ def hello (string: str) -> str :
self.assertIsInstance(inst, synthetic.components.FunctionDescriptions)

output = inst.format(functions = [evaluate, hello])
self.assertEqual(output, f"-{evaluate.name}: {evaluate.description}\n-{hello.name}: {hello.description}")
self.assertEqual(output, f"-{evaluate.name}: {evaluate.description}\n-{hello.name}: {hello.description}")

def test_default_function_call_description_component_works_as_expected (self) :
inst = synthetic.components.FunctionCallDescription()
self.assertIsInstance(inst, synthetic.components.FunctionCallDescription)

output = inst.format(signature = "[{name}({input})->{output}]")
self.assertEqual(output, "[{name}({input})->{output}]")

self.assertListEqual(synthetic.load_components(names=["FunctionCallDescription"]), [synthetic.components.FunctionCallDescription])

0 comments on commit c43e922

Please sign in to comment.