안녕하세요~!
어제에 이어서 약간만 더 발전된 ollama 사용을 해보려고 합니다.
일단 미리 설치하면 될 것들은 아래와 같습니다.
pip install langchain
pip install langchain-core
pip install langchain-community
1번 쉬운거
py 파일에 아래와 같이 작성하였습니다.
단점은 답변이 한방에 나오기 때문에 시간이 좀 걸립니다.
from langchain_community.chat_models import ChatOllama
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOllama(model='llama3')
prompt = ChatPromptTemplate.from_template(
"{topic} 에 대하여 200자 내로 간략히 설명해줘."
)
# Langchain 언어 체인 구문
chain = prompt | llm | StrOutputParser()
print(chain.invoke({'topic': "블록체인"}))
답변:
Here's a brief explanation of blockchain in under 200 words:
Blockchain is a decentralized, digital ledger technology that allows multiple parties to record and verify transactions without the need for a centralized authority. It's like a giant spreadsheet that's shared among a network of computers called nodes.
When a new transaction is made, it's broadcast to the network and verified by nodes using complex algorithms and cryptography. Once verified, the transaction is added to a "block" of data, which is then linked to previous blocks through unique codes called "hashes." This creates an irreversible chain of transactions, hence the name blockchain.
The decentralized nature of blockchain makes it resistant to tampering or censorship, as anyone on the network can verify and validate transactions. It's also transparent, as all transactions are recorded publicly and in real-time.
Blockchain technology has many potential applications, including secure data storage, supply chain management, and cryptocurrency transactions. It's a rapidly evolving field with exciting possibilities! 🚀
llama3를 그냥사용하면 한글을 잘 못한다.
당장에라도 한글을 나오게 하고 싶지만 일단 쉬운 것부터 하려고함.
한글 파인튜닝된 모델 사용하면 한글이 잘 나온다고한다.
2번 chunk 사용하기
일단 저 chunk 단위로 결과를 가져와서 좀 덜 지루한 느낌을 가져다 준다.
그리고 약간 GPT답변 작성할때 나오는 느낌? 스멜이남
from langchain_community.chat_models import ChatOllama
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOllama(model="EEVE-Korean-10.8B:latest")
# llm = ChatOllama(model='llama3')
prompt = ChatPromptTemplate.from_template(
"당신은 초등학생이 이해 할만큼 설명을 잘하는 Tutor 입니다."
"{topic} 에 대하여 이해하기 쉬운면서도 간략하게 설명해줘."
)
chain = prompt | llm | StrOutputParser()
topic = {'topic': "뉴진스"}
for chunks in chain.stream(topic):
print(chunks, end="", flush=True)
뉴진스에 뉴턴해버리기
답변1:
What a fun challenge! 😄 I'll try my best to explain Newton's laws in a way that a 3rd grader can understand! **Newton's First Law: The Law of Inertia** You know how you're sitting on the bus, and it starts moving? You don't just jump up and start flying off the seat because the bus is moving, right? That's because things like to keep doing what they're doing unless something else stops them. This is called "inertia." It means that if something is sitting still or moving, it will keep doing that until something else makes it change. **Newton's Second Law: The Force** Imagine you have a toy car and you push it across the floor. You use some force to make it move, right? That's because everything has a little bit of weight (or mass) that makes it resist moving or changing direction. So, if you want to make something move or change direction, you need to apply a force to it. The more massive an object is, the more force you need to use to get it moving! **Newton's Third Law: Action and Reaction** Have you ever played tug-of-war with your friends? You all grab onto a rope and pull in different directions. What happens? The other team pulls back on the rope just as hard! That's because when one side applies a force, the other side feels that same force. This is called "action and reaction." When you push or pull something, it always pushes or pulls back on you with an equal amount of force! That's Newton's laws in a nutshell (or a toy car, haha!)! They help us understand how things move and interact with each other in the world. 🚀
뉴진스를 New Jeans로 변경
뉴진스가 나오긴 하는데 10명이라고 한다.
평행우주 뉴진스는 아마도 10명일수도
답변2:
Let me explain NewJeans to you in a way that's easy to understand! So, NewJeans is a super cool K-pop group! 🎉 They're like a special team of friends who make music and perform together. The group has 10 members: Haerin, Danielle, Hanni, Hyein, Hina, Minji, You Jung, Hanni, Hyeongjun, and Hwang Minju. They all have different personalities and talents, but they work together like a puzzle to create something amazing! NewJeans' music is like a mix of fun pop songs with catchy melodies and dance moves. They also have meaningful lyrics that talk about life, love, and growing up. The group's name "NewJeans" comes from the idea of wearing new jeans - it symbolizes a fresh start and being ready to take on new adventures! 🌟 That's NewJeans in a nutshell! Aren't they just the coolest? 😊
3번 model, format, temperature 사용
이런 형식도 어디서 본것 같은디...
맨날 유투브를 너무 많이 본듯함
from langchain_community.chat_models import ChatOllama
from langchain_core.messages import HumanMessage
llm = ChatOllama(
model='llama3',
foramt='json',
temperature=0, # 모델 설명을 결정론적으로 출력 생성
)
messages = [
HumanMessage(
content='한국에 갈만한곳 10군대를 추천해줘.'
'translate to Korean if possible'
)
]
chat_model_response = llm.invoke(messages)
print(chat_model_response.content)
이게 더 답변이 깔끔해 보여서 이걸로 작성했다.
------
답변:
I'd be happy to recommend some must-visit places in South Korea for you! 😊 Here are my top 10 picks:
1. **Gyeongbokgung Palace** (경복궁) - A historic palace that dates back to the 14th century, showcasing traditional Korean architecture and culture.
2. **Myeong-dong Shopping District** (명동 쇼핑 디스트릭트) - One of Seoul's busiest shopping areas, offering a wide range of fashion, beauty, and food options.
3. **Nami Island** (남이도) - A peaceful island in the Han River, famous for its beautiful scenery, walking trails, and romantic atmosphere.
4. **Bukchon Hanok Village** (북촌한옥마을) - A traditional Korean village with hundreds of hanok houses, offering a glimpse into the country's past.
5. **N Seoul Tower** (서울타워) - A iconic landmark that offers stunning views of the city and is a popular spot for couples to take romantic photos.
6. **Jeju Island** (제주도) - A tropical island off the southern coast, known for its natural wonders like waterfalls, black sand beaches, and volcanic landscapes.
7. **Gwangjang Market** (광장시장) - A traditional market in Seoul that offers a wide range of street food, souvenirs, and local products.
8. **Haeundae Beach** (해운대 해변) - One of Busan's most popular beaches, known for its white sand and crystal-clear waters.
9. **Pyeongchang Ski Resort** (평창 스키 리조트) - A world-class ski resort in the Pyeongchang region, hosting several international skiing events.
10. **Jinhae Ganseok Festival** (진해간석제) - A colorful festival held annually in Jinhae, featuring traditional music, dance, and food.
I hope you enjoy your trip to South Korea! 🎉
------
뭐 아무튼 일단 이렇게도 답을 한다.
사실 이거보다 좀 더 현실적인 것을 바로 해보고 싶긴한데 너무 달리면
또 하나도 이해가 안될까봐 까먹지 않기위해 적으면서 해본다.
그럼 다음에 또 다른 글로 찾아오도록 하겠습니다.

2024.05.06 - [LLM] - [Ollama] Ollama로 llama3 간단하게 사용해보기~!
[Ollama] Ollama로 llama3 간단하게 사용해보기~!
안녕하세요~! 오늘은 저번글에서 설치한 ollama 를 간단하게 사용해보려고 합니다. Ollama 설치글은 저번글을 참고 하시면 됩니다.2024.05.06 - [LLM] - [LLM] Ollama 설치해보기~! [LLM] Ollama 설치해보기~
allispendabout.tistory.com
2024.05.06 - [LLM] - [Ollama] Ollama 설치해보기~!
[Ollama] Ollama 설치해보기~!
안녕하세요 ~! 오늘은 Ollama 설치에 대한 간단한 설치 방법을 소개해보려고 합니다. 설치는 아래 주소로 들어가서 진행하면됩니다.https://ollama.com/ OllamaGet up and running with large language models.ollam
allispendabout.tistory.com
'LLM > Langchain' 카테고리의 다른 글
[Langchain] Langchain에서 Ollama로 llama3 간단하게 사용해보기~! (0) | 2024.05.08 |
---|