Crosshatch 프로바이더
Crosshatch 프로바이더
Crosshatch 프로바이더는 사용자가 공유한 데이터에 권한 있는 접근을 제공하면서 인기 언어 모델의 보안 추론을 지원해, 완전한 사용자 컨텍스트로 개인화된 응답을 제공해요.
이 프로바이더는 generateText와 streamText 함수에서 사용할 수 있는 언어 모델 객체를 만들며, Output을 통한 구조화된 데이터 생성도 지원해요.
참고: 이 커뮤니티 프로바이더는 아직 AI SDK 5와 호환되지 않아요. 프로바이더가 업데이트될 때까지 기다리거나 AI SDK 5 호환 프로바이더를 고려해 주세요.
출처: 문서
본문
설정 (Setup)
Crosshatch 프로바이더는 @crosshatch/ai-provider 모듈에서 사용할 수 있어요. 다음과 같이 설치할 수 있어요:
Crosshatch 프로바이더는 OpenAI의 GPT, Anthropic의 Claude 등 사용 가능한 모든 모델을 지원해요. 이 프로바이더는 Crosshatch의 커스텀 데이터 통합 동작을 제어하기 위한 쿼리 인터페이스도 지원해요. 이 프로바이더는 기존의 기반 프로바이더(@ai-sdk/openai, @ai-sdk/anthropic)를 감싸요.
자격 증명 (Credentials)
Crosshatch 프로바이더는 사용자별 토큰으로 인증돼, 개인화된 추론에 대한 권한 있는 접근을 가능하게 해요.
Crosshatch 개발자 대시보드에서 합성 및 테스트용 사용자 토큰을 얻을 수 있어요.
프로덕션 사용자 토큰은 Link SDK를 사용해 여러분의 Crosshatch 개발자 클라이언트 ID로 프로비저닝하고 접근해요.
프로바이더 인스턴스 (Provider Instance)
Crosshatch 프로바이더 인스턴스를 만들려면 createCrosshatch 함수를 사용하세요:
import createCrosshatch from '@crosshatch/ai-provider';
언어 모델 (Language Models)
프로바이더 인스턴스를 사용해 Crosshatch 모델을 만들 수 있어요.
import { createCrosshatch } from '@crosshatch/ai-provider';
const crosshatch = createCrosshatch();
모델 인스턴스를 만들려면 프로바이더 인스턴스를 호출하고 첫 번째 인자에 사용할 모델을 지정하세요. 두 번째 인자에는 사용자 인증 토큰, 원하는 컨텍스트, 모델 인자를 지정해요. Crosshatch로 권한 있는 사용자 컨텍스트와 원하는 언어 모델을 바탕으로 생성 텍스트를 얻을 수 있어요.
예시: 컨텍스트로 텍스트 생성 (Generate Text with Context)
이 예시는 gpt-4o-mini로 텍스트를 생성해요.
import { generateText } from 'ai';
import createCrosshatch from '@crosshatch/ai-provider':
const crosshatch = createCrosshatch();
const { text } = await generateText({
model: crosshatch.languageModel("gpt-4o-mini", {
token: 'YOUR_ACCESS_TOKEN',
replace: {
restaurants: {
select: ["entity_name", "entity_city", "entity_region"],
from: "personalTimeline",
where: [
{ field: "event", op: "=", value: "confirmed" },
{ field: "entity_subtype2", op: "=", value: "RESTAURANTS" }
],
groupby: ["entity_name", "entity_city", "entity_region"],
orderby: "count DESC",
limit: 5
}
}
}),
system: `The user recently ate at these restaurants: {restaurants}`,
messages: [{role: "user", content: "Where should I stay in Paris?"}]
});
예시: 컨텍스트를 바탕으로 아이템 추천 (Recommend Items based on Context)
Crosshatch를 사용해 최근 사용자 구매를 바탕으로 아이템을 재정렬해요.
import { streamText, Output } from 'ai';
import createCrosshatch from `@crosshatch/ai-provider`
const crosshatch = createCrosshatch();
const itemSummaries = [...]; // 아이템 목록
const ids = (itemSummaries?.map(({ itemId }) => itemId) ?? []) as string[];
const { elementStream } = streamText({
output: Output.array({
element: jsonSchema<{ id: string; reason: string }>({
type: "object",
properties: {
id: { type: "string", enum: ids },
reason: { type: "string", description: "Explain your ranking." },
},
}),
}),
model: crosshatch.languageModel("gpt-4o-mini", {
token,
replace: {
"orders": {
select: ["originalTimestamp", "entity_name", "order_total", "order_summary"],
from: "personalTimeline",
where: [{ field: "event", op: "=", value: "purchased" }],
orderBy: [{ field: "originalTimestamp", dir: "desc" }],
limit: 5,
},
},
}),
system: `Rerank the following items based on alignment with users recent purchases {orders}`,
messages: [{role: "user", content: "Heres a list of item: ${JSON.stringify(itemSummaries)"},],
})