-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.py
executable file
·33 lines (27 loc) · 1013 Bytes
/
ai.py
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
# Initialize the OpenAI client
import json
import os
from dotenv import load_dotenv
from openai import OpenAI
import config
# Load environment variables from .env file
load_dotenv()
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
def get_chat_response(user_input):
new_messages = [{"role": "system", "content": config.context}]
new_messages.append(
{"role": "user", "content": "Current directory: " + config.current_path})
new_messages.extend(config.filesystem)
new_messages.extend([
{**obj, "content": json.dumps(obj["content"])}
if isinstance(obj.get("content"), dict) else obj
for obj in config.commands
])
new_messages.extend(config.dialogue_history)
new_messages.append({"role": "user", "content": user_input})
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
response_format={"type": "json_object"},
messages=new_messages
)
return json.loads(completion.choices[0].message.content)