Skip to content

Commit

Permalink
Verify model compatibility if OPENAI_FUNCTIONS is set (Significant-Gr…
Browse files Browse the repository at this point in the history
…avitas#5075)

Co-authored-by: Luke <2609441+lc0rp@users.noreply.github.com>
  • Loading branch information
Pwuts and lc0rp authored Jul 31, 2023
1 parent b7f1df3 commit 3651d22
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
8 changes: 6 additions & 2 deletions autogpt/command_decorator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from __future__ import annotations

import functools
from typing import Any, Callable, Optional, TypedDict
from typing import TYPE_CHECKING, Any, Callable, Optional, TypedDict

if TYPE_CHECKING:
from autogpt.config import Config

from autogpt.config import Config
from autogpt.models.command import Command, CommandParameter

# Unique identifier for auto-gpt commands
Expand Down
10 changes: 10 additions & 0 deletions autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pydantic import Field, validator

from autogpt.core.configuration.schema import Configurable, SystemSettings
from autogpt.llm.providers.openai import OPEN_AI_CHAT_MODELS
from autogpt.plugins.plugins_config import PluginsConfig

AI_SETTINGS_FILE = "ai_settings.yaml"
Expand Down Expand Up @@ -147,6 +148,15 @@ def validate_plugins(cls, p: AutoGPTPluginTemplate | Any):
), f"Plugins must subclass AutoGPTPluginTemplate; {p} is a template instance"
return p

@validator("openai_functions")
def validate_openai_functions(cls, v: bool, values: dict[str, Any]):
if v:
smart_llm = values["smart_llm"]
assert OPEN_AI_CHAT_MODELS[smart_llm].supports_functions, (
f"Model {smart_llm} does not support OpenAI Functions. "
"Please disable OPENAI_FUNCTIONS or choose a suitable model."
)

def get_openai_credentials(self, model: str) -> dict[str, str]:
credentials = {
"api_key": self.openai_api_key,
Expand Down
2 changes: 2 additions & 0 deletions autogpt/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class CompletionModelInfo(ModelInfo):
class ChatModelInfo(CompletionModelInfo):
"""Struct for chat model information."""

supports_functions: bool = False


@dataclass
class TextModelInfo(CompletionModelInfo):
Expand Down
4 changes: 4 additions & 0 deletions autogpt/llm/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
prompt_token_cost=0.0015,
completion_token_cost=0.002,
max_tokens=4096,
supports_functions=True,
),
ChatModelInfo(
name="gpt-3.5-turbo-16k-0613",
prompt_token_cost=0.003,
completion_token_cost=0.004,
max_tokens=16384,
supports_functions=True,
),
ChatModelInfo(
name="gpt-4-0314",
Expand All @@ -54,6 +56,7 @@
prompt_token_cost=0.03,
completion_token_cost=0.06,
max_tokens=8191,
supports_functions=True,
),
ChatModelInfo(
name="gpt-4-32k-0314",
Expand All @@ -66,6 +69,7 @@
prompt_token_cost=0.06,
completion_token_cost=0.12,
max_tokens=32768,
supports_functions=True,
),
]
}
Expand Down
7 changes: 5 additions & 2 deletions autogpt/models/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Any, Callable, Optional
from __future__ import annotations

from autogpt.config import Config
from typing import TYPE_CHECKING, Any, Callable, Optional

if TYPE_CHECKING:
from autogpt.config import Config

from .command_parameter import CommandParameter

Expand Down

0 comments on commit 3651d22

Please sign in to comment.