ChatGPT に勝手に議論してもろていい感じの結果だけシュッと教えてもらう
ちわっす(/・ω・)/
ChatGPT のプロンプトをコネコネしてアイデアのブラッシュアップとかしてもらうこと。
ままあると思いやす。
なんかでもブラウザでやるとポチポチめんどくさいの( ・ω・)
ならばシュッと API でやるかぁ。
ってなわけで遊んでみた。
そういう話。
Google Colab でシュッといきますわよ(/・ω・)/
いつもの初手
!pip install openai
open_ai_api_key = 'sk-...........'
import openai
import json
from tenacity import retry, wait_random_exponential, stop_after_attempt
from termcolor import colored
openai.api_key = open_ai_api_key
今回やることー
ワタクシが質問を設定して処理を Do する
それに対して回答してもらう
と同時に ↓ を考えてもらう
その意見に反対しそうな人物プロフィール
その人物がしそうな批判
Functions Calling でそれらを受け取る
system role を考えてもらった人物プロフィールに差し替え
批判をユーザークエリとして設定
ループ・ザ・ループ
最終的な回答を得る
system prompt を Get する関数作る(プロンプトは適当)
def get_system_prompt(role):
return f"""- Instructions:
Please take the following all of actions 10000000% below
- Constraints:
Do all of actions 10000000%
- Actions:
1. answer any questions, doubts, or objections you receive.
2. Think of a detailed person profile (name, occupation, age, gender, personality, etc.) that might disagree with your answer.
3. Think of a specific question that a potential opponent might ask and set.
- Role:
{role}
- Output Format:
answer(string): answer any questions, doubts, or objections you receive
profile(string): Think of a detailed person profile (name, occupation, age, gender, personality, etc.) that might disagree with your answer
question(string): Think of a specific question that a potential opponent might ask and set
"""
ChatGPT 氏を呼び出す処理
@retry(wait=wait_random_exponential(min=1, max=40), stop=stop_after_attempt(3))
def call_chatgpt(messages):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k-0613",
temperature=0.5,
messages=messages,
functions=[
{
"name": "eval_answers",
"description": "Evaluate the answers obtained",
"parameters": {
"type": "object",
"properties": {
"answer": {
"type": "string",
"description": "your answer",
},
"profile": {
"type": "string",
"description": "detailed person profile who might disagree with your answer",
},
"question": {
"type": "string",
"description": "question that the likely dissenter might ask",
},
},
},
}
],
function_call={"name": "eval_answers"},
)
return response["choices"][0]["message"]
ぐりぐりループする処理
def discuss(input):
question = input
messages = [
{"role": "system", "content": get_system_prompt("good assistant")},
{"role": "user", "content": question}
]
count = 50
for i in range(count):
message = call_chatgpt(messages)
args = json.loads(message["function_call"]["arguments"])
if not args.get("profile") or not args.get("answer") or not args.get("question"):
continue
messages[0] = {"role": "system", "content": get_system_prompt(args["profile"])}
messages.append({"role": "assistant", "content": args["answer"]})
messages.append({"role": "user", "content": args["question"]})
return messages
Let's discuss !!
results = discuss('かなりエッジの効いたChatGPT ハッカソンのネタを考えてください。')
優秀なアシスタントを用意して決定稿を考えてもらう
results[0] = {"role": "system", "content": "あなたは非常に優秀なアシスタントです。"}
results[-1] = {"role": "user", "content": "Decide on the best ChatGPT Hackathon story based on the discussion so far and describe it in detail."}
final_answer = response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k-0613",
temperature=0.5,
messages=results,
)
ででーーーーーん!!
なかなかえぇやん(/・ω・)/
というわけでシュッと遊んでみた。
おしまい。
追記
提案してもらったネタをちょっとツンツンしてみた。結果は出ていない。
この記事が気に入ったらサポートをしてみませんか?