Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'digest' #18

Open
2 tasks done
raphavtorres opened this issue Sep 5, 2024 · 0 comments
Open
2 tasks done

KeyError: 'digest' #18

raphavtorres opened this issue Sep 5, 2024 · 0 comments
Assignees

Comments

@raphavtorres
Copy link

Prerequisites

  • I checked the documentation and found no answer to my problem
  • I checked the existing issues and made sure there are no similar bug reports

Category

Bug (unexpected behavior)

Expected Behavior

No response

Observed Behavior

.venv\Lib\site-packages\ai_engine_sdk\client.py", line 205, in get_messages
    'model': agent_json['context_json']['digest'],
             ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'digest'

To Reproduce

I was testing the "Example Usage of the SDK" from docs

import asyncio
import logging
import os
import sys
from time import sleep
from ai_engine_sdk import (
    AiEngine,
    is_agent_message,
    is_ai_engine_message,
    is_confirmation_message,
    is_stop_message,
    is_task_selection_message, TaskSelectionMessage
)
from ai_engine_sdk import ApiBaseMessage, FunctionGroup
 
logger = logging.getLogger(__name__)
 
api_key = os.getenv("AV_API_KEY", "")
interaction_user_prompt_header = f"\n\n🤖 Interaction time"
 
 
async def main():
    logger.debug("🚀 Starting example execution")
    ai_engine = AiEngine(api_key)
 
    function_groups: list[FunctionGroup] = await ai_engine.get_function_groups()
 
    public_group = next((g for g in function_groups if g.name == "Fetch Verified"), None)
    if public_group is None:
        raise Exception('Could not find "Public" function group.')
 
    session = await ai_engine.create_session(function_group=public_group.uuid)
    default_objective: str = "Find a flight to warsaw."
 
    logger.info(interaction_user_prompt_header)
    objective = input(f"\n🎯 What is your objective [default: {default_objective}]: ") or default_objective
    await session.start(objective)
 
    try:
        empty_count = 0
        session_ended = False
 
        while empty_count < 100:
            messages: list[ApiBaseMessage] = await session.get_messages()
            if len(messages) == 0:
                empty_count += 1
            else:
                empty_count = 0
 
            message: ApiBaseMessage
            for message in messages:
                if is_task_selection_message(message_type=message.type):
                    task_selection_message: TaskSelectionMessage = message
 
                    logger.info(interaction_user_prompt_header)
                    print("Please select a key from the list below:\n")
                    for _, option in task_selection_message.options.items():
                        print(f"➡ 🔑 {option.key}  ->  🧰 {option.title}")
                    option_key = str(input("\nEnter task key: "))
 
                    # check the index
                    if option_key not in task_selection_message.options.keys():
                        raise Exception(f"🔴 Invalid task number.\n You selected: {option_key}")
                    logger.debug(option_key)
                    await session.submit_task_selection(
                        message, 
                        [task_selection_message.options[option_key]]
                        )
                    del task_selection_message
                elif is_agent_message(message):
                    logger.info(interaction_user_prompt_header)
                    print(message.text.capitalize())
                    response = input("✍ (enter to skip): ")
                    if response == "exit":
                        break
 
                    if response != "":
                        await session.submit_response(message, response)
                elif is_ai_engine_message(message):
                    logger.info(f"\n 🤖 ℹ Informative message \n\n ---> ✨{message.text}")
                    sleep(3.5)
                elif is_confirmation_message(message_type=message.type):
                    logger.info(interaction_user_prompt_header)
                    print("Confirm:", message.payload)
                    response = input("\nPress enter to confirm, otherwise explain issue:\n")
 
                    if response == "":
                        await session.submit_confirmation(message)
                    else:
                        await session.reject_confirmation(message, response)
                elif is_stop_message(message):
 
                    logger.info("\n 👋 Session has ended, thanks! ")
                    session_ended = True
                    break
 
            # if the session has concluded then break
            if session_ended:
                break
 
            logger.info(f"\n🤖 Processing\n")
            sleep(1.5)
            logger.debug(f"No messages: {empty_count} times in a row")
 
    except Exception as e:
        logger.debug(f"Unhandled exception: {e}")
        print("Error", e)
        raise e
    finally:
        # clean up the session
        await session.delete()
 
 
if __name__ == "__main__":
    logging.basicConfig(
        stream=sys.stdout,
        level=logging.DEBUG,
        # level=logging.INFO,
        format='%(asctime)s %(levelname)s %(module)s: %(message)s',
        datefmt="%H:%M:%S"
    )
    asyncio.run(main())

Version

0.1.2 (latest)

Environment Details (Optional)

ai-engine-sdk==0.1.2
aiohappyeyeballs==2.4.0
aiohttp==3.10.5
aiosignal==1.3.1
attrs==24.2.0
frozenlist==1.4.1
idna==3.8
multidict==6.0.5
pydantic==1.10.18
python-dotenv==1.0.1
typing_extensions==4.12.2
yarl==1.9.8

Failure Logs (Optional)

No response

Additional Information (Optional)

It ran until one of the last requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants