Skip to content

Instantly share code, notes, and snippets.

@laiso
Last active June 14, 2023 14:09
Show Gist options
  • Save laiso/c088a94b8c6c4590743de5600c5d9529 to your computer and use it in GitHub Desktop.
Save laiso/c088a94b8c6c4590743de5600c5d9529 to your computer and use it in GitHub Desktop.
ダジャレを送ると採点と評価をしてくれるプログラム https://zenn.dev/laiso/articles/b516dc215a2e87
import sys
import openai
import json
def run_conversation(input):
content = f"""
ダジャレの面白さをAからEに評価して、評価の理由を論理的にコメントします。
ダジャレ:{input}
"""
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
temperature=0.0,
messages=[
{"role": "user", "content": content}],
functions=[
{
"name": "send_dajare_result",
"description": "ダジャレの面白さをAからEに評価してコメントします",
"parameters": {
"type": "object",
"properties": {
"comment": {
"type": "string",
"description": "コメント内容",
},
"rank": {
"type": "string",
"enum": ["A", "B", "C", "D", "E"],
"description": "評価ラベルです。Aが最高、Eが最低です",
},
},
"required": ["comment", "rank"],
},
}
],
function_call={"name": "send_dajare_result"},
)
message = response["choices"][0]["message"]
result = json.loads(message["function_call"]["arguments"])
print("評価:"+result["rank"])
print("コメント:"+result["comment"])
run_conversation(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment