Skip to content

Commit

Permalink
Implement complete data types
Browse files Browse the repository at this point in the history
Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
  • Loading branch information
waynehamadi committed Jun 21, 2023
1 parent b4f2077 commit 0c39937
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion autogpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_command(
if not isinstance(assistant_reply_json, dict):
return (
"Error:",
f"'assistant_reply_json' object is not dictionary {assistant_reply_json}",
f"The previous message sent was not a dictionary {assistant_reply_json}",
)

command = assistant_reply_json["command"]
Expand Down
27 changes: 24 additions & 3 deletions autogpt/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from dataclasses import dataclass, field
from math import ceil, floor
from typing import Any, Dict, List, Literal, TypedDict
from typing import List, Literal, TypedDict

from autogpt.models.command_argument import CommandArgument

MessageRole = Literal["system", "user", "assistant"]
MessageType = Literal["ai_response", "action_result"]
Expand Down Expand Up @@ -157,7 +159,7 @@ class ChatModelResponse(LLMResponse):
"""Standard response struct for a response from an LLM model."""

content: str = None
function_call: Dict[str, Any] = None
function_call: OpenAIFunctionCall = None


@dataclass
Expand All @@ -166,4 +168,23 @@ class OpenAIFunctionSpec:

name: str
description: str
parameters: dict[str, Any]
parameters: OpenAIFunctionParameter


@dataclass
class OpenAIFunctionCall:
name: str
arguments: List[CommandArgument]


@dataclass
class OpenAIFunctionParameter:
type: str
properties: OpenAIFunctionProperties
required: bool


@dataclass
class OpenAIFunctionProperties:
type: str
description: str
20 changes: 11 additions & 9 deletions autogpt/llm/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
ChatModelInfo,
EmbeddingModelInfo,
MessageDict,
OpenAIFunctionParameter,
OpenAIFunctionProperties,
OpenAIFunctionSpec,
TextModelInfo,
TText,
Expand Down Expand Up @@ -282,18 +284,18 @@ def get_openai_command_specs(agent) -> list[OpenAIFunctionSpec]:
required = []

for argument in command.arguments:
properties[argument.name] = {
"type": argument.type,
"description": argument.description,
}
properties[argument.name] = OpenAIFunctionProperties(
type=argument.type,
description=argument.description,
)
if argument.required:
required.append(argument.name)
parameters = OpenAIFunctionParameter(
type="object",
properties=properties,
required=required,
)

parameters = {
"type": "object",
"properties": properties,
"required": required,
}
functions.append(
OpenAIFunctionSpec(
name=command.name,
Expand Down
3 changes: 2 additions & 1 deletion autogpt/llm/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from dataclasses import asdict
from typing import List, Literal, Optional

from colorama import Fore
Expand Down Expand Up @@ -139,7 +140,7 @@ def create_chat_completion(
] = config.get_azure_deployment_id_for_model(model)
if functions:
chat_completion_kwargs["functions"] = [
function.__dict__ for function in functions
asdict(function) for function in functions
]

response = iopenai.create_chat_completion(
Expand Down

0 comments on commit 0c39937

Please sign in to comment.