you should extract information from the conversation for example is the user said "write a doc about pizza" the script write a content about pizza and store in google docs :
import os
import json
import torch
import re
from transformers import AutoTokenizer, AutoModelForCausalLM
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# Define the scope for Google Docs API
SCOPES = ['https://www.googleapis.com/auth/documents']

def create_and_write_doc(service, title, content):
    try:
        # Create a new document
        doc = {'title': title}
        created_doc = service.documents().create(body=doc).execute()
        document_id = created_doc.get('documentId')

        # Insert text into the document
        requests = [{
            'insertText': {
                'location': {'index': 1},
                'text': content
            }
        }]
        service.documents().batchUpdate(
            documentId=document_id,
            body={'requests': requests}
        ).execute()

        print(f"Document '{title}' created with ID: {document_id}")
        return True  # Indicate success
    except Exception as e:
        print(f"Error in creating or writing to the document: {e}")
        return False  # Indicate failure

def parse_input_with_llm(model, tokenizer, user_input):
    # Prepare the prompt for the LLM
    prompt = f"""Extract the document title and content from the following request and return only the JSON object in the format {{"title": "TITLE", "content": "CONTENT"}} without any additional text or explanations. Do not include any code blocks or comments.

User request: "{user_input}"

JSON output:
"""

    try:
        # Encode the prompt with attention mask
        inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
        input_ids = inputs['input_ids']
        attention_mask = inputs['attention_mask']

        # Generate the output
        with torch.no_grad():
            output_ids = model.generate(
                input_ids,
                attention_mask=attention_mask,
                max_new_tokens=150,
                temperature=0.7,
                do_sample=False,
                num_beams=1,
                pad_token_id=tokenizer.eos_token_id
            )

        # Decode the output
        output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)

        # Extract the JSON output from the generated text using regex
        json_pattern = r'```json\s*(\{[\s\S]*?\})\s*```|(\{[\s\S]*?\})'
        matches = re.findall(json_pattern, output_text, re.DOTALL)
        if matches:
            # matches is a list of tuples; get the first non-empty match
            json_str = ''
            for match in matches:
                json_str = match[0] or match[1]  # Either the code block capture or standalone
                if json_str:
                    break
            data = json.loads(json_str)
            title = data.get('title')
            content = data.get('content')
            return title, content
        else:
            print("Could not find JSON in the LLM output.")
            print("LLM Output:", output_text)
            return None, None
    except Exception as e:
        print(f"Error parsing LLM output: {e}")
        print("LLM Output:", output_text)
        return None, None

def main():
    # Check if credentials.json exists
    if not os.path.exists('credentials.json'):
        print("Error: 'credentials.json' file not found in the current directory.")
        return

    # Authentication
    try:
        flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
        creds = flow.run_local_server(port=0)
    except Exception as e:
        print(f"Error during authentication: {e}")
        return

    # Build the Docs API service
    try:
        docs_service = build('docs', 'v1', credentials=creds)
    except Exception as e:
        print(f"Error building Google Docs API service: {e}")
        return

    # Load the Hugging Face tokenizer and model
    print("Loading Hugging Face model...")
    try:
        model_name = "meta-llama/Llama-3.2-1B-Instruct"  # Update with a suitable model
        tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
        model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=True)
        print("Model loaded successfully.")
    except Exception as e:
        print(f"Error loading the model: {e}")
        return

    # Move model to GPU if available
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model.to(device)

    # Main loop to take user input
    while True:
        user_input = input("==> ")
        if user_input.lower() == "exit":
            break
        elif user_input.strip() == "":
            continue
        else:
            # Parse the user input using the LLM
            title, content = parse_input_with_llm(model, tokenizer, user_input)
            if title and content:
                success = create_and_write_doc(docs_service, title, content)
                if success:
                    print("Document created successfully.")
                else:
                    print("Failed to create the document.")
            else:
                print("Sorry, I couldn't understand your request.")
                print("Please make sure to provide clear instructions.")

if __name__ == '__main__':
    main()