[PYTHON/LANGCHAIN] Llamafile 클래스 : invoke 메소드를 사용해 LLAMAFILE 서버와 질의 응답하기
■ Llamafile 클래스의 invoke 메소드를 사용해 LLAMAFILE 서버와 질의 응답을 하는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from langchain_community.llms.llamafile import Llamafile llamafile = Llamafile(base_url = "http://127.0.0.1:8080") resultString = llamafile.invoke("Here is my grandmother's beloved recipe for spaghetti and meatballs:") print(resultString) """ Ingredients: - 1 pound spaghetti (preferably homemade) - 2 cups all-purpose flour - 3 large eggs, beaten - 4 tablespoons olive oil - 1/2 teaspoon salt - 1/2 teaspoon black pepper - 2 pound ground beef (80% lean) - 1 cup chopped cooked sausage (usually Italian or Italian sausage, but feel free to use any other type you like) - 1 pound meatballs (homemade or store-bought), made from ground beef and bread crumbs - 2 cups tomato sauce - Salt and pepper to taste - Fresh parsley for garnish Directions: 1. Cook spaghetti according to package instructions until al dente. Drain and set aside. 2. In a large skillet, heat the olive oil over medium-high heat. Add the ground beef and cook until browned, breaking it up with a wooden spoon as it cooks. Remove the meatballs from the skillet and set aside. 3. In the same skillet, add another tablespoon of olive oil and the chopped sausage. Cook for about 5 minutes or until browned. Add salt and pepper to taste. Set aside. 4. In a large mixing bowl, whisk together the flour, eggs, and the remaining 1/2 teaspoon of salt and black pepper. Slowly pour in the tomato sauce, whisking constantly. Continue mixing until all ingredients are well combined. 5. Add the meatballs to the bowl with the egg mixture and stir until evenly coated. 6. Pour the spaghetti into a large baking dish and spread it out in an even layer. Add the meatballs on top of the pasta, making sure they are covered by about 1/4 inch. 7. Pour the tomato sauce over the meatballs and pasta, making sure to coat everything well. 8. Bake in the preheated oven for 30-35 minutes or until the spaghetti is tender and the meatballs are cooked through. 9. Let it rest for a few minutes before serving. 10. Garnish with fresh parsley and serve hot with a side of garlic bread (homemade, store-bought). Enjoy!</s> """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
aiohttp==3.9.5 aiosignal==1.3.1 annotated-types==0.7.0 async-timeout==4.0.3 attrs==23.2.0 certifi==2024.6.2 charset-normalizer==3.3.2 dataclasses-json==0.6.7 frozenlist==1.4.1 greenlet==3.0.3 idna==3.7 jsonpatch==1.33 jsonpointer==3.0.0 langchain==0.2.4 langchain-community==0.2.4 langchain-core==0.2.6 langchain-text-splitters==0.2.1 langsmith==0.1.77 marshmallow==3.21.3 multidict==6.0.5 mypy-extensions==1.0.0 numpy==1.26.4 orjson==3.10.5 packaging==24.1 pydantic==2.7.4 pydantic_core==2.18.4 PyYAML==6.0.1 requests==2.32.3 SQLAlchemy==2.0.30 tenacity==8.3.0 typing-inspect==0.9.0 typing_extensions==4.12.2 urllib3==2.2.1 yarl==1.9.4 |
※ pip install