From a6cf9c2af41e932dfb3787970c2278071315e8f8 Mon Sep 17 00:00:00 2001 From: Samuel Monson Date: Fri, 27 Sep 2024 11:51:03 -0400 Subject: [PATCH] fix: move deepget back to plugin This avoids a circular dependency --- plugins/openai_plugin.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/openai_plugin.py b/plugins/openai_plugin.py index 3628ecbf..113ea83c 100644 --- a/plugins/openai_plugin.py +++ b/plugins/openai_plugin.py @@ -1,14 +1,13 @@ import json import logging import time -from typing import Optional +from typing import Any, Optional import requests import urllib3 from plugins import plugin from result import RequestResult -from utils import deepget urllib3.disable_warnings() """ @@ -27,6 +26,18 @@ logger = logging.getLogger("user") +def deepget(obj: dict, *path, r: Any = None) -> Any: + """Acts like .get() but for nested objects.""" + loc = obj + for p in path: + try: + loc = loc[p] + # NOTE: If loc is list then an invalid index throws IndexError + except (KeyError, IndexError): + return r + return loc + + # This plugin is written primarily for testing vLLM, though it can be made # to work for other runtimes which conform to the OpenAI API, as required. class OpenAIPlugin(plugin.Plugin):