blob: e6423827c1a19b281506c4ca388bfdfd40e77b4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Callable, Iterable, TypeVar
if TYPE_CHECKING:
from autogpt.models.command import Command
from autogpt.core.resource.model_providers import CompletionModelFunction
logger = logging.getLogger(__name__)
T = TypeVar("T", bound=Callable)
def function_specs_from_commands(
commands: Iterable[Command],
) -> list[CompletionModelFunction]:
"""Get OpenAI-consumable function specs for the agent's available commands.
see https://platform.openai.com/docs/guides/gpt/function-calling
"""
return [
CompletionModelFunction(
name=command.names[0],
description=command.description,
parameters={param.name: param.spec for param in command.parameters},
)
for command in commands
]
|