ragcar
v0.1.4
ラグカー? Kakaove Lane Pororo Architectureの自然言語加工ライブラリに基づいており、大規模な言語モデル(LLM)Openai GPTおよびNaverのHyperclova X API機能を追加しています。 RAG(RAG)に必要なツールをサポートします。
python>=3.8環境では通常動作します。
以下のコマンドを介してパッケージをインストールできます。
pip install ragcar git clone https://github.com/leewaay/ragcar.git
cd ragcar
pip install -e . 次のコマンドでRagcar使用できます。
Ragcarをインポートするには、次のコマンドを実行する必要があります。 > >> from ragcar import RagcarRagcarが現在サポートしているタスクを確認できます。 > >> from ragcar import Ragcar
> >> Ragcar . available_tools ()
"Available tools are ['tokenization', 'sentence_embedding', 'sentence_similarity', 'semantic_search', 'text_generation', 'text_segmentation']" > >> Ragcar . available_models ( "text_generation" )
'Available models for text_generation are ([src]: openai, [model]: gpt-4-turbo-preview, gpt-4, gpt-3.5-turbo, MODELS_SUPPORTED(https://platform.openai.com/docs/models)), ([src]: clova, [model]: YOUR_MODEL(https://www.ncloud.com/product/aiService/clovaStudio))'toolファクターの前に見たsrc引数を配置できます。 > >> from ragcar . utils import PromptTemplate
> >> prompt_template = PromptTemplate ( "사용자: {input} 수도는? n AI:" )
> >> generator = Ragcar ( tool = "text_generation" , src = "openai" , prompt_template = prompt_template , formatting = True ) > >> generator ( input = "대한민국" )
{
'id' : 'openai-dad4969f-6f0d-4413-a748-26d05cc0e73d' ,
'model' : 'gpt-4-turbo-preview' ,
'content' : '대한민국의 수도는 서울입니다.' ,
'finish_reason' : 'stop' ,
'input_tokens' : 23 ,
'output_tokens' : 15 ,
'total_tokens' : 38 ,
'predicted_cost' : 0.0015899999999999998 ,
'response_time' : 1.0608701705932617
}特定のsrcには、セキュリティとメンテナンスを必要とする環境変数(例: APIキー)が必要であり、次の3つの方法のいずれかとして設定できます。
.envファイル:プロジェクトのトップルートで.ENVファイルを作成し、必要な環境変数値を入力します。 export OPENAI_API_KEY= ' sk-... 'model因子値:必要な環境変数をモデル係数値に直接入力します。 (デフォルトmodelに加えて追加する必要がある場合でも、同じものを適用します) > >> Ragcar . available_customizable_src ( "text_generation" )
"Available customizable src for text_generation are ['clova', 'openai']"
> >> Ragcar . available_model_fields ( "clova" )
'Available fields for clova are ([field]: model_n, [type]: str), ([field]: api_key, [type]: str), ([field]: app_key, [type]: str)' > >> generator = Ragcar (
tool = "text_generation" ,
src = "clova" ,
model = {
"model_n" : "YOUR_API_URL" ,
"api_key" : "YOUR_APIGW-API-KEY" ,
"app_key" : "YOUR_CLOVASTUDIO-API-KEY"
},
prompt_template = prompt_template ,
formatting = True
)
> >> generator ( input = "대한민국" )
{
'id' : 'clova-3c241fa1-f01e-4738-b208-5bcb35daad42' ,
'model' : 'HCX-003' ,
'content' : '대한민국 수도는 서울입니다.' ,
'finish_reason' : 'stop_before' ,
'input_tokens' : 12 ,
'output_tokens' : 8 ,
'total_tokens' : 20 ,
'predicted_cost' : 0.6 ,
'response_time' : 0.7090704441070557 ,
'ai_filter' : []
}Tool使用に関するメモpredicted_cost predicted_cost 、 text_generationツールを使用するときに使用されるAPIに応じて異なる方法で計算されます。 Openaiの場合、 predicted_costはドル(USD)によって計算され、Clovaは元の(KRW)として計算されます。これは、各サービスの請求システムが異なるためです。現在のモデルによる特定の充電情報は、base.pyファイルにあります。
Clova srcを使用してText_Generation toolを使用する場合、公式パラメーターと比較して変更された変更に注意してください。
パラメーター名の変更:
top_kの代わりにpresence_penaltyを使用してください。repeat_penaltyの代わりにfrequency_penalty使用してください。パラメーター値範囲:
0.0 < temperature < 1.00.0 < top_p < 1.00 < presence_penalty < 1280.0 < frequency_penalty < 10.0cente_embeddingの例チェック
ご質問や意見がある場合は、問題を残してください。
@misc { pororo ,
author = { Heo, Hoon and Ko, Hyunwoong and Kim, Soohwan and
Han, Gunsoo and Park, Jiwoo and Park, Kyubyong } ,
title = { PORORO: Platform Of neuRal mOdels for natuRal language prOcessing } ,
howpublished = { url{https://github.com/kakaobrain/pororo} } ,
year = { 2021 } ,
} @inproceedings { reimers-2019-sentence-bert ,
title = " Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks " ,
author = " Reimers, Nils and Gurevych, Iryna " ,
booktitle = " Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing " ,
month = " 11 " ,
year = " 2019 " ,
publisher = " Association for Computational Linguistics " ,
url = " https://arxiv.org/abs/1908.10084 " ,
}