Untitled
unknown
plain_text
a year ago
1.1 kB
5
Indexable
import instructor from pydantic import BaseModel from openai import OpenAI import json # Define your desired output structure class UserInfo(BaseModel): subsidiary: str brand: str customer: str def get_user_info(api_key, message): # Patch the OpenAI client client = instructor.from_openai(OpenAI(api_key=api_key)) # Extract structured data from natural language user_info = client.chat.completions.create( model="gpt-3.5-turbo", response_model=UserInfo, messages=[{"role": "user", "content": message}], ) return user_info def main(): with open('config.json', 'r') as f: config = json.load(f) # Access configuration values api_key = config['OPENAI_API_KEY'] #message = "Give me all bills & bill credits for the pre-paid rent account and subsidiary DDE-US for Q2?" message = "pre-paid rent account?" user_info = get_user_info(api_key, message) print (user_info) # Convert the Pydantic object to JSON # user_info_json = json.dumps(user_info.dict()) # print(user_info_json) if __name__ == "__main__": main()
Editor is loading...
Leave a Comment