attribution / llm_api /native_api.py
thanhnt-cf's picture
initial commit
7a38b33
raw
history blame
910 Bytes
import base64
from dotenv import load_dotenv
from . import openai_api as openai_info_extractor
from . import anthropic_api as anthropic_extractor
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
def extract_info(image_paths, provider, schema):
if provider == 'anthropic':
extractor = anthropic_extractor
elif provider == 'openai':
extractor = openai_info_extractor
else:
raise ValueError('Invalid provider')
return extractor.extract_info(image_paths, schema)
def follow_structure(json_info, provider, schema):
if provider == 'anthropic':
extractor = anthropic_extractor
elif provider == 'openai':
extractor = openai_info_extractor
else:
raise ValueError('Invalid provider')
return extractor.follow_structure(json_info, schema)