From 88e3ed0648b17927ac319a48ae400e263a2f8752 Mon Sep 17 00:00:00 2001 From: fiatrete Date: Fri, 16 Jun 2023 15:58:57 +0800 Subject: [PATCH] Delete Message typed dict --- agent_jarvis/jarvis/ai_agent/agent_utils.py | 16 ---------------- agent_jarvis/jarvis/ai_agent/gpt_agent.py | 6 ++---- agent_jarvis/jarvis/gpt/ai_function.py | 3 +-- agent_jarvis/jarvis/gpt/gpt.py | 3 +-- agent_jarvis/jarvis/gpt/message.py | 9 --------- agent_jarvis/jarvis/gpt/token_counter.py | 4 +--- 6 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 agent_jarvis/jarvis/gpt/message.py diff --git a/agent_jarvis/jarvis/ai_agent/agent_utils.py b/agent_jarvis/jarvis/ai_agent/agent_utils.py index 5e32344..aa70ac4 100644 --- a/agent_jarvis/jarvis/ai_agent/agent_utils.py +++ b/agent_jarvis/jarvis/ai_agent/agent_utils.py @@ -2,7 +2,6 @@ import json from typing import Dict from jarvis.functional_modules.functional_module import CallerContext, moduleRegistry -from jarvis.gpt.message import Message from jarvis.logger import logger @@ -16,21 +15,6 @@ def must_not_be_valid_json(s: str): return True return False - -def create_chat_message(role, content) -> Message: - """ - Create a chat message with the given role and content. - - Args: - role (str): The role of the message sender, e.g., "system", "user", or "assistant". - content (str): The content of the message. - - Returns: - dict: A dictionary containing the role and content of the message. - """ - return {"role": role, "content": content} - - def get_thoughts(reply: Dict, assistant_reply_json_valid: dict): assistant_thoughts_reasoning = None assistant_thoughts_speak = None diff --git a/agent_jarvis/jarvis/ai_agent/gpt_agent.py b/agent_jarvis/jarvis/ai_agent/gpt_agent.py index 47b2a9f..a6d8368 100644 --- a/agent_jarvis/jarvis/ai_agent/gpt_agent.py +++ b/agent_jarvis/jarvis/ai_agent/gpt_agent.py @@ -7,12 +7,10 @@ from typing import Dict, List from openai.error import RateLimitError from jarvis import CFG -from jarvis.ai_agent.agent_utils import must_not_be_valid_json, get_thoughts, get_function, execute_function, \ - create_chat_message +from jarvis.ai_agent.agent_utils import must_not_be_valid_json, get_thoughts, get_function, execute_function from jarvis.ai_agent.base_agent import BaseAgent from jarvis.functional_modules.functional_module import CallerContext, moduleRegistry from jarvis.gpt import token_counter, gpt -from jarvis.gpt.message import Message from jarvis.json_utils.json_fix_llm import fix_json_using_multiple_techniques from jarvis.json_utils.utilities import validate_json from jarvis.logger import logger @@ -74,7 +72,7 @@ you: { class GptAgent(BaseAgent): _system_prompt: str - _full_message_history: List[Message] = [] + _full_message_history: List[dict] = [] _message_tokens: List[int] = [] def __init__(self, caller_context: CallerContext): diff --git a/agent_jarvis/jarvis/gpt/ai_function.py b/agent_jarvis/jarvis/gpt/ai_function.py index 3c52008..1bcdcb3 100644 --- a/agent_jarvis/jarvis/gpt/ai_function.py +++ b/agent_jarvis/jarvis/gpt/ai_function.py @@ -2,7 +2,6 @@ from typing import List from jarvis import CFG from jarvis.gpt import gpt -from jarvis.gpt.message import Message from jarvis.logger import logger @@ -27,7 +26,7 @@ async def acall_ai_function(function: str, args: list, description: str, model: args = [str(arg) if arg is not None else "None" for arg in args] # parse args to comma separated string args: str = ", ".join(args) - messages: List[Message] = [ + messages: List[dict] = [ { "role": "system", "content": f"You are now the following python function: ```# {description}" diff --git a/agent_jarvis/jarvis/gpt/gpt.py b/agent_jarvis/jarvis/gpt/gpt.py index e2d3bd3..3d13031 100644 --- a/agent_jarvis/jarvis/gpt/gpt.py +++ b/agent_jarvis/jarvis/gpt/gpt.py @@ -4,7 +4,6 @@ import openai from openai.error import RateLimitError, APIError, Timeout from jarvis import CFG -from jarvis.gpt.message import Message from jarvis.logger import logger from typing import Callable @@ -60,7 +59,7 @@ async def acreate_chat_completion_once( # Overly simple abstraction until we create something better # simple retry mechanism when getting a rate error or a bad gateway async def acreate_chat_completion( - messages: list[Message], # type: ignore + messages: list[dict], model: str = None, temperature: float = CFG.temperature, max_tokens: int = None, diff --git a/agent_jarvis/jarvis/gpt/message.py b/agent_jarvis/jarvis/gpt/message.py deleted file mode 100644 index 2af8578..0000000 --- a/agent_jarvis/jarvis/gpt/message.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Type helpers for working with the OpenAI library""" -from typing import TypedDict - - -class Message(TypedDict): - """OpenAI Message object containing a role and the message content""" - - role: str - content: str diff --git a/agent_jarvis/jarvis/gpt/token_counter.py b/agent_jarvis/jarvis/gpt/token_counter.py index 4dfbaeb..2e661d5 100644 --- a/agent_jarvis/jarvis/gpt/token_counter.py +++ b/agent_jarvis/jarvis/gpt/token_counter.py @@ -5,11 +5,9 @@ from typing import List import tiktoken_async -from jarvis.gpt.message import Message - async def count_message_tokens( - messages: List[Message], model: str = "gpt-3.5-turbo-0301" + messages: List[dict], model: str = "gpt-3.5-turbo-0301" ) -> int: """ Returns the number of tokens used by a list of messages.