Initial commit
This commit is contained in:
commit
e42a5bfa7c
32
gpt_sort.py
Executable file
32
gpt_sort.py
Executable 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
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
langchain
|
||||
openai
|
||||
Loading…
Reference in New Issue
Block a user