-
-
Save juananpe/34bb3c04b0afb50e1e7b702e5a8c1c5f to your computer and use it in GitHub Desktop.
Similarity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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