패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.3

tiktoken

Tiktoken은 OpenAI 모델과 함께 사용할 수 있는 BPE 토크나이저입니다. 토큰을 사용하여 텍스트를 처리하는 데 사용되는 API를 제공합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
931
좋아요
22
Pub 점수
160

패키지 설치

flutter pub add tiktoken

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Tiktoken은 OpenAI의 언어 모델을 위한 BPE(바이트 페어 인코딩) 토크나이저로, 원시 텍스트를 토큰으로 변환하여 효율적인 텍스트 처리를 가능하게 합니다. 토큰 수 계산 및 텍스트 세그멘테이션 관리를 위한 API를 제공하며, LLM 상호작용에서 입력 길이를 최적화하는 데 필수적입니다. 이 패키지는 Android, iOS, 웹, macOS, Windows, Linux 등 여러 플랫폼을 지원하여 OpenAI 모델과 통합되는 크로스플랫폼 애플리케이션에 적합합니다. Dart로 구현되어 환경 간 일관된 토크나이제이션을 보장합니다.

사용 사례

  • LLM 프롬프트를 위한 텍스트 길이 추정
  • 토큰 인식 텍스트 자르기
  • OpenAI API 클라이언트와의 통합
  • 크로스 플랫폼 AI 애플리케이션
  • 프롬프트 엔지니어링 및 최적화

주요 기능

  • BPE 기반 토큰화
  • 플랫폼에 관계없는 구현
  • OpenAI 모델 토크나이저 지원
  • 정확한 토큰 카운팅
  • 가볍고 빠름

적합한 대상

  • AI 기반 앱을 개발하는 개발자
  • 즉각적인 관리가 필요한 응용 프로그램
  • 다양한 플랫폼에서 OpenAI 모델을 사용하는 프로젝트
  • 정확한 토큰 제어가 필요한 사용자

고려 사항

  • 토큰화 개념에 대한 이해가 필요합니다
  • OpenAI 모델 고유의 어휘에 의존합니다
  • 오픈AI 모델이 아닌 경우 적합하지 않습니다
  • 텍스트 전처리 작업에 한정
  • 새로운 모델이 출시될 때 업데이트가 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

⏳ tiktoken

tiktoken is a BPE tokeniser for use with OpenAI's models.

Splitting text strings into tokens is useful because GPT models see text in the form of tokens. Knowing how many tokens are in a text string can tell you a) whether the string is too long for a text model to process and b) how much an OpenAI API call costs (as usage is priced by token). Different models use different encodings.

Features

The main Tiktoken class exposes APIs that allow you to process text using tokens, which are common sequences of character found in text. Some of the things you can do with tiktoken package are:

  • Encode text into tokens
  • Decode tokens into text
  • Compare different encodings
  • Count tokens for chat API calls

Usage

For more examples, see the /example folder.

import 'package:tiktoken/tiktoken.dart';

// Load an encoding
final encoding = encodingForModel("gpt-4");

// Tokenize text
print(encoding.encode("tiktoken is great!")); // [83, 1609, 5963, 374, 2294, 0]

// Decode tokens
print(encoding.decode([83, 1609, 5963, 374, 2294, 0])); // "tiktoken is great!"

// Alternatively, get the tokenizer by specifying encoding name:
final encoding = getEncoding("cl100k_base");
assert(enc.decode(enc.encode("hello world")) == "hello world");

Extending tiktoken

You may wish to extend Tiktoken to support new encodings. You can do this by passing around the existing model:

import 'package:tiktoken/tiktoken.dart';

// Create a base
final cl100kBase = encodingForModel("cl100k_base");

// Instantiate a new encoding and extend the base params
final encoding = Tiktoken(
  name: "cl100k_im",
  patStr: cl100kBase.patStr,
  mergeableRanks: cl100kBase.mergeableRanks,
  specialTokens: {
    ...cl100kBase.specialTokens,
    "<|im_start|>": 100264,
    "<|im_end|>": 100265,
  },
);

Additional information

This is a Dart port from the original tiktoken library written in Rust/Python.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트