ImiHuman
ImiHuman

Reputation: 63

AttributeError: 'tuple' object has no attribute 'run' when using LangChain LLMChain

I'm building my first langchain app by following https://www.youtube.com/watch?v=MlK6SIjcjE8&t=189s

Here's my code:

#bring in deps
import os
from apikey import apikey

import streamlit as st
from langchain import LLMChain, OpenAI, PromptTemplate

os.environ['OPENAI_API_KEY'] = apikey

#app framework
st.title('YouTube GPT Creator')
prompt = st.text_input('Plug in your prompt here')

# Prompt templates
title_template = PromptTemplate(
    input_variables = ["topic"],
    template = 'write me a youtube video title about {topic}'
)


#Llms
llm = OpenAI(model="text-davinci-003",
             temperature=0.9)
title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True),


#show stuff to the screen if it has prompt
if prompt:
    # response = llm(prompt)
    response = title_chain.run(topic=prompt)
    st.write(response)

When I try to run it, I get this error:

AttributeError: 'tuple' object has no attribute 'run'
File "D:\Coding\langchain\app.py", line 30, in <module>
    response = title_chain.run(topic=prompt)
               ^^^^^^^^^^^^^^^

I'm not familiar with LangChain yet and I wonder if anyone can lend a hand to a potentialy real simple problem. Thank you for your time

Upvotes: 1

Views: 2258

Answers (2)

Ahmad Raza
Ahmad Raza

Reputation: 31

When we put a comma at the end it considers it as a tuple. So, Just remove the comma.

Upvotes: 3

ImiHuman
ImiHuman

Reputation: 63

Thank you @EwyynTomato

You have an extra comma in the end of this line title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True), remove that comma and things should work.

Silly me. Problem solved.

Upvotes: 1

Related Questions