TypeScript v1 레거시 언어 모델
레거시 TSv1 모델은 @foundry/models-api/language-models에서 가져옵니다. 기존 저장소를 유지할 때 사용할 수 있으며 새 TSv1 바인딩은 이미지와 스트리밍 등 추가 기능을 제공합니다. TSv2와 Python은 모델 별칭 및 프록시 경로를 사용합니다.
플랫폼 인스턴스에 AIP가 활성화되어 있고 AIP 제작 기능을 사용할 권한이 있어야 합니다. 모델과 기능 제공 여부는 플랫폼 인스턴스별로 다를 수 있습니다.
가져오기
Model Imports 사이드바를 열어 기존 모델을 확인합니다.
Resource Imports의 Add > Models에서 접근 가능한 제공 모델을 선택합니다. 사용자 모델 탭에는 Modeling Objective 및 직접 배포 모델이 따로 표시됩니다.
Confirm selection을 선택하면 localDev가 코드 바인딩을 생성합니다. 예를 들어 GPT_4o를 가져왔다면 같은 이름의 생성 바인딩을 사용합니다.
대화 기반 감정 분석
아래 예제는 text 내용이 들어 있는 contents 배열을 메시지에 사용합니다. 새 TSv1 바인딩의 content 형식과 다릅니다. 모델에 Good, Bad와 Uncertain 중 하나를 답하도록 요청하고 temperature는 0.7로 설정합니다.
import { Function, UserFacingError } from "@foundry/functions-api";
import { GPT_4o } from "@foundry/models-api/language-models";
export class LegacyLanguageModelFunctions {
@Function()
public async sentimentAnalysis(userPrompt: string): Promise<string> {
const systemPrompt =
"Provide an estimation of the sentiment the text the user has provided. " +
"You may respond with either Good, Bad, or Uncertain. Only choose Good or Bad if you are overwhelmingly " +
"sure that the text is either good or bad. If the text is neutral, or you are unable to determine, choose Uncertain.";
const response = await GPT_4o.createChatCompletion({
messages: [
{ role: "SYSTEM", contents: [{ text: systemPrompt }] },
{ role: "USER", contents: [{ text: userPrompt }] },
],
params: { temperature: 0.7 },
});
const completion = response.choices[0]?.message.content;
if (typeof completion !== "string") {
throw new UserFacingError("모델 응답에 텍스트가 없습니다.");
}
return completion;
}
}
Uncertain은 모델이 문맥의 감정을 확정할 수 없을 때 요청한 답변입니다. 응답 필드가 없는 경우의 실행 오류와 구분해야 합니다. 프롬프트가 허용 단어를 요청하더라도 반환 타입 자체는 문자열입니다.
ada-002 임베딩
TextEmbeddingAda_002를 가져오면 response.embeddings에서 벡터 목록을 읽습니다.
import { Double, Function } from "@foundry/functions-api";
import { TextEmbeddingAda_002 } from "@foundry/models-api/language-models";
export class LegacyEmbeddingFunctions {
@Function()
public async generateEmbeddingsForText(inputs: string[]): Promise<Double[][]> {
const response = await TextEmbeddingAda_002.createEmbeddings({ inputs });
return response.embeddings;
}
}
이 경로는 1,536차원 벡터를 사용합니다. 의미 기반 검색에서는 문서와 질의를 같은 모델과 차원으로 맞추며 TSv1의 KNN 2,048차원 한도 안에서 사용합니다.
호출에는 모델의 토큰 처리량 제한과 함수 실행 한도가 모두 적용됩니다. 레거시에서 새 모델로 이전하면 import 경로, 메시지 필드와 응답 포장이 바뀌므로 이전 절차를 따라 소비 코드를 함께 변경해야 합니다.