23 lines
818 B
Python
23 lines
818 B
Python
|
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__':
|
||
|
llm = GPT('gpt-3.5-turbo', 'fk193752-RlcPi2mBQqPOU5u1F8SFkG2z0gtxD0HS','https://openai.api2d.net/v1')
|
||
|
# llm = GPT('gpt-3.5-turbo', 'fk193752-RlcPi2mBQqPOU5u1F8SFkG2z0gtxD0HS','https://openai.api2d.net/v1')
|
||
|
response = llm.chat("如何应对压力?")
|