lawyer_assitance / examples /test /dynamic_import_package.py
qgyd2021's picture
[update]add function calling test
44e1a5b
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import importlib
import time
from openai import OpenAI
from openai.pagination import SyncCursorPage
from openai.types.beta.threads import ThreadMessage
from project_settings import environment, project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--package_name",
default="get_current_weather",
type=str
)
parser.add_argument(
"--function_name",
default="get_current_weather",
type=str
)
args = parser.parse_args()
return args
def main():
args = get_args()
lib = importlib.import_module("functions.{}".format(args.package_name))
print(lib)
function_to_call = getattr(lib, args.function_name)
print(function_to_call)
result = function_to_call("beijing")
print(result)
del lib
lib = importlib.import_module("functions.not_exist")
print(lib)
return
if __name__ == '__main__':
main()