[Python] Claude 3.5 sonnet V2 error using Bedrock-aws

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I have this code where I wanna use the claude llm in Bedrock.

    def txt_json_exp(txt, language):
    final_data = {'Potential Candidate': {'Experiences': []}}
    chunks = []
    try:
    prof_text = extract_sections(txt, "Professional Experiences")
    # Ajouter la langue au texte ou au prompt de manière explicite
    chunked_experiences = split_experiences(prof_text, max_experiences=8)
    prompt_template = PromptTemplate(
    input_variables=["text", "language"],
    template="Human: Generate the response in the same language as provided: {language}\n\n{text}\n\nAssistant:",
    validate_template=True
    )
    for chunk in chunked_experiences:
    prof_text = f"Generate the response in the same language as provided : {language}\n{additional_instruction}\n" + chunk
    chain = create_extraction_chain(llm, schema_exp, encoder_or_encoder_class='json', instruction_template = prompt_template, verbose=True)
    res = chain.run({"text" : prof_text, "language": language})['data']
    chunks.append(res)

    for chunk in chunks:
    if 'Potential Candidate' in chunk and 'Experiences' in chunk['Potential Candidate']:
    final_data['Potential Candidate']['Experiences'].extend(chunk['Potential Candidate']['Experiences'])
    return final_data

    except Exception as e:
    print(f"Erreur lors de l'extraction des données : {str(e)}")
    return None


    I was first getting errors, missing input key {"text"}. When I replaced my input varibales with that, now I simply get 'text' as an error when printing it below in my error handling. I don't know what I'm doing wrong.

    Continue reading...

Compartilhe esta Página