Delete Message typed dict
This commit is contained in:
@@ -2,7 +2,6 @@ import json
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from jarvis.functional_modules.functional_module import CallerContext, moduleRegistry
|
from jarvis.functional_modules.functional_module import CallerContext, moduleRegistry
|
||||||
from jarvis.gpt.message import Message
|
|
||||||
from jarvis.logger import logger
|
from jarvis.logger import logger
|
||||||
|
|
||||||
|
|
||||||
@@ -16,21 +15,6 @@ def must_not_be_valid_json(s: str):
|
|||||||
return True
|
return True
|
||||||
return False
|
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):
|
def get_thoughts(reply: Dict, assistant_reply_json_valid: dict):
|
||||||
assistant_thoughts_reasoning = None
|
assistant_thoughts_reasoning = None
|
||||||
assistant_thoughts_speak = None
|
assistant_thoughts_speak = None
|
||||||
|
|||||||
@@ -7,12 +7,10 @@ from typing import Dict, List
|
|||||||
from openai.error import RateLimitError
|
from openai.error import RateLimitError
|
||||||
|
|
||||||
from jarvis import CFG
|
from jarvis import CFG
|
||||||
from jarvis.ai_agent.agent_utils import must_not_be_valid_json, get_thoughts, get_function, execute_function, \
|
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.base_agent import BaseAgent
|
from jarvis.ai_agent.base_agent import BaseAgent
|
||||||
from jarvis.functional_modules.functional_module import CallerContext, moduleRegistry
|
from jarvis.functional_modules.functional_module import CallerContext, moduleRegistry
|
||||||
from jarvis.gpt import token_counter, gpt
|
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.json_fix_llm import fix_json_using_multiple_techniques
|
||||||
from jarvis.json_utils.utilities import validate_json
|
from jarvis.json_utils.utilities import validate_json
|
||||||
from jarvis.logger import logger
|
from jarvis.logger import logger
|
||||||
@@ -74,7 +72,7 @@ you: {
|
|||||||
|
|
||||||
class GptAgent(BaseAgent):
|
class GptAgent(BaseAgent):
|
||||||
_system_prompt: str
|
_system_prompt: str
|
||||||
_full_message_history: List[Message] = []
|
_full_message_history: List[dict] = []
|
||||||
_message_tokens: List[int] = []
|
_message_tokens: List[int] = []
|
||||||
|
|
||||||
def __init__(self, caller_context: CallerContext):
|
def __init__(self, caller_context: CallerContext):
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ from typing import List
|
|||||||
|
|
||||||
from jarvis import CFG
|
from jarvis import CFG
|
||||||
from jarvis.gpt import gpt
|
from jarvis.gpt import gpt
|
||||||
from jarvis.gpt.message import Message
|
|
||||||
from jarvis.logger import logger
|
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]
|
args = [str(arg) if arg is not None else "None" for arg in args]
|
||||||
# parse args to comma separated string
|
# parse args to comma separated string
|
||||||
args: str = ", ".join(args)
|
args: str = ", ".join(args)
|
||||||
messages: List[Message] = [
|
messages: List[dict] = [
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
"content": f"You are now the following python function: ```# {description}"
|
"content": f"You are now the following python function: ```# {description}"
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import openai
|
|||||||
from openai.error import RateLimitError, APIError, Timeout
|
from openai.error import RateLimitError, APIError, Timeout
|
||||||
|
|
||||||
from jarvis import CFG
|
from jarvis import CFG
|
||||||
from jarvis.gpt.message import Message
|
|
||||||
from jarvis.logger import logger
|
from jarvis.logger import logger
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ async def acreate_chat_completion_once(
|
|||||||
# Overly simple abstraction until we create something better
|
# Overly simple abstraction until we create something better
|
||||||
# simple retry mechanism when getting a rate error or a bad gateway
|
# simple retry mechanism when getting a rate error or a bad gateway
|
||||||
async def acreate_chat_completion(
|
async def acreate_chat_completion(
|
||||||
messages: list[Message], # type: ignore
|
messages: list[dict],
|
||||||
model: str = None,
|
model: str = None,
|
||||||
temperature: float = CFG.temperature,
|
temperature: float = CFG.temperature,
|
||||||
max_tokens: int = None,
|
max_tokens: int = None,
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -5,11 +5,9 @@ from typing import List
|
|||||||
|
|
||||||
import tiktoken_async
|
import tiktoken_async
|
||||||
|
|
||||||
from jarvis.gpt.message import Message
|
|
||||||
|
|
||||||
|
|
||||||
async def count_message_tokens(
|
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:
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Returns the number of tokens used by a list of messages.
|
Returns the number of tokens used by a list of messages.
|
||||||
|
|||||||
Reference in New Issue
Block a user