Skip to content

Instantly share code, notes, and snippets.

@juananpe
Created July 8, 2023 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juananpe/34bb3c04b0afb50e1e7b702e5a8c1c5f to your computer and use it in GitHub Desktop.
Save juananpe/34bb3c04b0afb50e1e7b702e5a8c1c5f to your computer and use it in GitHub Desktop.
Similarity
from dotenv import load_dotenv
from langchain import PromptTemplate, LLMChain
from langchain.llms import OpenAI
load_dotenv()
template = """Given the following true sentence:
A sign that says W3C is on a white background
Tell me how similar is that sentence to the following one:
{sentence}
Write your answer in a JSON object with one key: similarity (a float from 0 to 1)
"""
prompt = PromptTemplate(
template=template,
input_variables=['sentence']
)
llm = OpenAI(temperature=0)
llm_chain = LLMChain(
prompt=prompt,
llm=llm,
)
sentence = input("Enter a sentence: ")
print(llm_chain.run(sentence))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment