Groq

Open In Colab
설정 없이 Weave에서 Groq 모델을 실험해 보고 싶으신가요? LLM 플레이그라운드를 사용해 보세요.
Groq는 빠른 AI 추론을 제공하는 AI 인프라 회사입니다. Groq의 LPU™ 추론 엔진은 뛰어난 컴퓨팅 속도, 품질 및 에너지 효율성을 제공하는 하드웨어 및 소프트웨어 플랫폼입니다. Weave는 Groq 채팅 완성 호출을 사용하여 이루어진 호출을 자동으로 추적하고 기록합니다.

추적

개발 중이나 프로덕션 환경에서 언어 모델 애플리케이션의 추적을 중앙 위치에 저장하는 것이 중요합니다. 이러한 추적은 디버깅에 유용하며, 애플리케이션을 개선하는 데 도움이 되는 데이터셋으로 활용될 수 있습니다. Weave는 Groq에 대한 추적을 자동으로 캡처합니다. 추적을 시작하려면 weave.init(project_name="<YOUR-WANDB-PROJECT-NAME>")를 호출하고 라이브러리를 평소와 같이 사용하세요.
import os
import weave
from groq import Groq

weave.init(project_name="groq-project")

client = Groq(
    api_key=os.environ.get("GROQ_API_KEY"),
)
chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Explain the importance of fast language models",
        }
    ],
    model="llama3-8b-8192",
)
이제 Weave는 Groq 라이브러리를 통해 이루어진 모든 LLM 호출을 추적하고 기록합니다. Weave 웹 인터페이스에서 추적을 볼 수 있습니다.

자체 작업 추적하기

함수를 @weave.op로 래핑하면 입력, 출력 및 앱 로직을 캡처하여 데이터가 앱을 통해 어떻게 흐르는지 디버깅할 수 있습니다. 작업을 깊게 중첩하고 추적하려는 함수의 트리를 구축할 수 있습니다. 또한 실험할 때 코드를 자동으로 버전 관리하여 git에 커밋되지 않은 임시 세부 정보를 캡처합니다. 간단히 @weave.op로 장식된 함수를 만드세요. 아래 예제에서는 recommend_places_to_visit 함수가 @weave.op로 래핑된 함수로, 도시에서 방문할 장소를 추천합니다.
import os
import weave
from groq import Groq


weave.init(project_name="groq-test")

client = Groq(
    api_key=os.environ.get("GROQ_API_KEY"),
)

@weave.op()
def recommend_places_to_visit(city: str, model: str="llama3-8b-8192"):
    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "system",
                "content": "You are a helpful assistant meant to suggest places to visit in a city",
            },
            {
                "role": "user",
                "content": city,
            }
        ],
        model="llama3-8b-8192",
    )
    return chat_completion.choices[0].message.content


recommend_places_to_visit("New York")
recommend_places_to_visit("Paris")
recommend_places_to_visit("Kolkata")
recommend_places_to_visit 함수를 @weave.op로 장식하면 함수의 입력, 출력 및 함수 내부에서 이루어진 모든 LM 호출을 추적합니다.

Model 생성으로 더 쉬운 실험

여러 요소가 있을 때 실험을 구성하는 것은 어렵습니다. Model 클래스를 사용하면 시스템 프롬프트나 사용 중인 모델과 같은 앱의 실험적 세부 사항을 캡처하고 구성할 수 있습니다. 이를 통해 앱의 다양한 반복을 구성하고 비교할 수 있습니다. 코드 버전 관리 및 입력/출력 캡처 외에도 Model는 애플리케이션의 동작을 제어하는 구조화된 매개변수를 캡처하여 어떤 매개변수가 가장 잘 작동했는지 쉽게 찾을 수 있게 합니다. Weave Models를 serve, 및 Evaluation와 함께 사용할 수도 있습니다. 아래 예제에서는 GroqCityVisitRecommender로 실험할 수 있습니다. 이 중 하나를 변경할 때마다 새로운 versionGroqCityVisitRecommender를 얻게 됩니다.
import os
from groq import Groq
import weave


class GroqCityVisitRecommender(weave.Model):
    model: str
    groq_client: Groq

    @weave.op()
    def predict(self, city: str) -> str:
        system_message = {
            "role": "system",
            "content": """
You are a helpful assistant meant to suggest places to visit in a city
""",
        }
        user_message = {"role": "user", "content": city}
        chat_completion = self.groq_client.chat.completions.create(
            messages=[system_message, user_message],
            model=self.model,
        )
        return chat_completion.choices[0].message.content


weave.init(project_name="groq-test")
city_recommender = GroqCityVisitRecommender(
    model="llama3-8b-8192", groq_client=Groq(api_key=os.environ.get("GROQ_API_KEY"))
)
print(city_recommender.predict("New York"))
print(city_recommender.predict("San Francisco"))
print(city_recommender.predict("Los Angeles"))
를 사용하여 호출 추적 및 버전 관리Model

Weave Model 제공하기

모든 weave.Model 객체에 대한 weave 참조가 주어지면 fastapi 서버를 시작하고 serve할 수 있습니다.
dspy_weave_model_serve.png
모델로 이동하여 UI에서 복사하면 모든 WeaveModel의 weave 참조를 찾을 수 있습니다.
터미널에서 다음 명령을 사용하여 모델을 제공할 수 있습니다:
weave serve weave:///your_entity/project-name/YourModel:<hash>