TypeError: 'module' object is not callable

I keep getting this error. How can I fix it?

And I will provide the code:

import os
from constants import openai_api_key
from langchain.llms import openai
import streamlit as st
from langchain_community.llms import openai


os.environ['OPENAI_API_KEY'] = openai_api_key


# streamlit framework
st.title('LangChain Demo With OPENAI API ')
input_text = st.text_input('Search the topic you want ')

## OPENAI LLMS
llm = openai(tempertaure=0.8)

if input_text:
    st.write(llm(input_text))

Hello there!

You do not seem to be calling the chat completions module correctly. Here would be a correct example from the OpenAI cookbook:

# Example OpenAI Python library request
MODEL = "gpt-3.5-turbo"
response = client.chat.completions.create(
    model=MODEL,
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Knock knock."},
        {"role": "assistant", "content": "Who's there?"},
        {"role": "user", "content": "Orange."},
    ],
    temperature=0,
)

If you’re trying to use langchain, I would check their docs to see how to set that up.

1 Like