EverlyAI

EverlyAI

EverlyAI의 LLM을 LlamaIndex에서 사용하는 통합 가이드예요. chat과 complete, 그리고 스트리밍까지 간단히 살펴봅니다.

출처: 문서

본문

colab에서 이 노트북을 열었다면 LlamaIndex 🦙를 설치해야 할 거예요.

%pip install llama-index-llms-everlyai
!pip install llama-index
from llama_index.llms.everlyai import EverlyAI
from llama_index.core.llms import ChatMessage

ChatMessage 목록으로 chat 호출

EVERLYAI_API_KEY 환경 변수를 설정하거나 클래스 생성자에서 api_key를 설정해야 해요.

# import os
# os.environ['EVERLYAI_API_KEY'] = '<your-api-key>'


llm = EverlyAI(api_key="your-api-key")
message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)
assistant:  Sure! Here's a classic one:

Why don't scientists trust atoms?

Because they make up everything!

I hope that brought a smile to your face!

스트리밍 (Streaming)

message = ChatMessage(role="user", content="Tell me a story in 250 words")
resp = llm.stream_chat([message])
for r in resp:
    print(r.delta, end="")
 Sure, here is a story in 250 words:

As the sun set over the horizon, a young girl named Lily sat on the beach, watching the waves roll in. She had always loved the ocean, and today was no different. The water was a deep blue, almost purple, and the waves were gentle and soothing. Lily closed her eyes and let the sound of the waves wash over her, feeling the stress of her daily life melt away.
Suddenly, a seagull landed nearby, chirping and flapping its wings. Lily opened her eyes and saw the bird was holding something in its beak. Curious, she leaned forward and saw that the bird was carrying a small, shimmering shell. The bird dropped the shell at Lily's feet, and she picked it up, feeling its smooth surface and admiring its beauty.
As she held the shell, Lily felt a strange sensation wash over her. She felt connected to the ocean and the bird, and she knew that this moment was special. She looked out at the water and saw a school of fish swimming in the distance, their scales shimmering in the sun

프롬프트로 complete 호출

resp = llm.complete("Tell me a joke")
print(resp)
 Sure, here's a classic one:

Why don't scientists trust atoms?

Because they make up everything!

I hope that brought a smile to your face!
resp = llm.stream_complete("Tell me a story in 250 words")
for r in resp:
    print(r.delta, end="")
 Sure, here is a story in 250 words:

As the sun set over the horizon, a young girl named Maria sat on the beach, watching the waves roll in. She had always loved the ocean, and today was no different. The water was a deep blue, almost purple, and the waves were gentle and soothing.
Maria closed her eyes and let the sound of the waves wash over her. She could feel the sand beneath her feet, warm and soft. She felt at peace, like she was a part of something bigger than herself.
Suddenly, a seagull landed nearby, chirping and flapping its wings. Maria opened her eyes and saw the bird, and she felt a smile spread across her face. She loved the sound of the seagulls, and the way they seemed to know exactly when to appear.
As the sun dipped lower in the sky, Maria stood up and walked closer to the water. She felt the cool water wash over her feet, and she let out a contented sigh. This was her happy place, where she could escape the stresses of everyday life and just be.
Maria stayed there for a while

더 알아보기 (Learn more)