Skip to content

Commit

Permalink
fix: move deepget back to plugin
Browse files Browse the repository at this point in the history
This avoids a circular dependency
  • Loading branch information
sjmonson committed Sep 27, 2024
1 parent 74380e2 commit a6cf9c2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugins/openai_plugin.py
Original file line number Diff line number Diff line change
@@ -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()
"""
Expand All @@ -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):
Expand Down

0 comments on commit a6cf9c2

Please sign in to comment.