In this code, I get the following message ‘You exceeded your current quota, please check your plan and billing details’ despite my $20/month fee.
import openai
Mock LLM class to represent LangChain’s way of interfacing with OpenAI or another LLM provider
class LLM:
def init(self, model_name, openai_api_key):
self.model_name = model_name
self.openai_api_key = openai_api_key
# Configure OpenAI with the provided API key
openai.api_key = self.openai_api_key
def generate(self, prompt):
# Using OpenAI's API to generate a response based on the prompt
try:
response = openai.Completion.create(
engine=self.model_name, # Use the specified model
prompt=prompt, # The full prompt constructed for the LLM
max_tokens=100 # Adjust based on your needs
)
# Extracting the text from the response
return response.choices[0].text.strip()
except Exception as e:
return f"Error generating response: {e}"
Assuming you have these values set appropriately
API_KEY = “■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■gnpAoOjy”
MODEL_NAME = “gpt-3.5-turbo” # Example model, replace with ‘gpt-3.5-turbo’ if available
Instantiate the LLM with your model and API key
llm = LLM(model_name=MODEL_NAME, openai_api_key=API_KEY)
Assuming ChatPromptTemplate and the full_prompt are correctly defined as per previous corrections
from langchain.prompts import ChatPromptTemplate
Correctly instantiate ChatPromptTemplate with messages
template = ChatPromptTemplate.from_messages([
(“system”, “You are a poet who composes beautiful poems in {language}.”),
(“human”, “Please write a four line rhyming poem about {topic}.”)
])
Use template.invoke() with variables if LangChain supports it, else manually replace placeholders
variables = {“language”: “English”, “topic”: “spring”}
This is a placeholder for how you might replace variables in the actual implementation
full_prompt = “You are a poet who composes beautiful poems in English.\nPlease write a four line rhyming poem about spring.”
Generate the response using the LLM
response = llm.generate(full_prompt)
print(response)