Created
April 8, 2023 23:33
-
-
Save reedlaw/c0adb9dbc98fc843748365c8c2154a61 to your computer and use it in GitHub Desktop.
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 langchain import OpenAI, LLMChain, PromptTemplate | |
from langchain import PromptTemplate, FewShotPromptTemplate | |
from langchain.chains import LLMChain | |
from langchain.llms import LlamaCpp | |
from langchain.prompts import PromptTemplate | |
import csv | |
examples = [ | |
{"product": "Toothpaste", | |
"category": "Health:Dental"}, | |
{"product": "Toilet Flapper", | |
"category": "Home:Maintenance"}, | |
{"product": "Laptop Stand", | |
"category": "Computer:Accessories"}, | |
{"product": "Pressure Cooker", | |
"category": "Kitchen:Appliances"}, | |
{"product": "T-shirt", | |
"category": "Clothing"}, | |
{"product": "Bananas", | |
"category": "Grocery"}, | |
] | |
llm = LlamaCpp(model_path="../llama.cpp/models/ggml-alpaca-7b-q4.bin") | |
example_formatter_template = """ | |
Product: {product} | |
Category: {category}\n | |
""" | |
example_prompt = PromptTemplate( | |
input_variables=["product", "category"], | |
template=example_formatter_template, | |
) | |
few_shot_prompt = FewShotPromptTemplate( | |
examples=examples, | |
example_prompt=example_prompt, | |
prefix="Give the category of every product", | |
suffix="Product: {product}\nCategory:", | |
input_variables=["product"], | |
example_separator="\n\n", | |
) | |
llm_chain = LLMChain( | |
llm=llm, | |
prompt=few_shot_prompt, | |
verbose=True, | |
) | |
with open('../../my/finances/amz.csv', 'r') as file: | |
reader = csv.DictReader(file) | |
for row in reader: | |
print(llm_chain.predict(product=row['Product Name'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This takes an Amazon order history CSV and categorizes products for expense tracking software such as Beancount. An example run produced: