livetalking/llm/GPT.py

22 lines
702 B
Python
Raw Normal View History

2024-04-03 18:25:03 +08:00
import openai
class GPT():
def __init__(self, model_path = 'gpt-3.5-turbo', api_key = None, base_url = None):
openai.api_key = api_key
self.model_path = model_path
if base_url != None:
openai.base_url = base_url
def chat(self, message):
response = openai.ChatCompletion.create(
model=self.model_path,
messages=[
{"role": "user", "content": message}
]
)
return response['choices'][0]['message']['content']
if __name__ == '__main__':
2024-04-03 18:26:00 +08:00
llm = GPT('gpt-3.5-turbo', 'sk-RlcPif13aQqPOU5udfkG2z0gtxD0HS','https://openai.api2d.net/v1')
2024-04-03 18:25:03 +08:00
response = llm.chat("如何应对压力?")