minte9
LearnRemember / MLEARNING





Hello World

 
""" Simple LLMChain passing LLM model and a prompt template
"""

from langchain.prompts import PromptTemplate
from langchain_openai import OpenAI   
from langchain.chains import LLMChain

import os
from dotenv import load_dotenv
load_dotenv()

prompt = PromptTemplate.from_template("Suggest {number} names for a {domain} website")
llm = OpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"))
chain = LLMChain(llm=llm, prompt=prompt)

answer = chain.run({'number': 5, 'domain': 'machine learning'})
print(answer)
"""
    1. IntelliLearn
    2. DataBrains
    3. ML Mastermind
    4. PredictiveIQ
    5. Algorithmic Academy
"""

response = chain.run({'number': 5, 'domain': 'online games'})
print(response)
"""
    1. GameSphere
    2. PlayHaven
    3. GamingZone
    4. VirtualArcade
    5. FunQuest 
"""

Text Preprocessing

 
""" LLMChain that preprocess a text by follogin a given sequence of steps.
If a step has the value no, it shouldn't be performed.
"""

from langchain.prompts import PromptTemplate
from langchain_openai import OpenAI   
from langchain.chains import LLMChain

import os
from dotenv import load_dotenv
load_dotenv()

prompt = PromptTemplate.from_template(
"""
    Process the given text by following the given steps in sequence. 
    Follow only the steps that have a 'yes' as value. Remove Number:{number}, 
    Remove Punctuation: {punctuation}, Word stemming: {stemming}. Output just
    the preprocessed text.Text:{text}
""")
llm = OpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"))
chain = LLMChain(llm=llm, prompt=prompt)

answer = print(chain.run({
    'text': 'I have answered correctly to 7 out of 10 questions!',
    'number': 'yes',
    'punctuation': 'yes',
    'stemming': 'no'
}))
print(answer)
"""
    I have answered correctly to out of questions
"""



  Last update: 3 days ago

References and applications: