Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-john-wbdocs-2044-rename-serverless-products.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
프롬프트를 만들고, 평가하고, 다듬는 일은 AI 엔지니어의 핵심 작업입니다.
프롬프트를 조금만 바꿔도 애플리케이션의 동작에 큰 영향을 줄 수 있습니다.
W&B Weave를 사용하면 프롬프트를 만들고, 게시하고, 시간이 지나면서 발전시켜 나갈 수 있습니다.
이 페이지에서는 프롬프트 객체를 만들고 게시하는 방법을 설명합니다. 게시된 프롬프트 버전을 참조하고, 가져오고, 관리하는 방법은 프롬프트 버전 저장 및 추적을 참조하세요.
프롬프트 요구 사항이 단순하다면 기본 제공 weave.StringPrompt 또는 weave.MessagesPrompt 클래스를 사용할 수 있습니다. 요구 사항이 더 복잡하다면 이러한 클래스나 기본 클래스인 weave.Prompt를 서브클래싱하고 format 방법을 재정의할 수 있습니다.
weave.publish로 프롬프트를 게시하면 Weave 프로젝트의 Prompts 페이지에 표시됩니다.
StringPrompt는 시스템 메시지, 사용자 질의 또는 LLM에 대한 독립적인 텍스트 입력에 사용할 수 있는 단일 문자열 프롬프트를 기록합니다. 여러 메시지로 이루어진 대화 수준의 복잡성이 필요하지 않은 개별 프롬프트 문자열을 관리할 때는 StringPrompt를 사용하는 것이 좋습니다.
import weave
weave.init('intro-example')
system_prompt = weave.StringPrompt("You speak like a pirate")
weave.publish(system_prompt, name="pirate_prompt")
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": system_prompt.format()
},
{
"role": "user",
"content": "Explain general relativity in one paragraph."
}
],
)
import * as weave from 'weave';
import OpenAI from 'openai';
async function main() {
// weave.init는 클라이언트 인스턴스를 반환합니다
const weaveClient = await weave.init('wandb/prompt-examples');
const systemPrompt = new weave.StringPrompt({
content: 'You speak like a pirate',
name: 'your-prompt',
description: 'A helpful description of your prompt',
});
// init에서 반환된 클라이언트를 사용합니다
await weaveClient.publish(systemPrompt, 'pirate_prompt');
// Weave에서 call을 추적하도록 OpenAI 클라이언트를 래핑합니다
const client = weave.wrapOpenAI(new OpenAI());
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "system",
content: systemPrompt.content
},
{
role: "user",
content: "Explain general relativity in one paragraph."
}
],
});
}
main();
MessagesPrompt를 사용하면 멀티턴 대화와 채팅 기반 프롬프트를 기록할 수 있습니다. 이 기능은 전체 대화 흐름을 나타내는 메시지 객체 배열(예: “system”, “user”, “assistant” 역할)을 저장합니다. 여러 메시지에 걸쳐 컨텍스트를 유지해야 하거나, 특정 대화 패턴을 정의하거나, 재사용 가능한 대화 템플릿을 만들어야 하는 채팅 기반 LLM에는 MessagesPrompt를 사용하는 것을 권장합니다.
import weave
weave.init('intro-example')
prompt = weave.MessagesPrompt([
{
"role": "system",
"content": "You are a stegosaurus, but don't be too obvious about it."
},
{
"role": "user",
"content": "What's good to eat around here?"
}
])
weave.publish(prompt, name="dino_prompt")
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=prompt.format(),
)
import * as weave from 'weave';
import OpenAI from 'openai';
async function main() {
// weave.init은 클라이언트 인스턴스를 반환합니다
const weaveClient = await weave.init('wandb/prompt-examples');
const prompt = new weave.MessagesPrompt({
messages: [
{
"role": "system",
"content": "You are a stegosaurus, but don't be too obvious about it."
},
{
"role": "user",
"content": "What's good to eat around here?"
}
],
});
// init에서 반환된 클라이언트를 사용합니다
await weaveClient.publish(prompt, 'dino_prompt');
// Weave에서 call을 추적할 수 있도록 OpenAI 클라이언트를 래핑합니다
const client = weave.wrapOpenAI(new OpenAI());
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: prompt.messages,
});
}
main();
StringPrompt와 MessagesPrompt는 모두 매개변수화를 통해 동적 콘텐츠를 지원합니다. 이를 통해 런타임에 서로 다른 값으로 채워 넣을 수 있는 플레이스홀더({variable} 구문 사용)가 포함된 유연하고 재사용 가능한 프롬프트 템플릿을 만들 수 있습니다. 이는 일관된 구조를 유지하면서도 프롬프트가 다양한 입력, 사용자 데이터 또는 컨텍스트에 맞게 조정되어야 하는 확장 가능한 애플리케이션을 구축할 때 유용합니다. format()은 이러한 플레이스홀더를 실제 값으로 바꾸기 위한 키-값 쌍을 받습니다.
import weave
weave.init('intro-example')
prompt = weave.StringPrompt("Solve the equation {equation}")
weave.publish(prompt, name="calculator_prompt")
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": prompt.format(equation="1 + 1 = ?")
}
],
)
import * as weave from 'weave';
import OpenAI from 'openai';
async function main() {
// weave.init은 클라이언트 인스턴스를 반환합니다
const weaveClient = await weave.init('wandb/prompt-examples');
const prompt = new weave.StringPrompt({
content: 'Solve the equation {equation}',
});
// init에서 반환된 클라이언트를 사용합니다
await weaveClient.publish(prompt, 'calculator_prompt');
// Weave에서 call을 추적하도록 OpenAI 클라이언트를 래핑합니다
const client = weave.wrapOpenAI(new OpenAI());
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: prompt.format({ equation: "1 + 1 = ?" })
}
],
});
}
main();
MessagesPrompt에서도 동일하게 사용할 수 있습니다.
import weave
weave.init('intro-example')
prompt = weave.MessagesPrompt([
{
"role": "system",
"content": "You will be provided with a description of a scene and your task is to provide a single word that best describes an associated emotion."
},
{
"role": "user",
"content": "{scene}"
}
])
weave.publish(prompt, name="emotion_prompt")
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=prompt.format(scene="A dog is lying on a dock next to a fisherman."),
)
import * as weave from 'weave';
import OpenAI from 'openai';
async function main() {
// weave.init은 클라이언트 인스턴스를 반환합니다
const weaveClient = await weave.init('wandb/prompt-examples');
const prompt = new weave.MessagesPrompt({
messages: [
{
"role": "system",
"content": "You will be provided with a description of a scene and your task is to provide a single word that best describes an associated emotion."
},
{
"role": "user",
"content": "{scene}"
}
]
});
// init에서 반환된 클라이언트를 사용합니다
await weaveClient.publish(prompt, 'emotion_prompt');
// Weave에서 call을 추적하도록 OpenAI 클라이언트를 래핑합니다
const client = weave.wrapOpenAI(new OpenAI());
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: prompt.format({ scene: "A dog is lying on a dock next to a fisherman." }),
});
}
main();