1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

設定関連はconfigファイルにまとめるといいですよ.md

Posted at

modelやmodelのparams, promptの設定などはpythonファイルでするのではなく、config.jsonに書いて、それを呼び出すように書くといいですよ。

以下のような感じです。

例:

main.py
import json
from pathlib import Path

# config.json を読み込む
with open('config.json', 'r', encoding='utf-8') as f:
    config = json.load(f)

# 選択されたパラメータファイルを読み込む
params_file = config['params_file']
with open(params_file, 'r', encoding='utf-8') as f:
    params = json.load(f)

# 選択されたプロンプトファイルを読み込む
prompt_file = config['prompt_file']
with open(prompt_file, 'r', encoding='utf-8') as f:
    prompt_template = f.read()

# 設定を使ってモデルを初期化
model_name = config['model']
temperature = params['temperature']
max_tokens = params['max_tokens']

print(f"モデル: {model_name}")
print(f"Temperature: {temperature}")
print(f"Max tokens: {max_tokens}")
print(f"プロンプト: {prompt_template[:50]}...")
config.json
{
  "model": "gpt-4",
  "params_file": "params1.json",
  "prompt_file": "prompt1.md"
}
params1.json
{
  "temperature": 0.7,
  "max_tokens": 1000,
  "top_p": 0.9,
  "frequency_penalty": 0.0,
  "presence_penalty": 0.0
}
params2.json
{
  "temperature": 0.2,
  "max_tokens": 2000,
  "top_p": 0.95,
  "frequency_penalty": 0.5,
  "presence_penalty": 0.5
}
prompt1.md
あなたは親切で知識豊富なアシスタントです。
ユーザーの質問に対して、正確で分かりやすい回答を提供してください。
prompt2.md
あなたはプロフェッショナルな技術コンサルタントです。
技術的な質問に対して、具体的な例とコードサンプルを含めて回答してください。
必要に応じて、ベストプラクティスやアンチパターンについても言及してください。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?