shigeru saito
チャット形式に変更
0e519fe
raw
history blame
1.52 kB
import codecs
import json
import time
import openai
import os
from dotenv import load_dotenv
load_dotenv()
class Llm:
def __init__(self):
print("### Step 1: Get the Assistant's ID ###")
# OpenAI API キーの設定
self.client = openai.OpenAI()
openai.api_key = os.getenv('OPENAI_API_KEY')
self.assistant_id = os.getenv('OPENAI_ASSISTANT_ID')
self.assistant = self.client.beta.assistants.retrieve(self.assistant_id)
print(self.assistant)
assistant_description = self.assistant.description
self.assistant.model = "mock"
assistant_model = self.assistant.model
if assistant_description is None:
assistant_description = f"このアシスタントは、OpenAI APIで {assistant_model} を使用して作成されました。"
def setup(self):
load_dotenv()
self.api_key = os.getenv('OPENAI_API_KEY')
self.assistant_id = os.getenv('OPENAI_ASSISTANT_ID')
self.client = openai.OpenAI()
def retrieve_assistant(self):
self.assistant = self.client.beta.assistants.retrieve(self.assistant_id)
return self.assistant
def chatcompletion(self, prompt):
import random
import csv
with open('flagged/log.csv', 'r') as file:
reader = csv.DictReader(file)
logs = [row for row in reader]
random_log = random.choice(logs)
answer = random_log['output']
return answer