mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 20:55:09 +01:00
Separate into steps and wrap filesystem access
This commit is contained in:
38
ai.py
Normal file
38
ai.py
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
import openai
|
||||
|
||||
|
||||
class AI:
|
||||
def __init__(self, **kwargs):
|
||||
self.kwargs = kwargs
|
||||
|
||||
def start(self, system, user):
|
||||
messages = [
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": user},
|
||||
]
|
||||
|
||||
return self.next(messages)
|
||||
|
||||
def fsystem(self, msg):
|
||||
return {"role": "system", "content": msg}
|
||||
|
||||
def fuser(self, msg):
|
||||
return {"role": "user", "content": msg}
|
||||
|
||||
def next(self, messages, prompt=None):
|
||||
if prompt:
|
||||
messages = messages + [{"role": "user", "content": prompt}]
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
messages=messages,
|
||||
**self.kwargs
|
||||
)
|
||||
|
||||
chat = []
|
||||
for chunk in response:
|
||||
delta = chunk['choices'][0]['delta']
|
||||
msg = delta.get('content', '')
|
||||
print(msg, end="")
|
||||
chat.append(msg)
|
||||
return messages + [{"role": "assistant", "content": "".join(chat)}]
|
||||
Reference in New Issue
Block a user