Langchain summarization 1

 Yes, it's definitely possible to use LangChain with a large language model (LLM) to create comment summarizations for RTSK Worknote. Here's a step-by-step guide to help you get started:

  1. Install LangChain and OpenAI: First, you'll need to install LangChain and the OpenAI library:

    sh
    pip install langchain langchain-openai
    
  2. Load the LLM: Next, load the OpenAI model:

    python
    from langchain_openai import ChatOpenAI
    import os
    import getpass
    
    os.environ["LANGCHAIN_API_KEY"] = getpass.getpass()
    llm = ChatOpenAI(model="text-davinci-003")
    
  3. Prepare the Data: Assuming you have a dataframe df with columns RTSK Number and RTSK Worknote, you can prepare the data for summarization:

    python
    import pandas as pd
    
    data = {
        'RTSK Number': ['001', '001', '002', '002'],
        'RTSK Worknote': [
            'Worknote 1 for RTSK 001.',
            'Worknote 2 for RTSK 001.',
            'Worknote 1 for RTSK 002.',
            'Worknote 2 for RTSK 002.'
        ]
    }
    df = pd.DataFrame(data)
    
  4. Create a Summarization Chain: Define a summarization chain using LangChain:

    python
    from langchain.chains.combine_documents import create_stuff_documents_chain
    from langchain_core.prompts import ChatPromptTemplate
    
    prompt = ChatPromptTemplate.from_template("Summarize this content: {context}")
    chain = create_stuff_documents_chain(llm, prompt)
    
  5. Summarize Comments: Group by RTSK Number and apply the summarization chain:

    python
    def summarize_comments(comments):
        combined_comments = ' '.join(comments)
        result = chain.invoke({"context": combined_comments})
        return result.choices[0].text.strip()
    
    summarized_df = df.groupby('RTSK Number')['RTSK Worknote'].apply(summarize_comments).reset_index()
    summarized_df.columns = ['RTSK Number', 'Summary']
    print(summarized_df)
    

This code will summarize the comments for each RTSK Number and print the summarized results. Let me know if you need any further assistance or adjustments!

---------------------------------------------------------------------------------------------------

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

---------------------------------------------------------------------------------------------------

https://kgptalkie.com/text-summarization-using-nlp/


failed


1


CondaSSLError: Encountered an SSL error. Most likely a certificate verification issue.


Exception: HTTPSConnectionPool(host='conda.anaconda.org', port=443): Max retries exceeded with url: /conda-forge/win-64/repodata.json .zst (Caused by SSLError (SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1000)')))


(myenv_spacy) C:\>


No comments

Theme images by tjasam. Powered by Blogger.