[LangChain] 토큰 및 비용 확인

pysun·2024년 12월 8일

LangChain

목록 보기
8/13

OpenAI API 비용 확인

from langchain_openai import ChatOpenAI
from langchain.callbacks import get_openai_callback

chat = ChatOpenAI(temperature=0.1)


# get_openai_callback: OpenAI API를 호출할 때 발생하는 사용량(토큰 수)과 비용을 추적할 수 있는 콜백 함수
with get_openai_callback as usage:
    a_result = chat.predict('What is the recipe for soju')
    b_result = chat.predict('What is the recipe for beer')
    print(a_result, '\n')
    print(b_result, '\n')
    print(usage)
Ingredients:
- 1 cup of rice
- 1 cup of water
- 1 tablespoon of nuruk (fermentation starter)
- 1 tablespoon of sugar

Instructions:
1. Rinse the rice thoroughly and soak it in water for at least 1 hour.
2. Drain the rice and place it in a steamer basket. Steam the rice for about 30 minutes or until it is cooked through.
3. Transfer the cooked rice to a large bowl and let it cool to room temperature.
4. In a separate bowl, mix the nuruk and sugar with water to create a paste.
5. Add the rice to the nuruk paste and mix well to combine.
6. Transfer the mixture to a clean glass jar and cover it with a clean cloth.
7. Let the mixture ferment in a dark, cool place for at least 1 week, stirring occasionally.
8. After 1 week, strain the mixture through a cheesecloth to remove any solids.
9. Transfer the liquid to a clean bottle and store it in the refrigerator.
10. Serve the homemade soju chilled and enjoy responsibly. 

Beer is typically made using the following ingredients and steps:

Ingredients:
- Water
- Barley malt
- Hops
- Yeast

Steps:
1. Malting: Barley grains are soaked in water and allowed to germinate, then dried in a kiln to produce malted barley.
2. Mashing: The malted barley is crushed and mixed with hot water to create a mash. This process extracts sugars from the barley.
3. Boiling: The mash is boiled and hops are added for flavor and aroma.
4. Fermentation: The boiled mixture, known as wort, is cooled and yeast is added. The yeast ferments the sugars in the wort, producing alcohol and carbon dioxide.
5. Conditioning: The beer is allowed to mature and develop its flavors in a process called conditioning.
6. Packaging: The beer is filtered, carbonated, and packaged for distribution and consumption.

Please note that there are many variations and styles of beer, each with its own unique ingredients and brewing process. 

Tokens Used: 461
	Prompt Tokens: 27
	Completion Tokens: 434
Successful Requests: 2
Total Cost (USD): $0.0009085

profile
배움의 흔적이 성장으로 이어지는 공간

0개의 댓글