Initial commit

This commit is contained in:
Jono Targett 2023-06-25 16:22:22 +09:30
commit e42a5bfa7c
2 changed files with 34 additions and 0 deletions

32
gpt_sort.py Executable file
View File

@ -0,0 +1,32 @@
#! /usr/bin/env python3
from langchain.chains import LLMChain
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
llm = OpenAI(temperature=0)
def gpt_sort(items: list) -> list:
sort_prompt = PromptTemplate(
input_variables=["unsorted_items"],
template="""{unsorted_items}
Please sort the items in the list. Format your output as a python list.
""",
)
sort_chain = LLMChain(prompt=sort_prompt, llm=llm)
sorted_items = eval(sort_chain.run(items))
return sorted_items
if __name__ == "__main__":
test_data = [4, 3, 22, -1, 1, 0, False, "banana", 1e100, -99]
results = gpt_sort(test_data)
# Output: [False, -99, -1, 1, 3, 4, 22, 'banana', 1e+100]
print(results)
print("Is a list? ", isinstance(results, list))

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
langchain
openai