mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 19:04:19 +00:00
# What does this PR do? The goal of this PR is code base modernization. Schema reflection code needed a minor adjustment to handle UnionTypes and collections.abc.AsyncIterator. (Both are preferred for latest Python releases.) Note to reviewers: almost all changes here are automatically generated by pyupgrade. Some additional unused imports were cleaned up. The only change worth of note can be found under `docs/openapi_generator` and `llama_stack/strong_typing/schema.py` where reflection code was updated to deal with "newer" types. Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
import json
|
|
import pathlib
|
|
|
|
|
|
class TestCase:
|
|
_apis = [
|
|
"inference/chat_completion",
|
|
"inference/completion",
|
|
"openai/responses",
|
|
]
|
|
_jsonblob = {}
|
|
|
|
def __init__(self, name):
|
|
# loading all test cases
|
|
if self._jsonblob == {}:
|
|
for api in self._apis:
|
|
with open(pathlib.Path(__file__).parent / f"{api}.json") as f:
|
|
coloned = api.replace("/", ":")
|
|
try:
|
|
loaded = json.load(f)
|
|
except json.JSONDecodeError as e:
|
|
raise ValueError(f"There is a syntax error in {api}.json: {e}") from e
|
|
TestCase._jsonblob.update({f"{coloned}:{k}": v for k, v in loaded.items()})
|
|
|
|
# loading this test case
|
|
tc = self._jsonblob.get(name)
|
|
if tc is None:
|
|
raise ValueError(f"Test case {name} not found")
|
|
|
|
# these are the only fields we need
|
|
self.data = tc.get("data")
|
|
|
|
def __getitem__(self, key):
|
|
return self.data[key]
|