File size: 1,519 Bytes
0e519fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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