1
0
Files
ai-server/ai-server.py
2025-02-10 11:24:49 +08:00

30 lines
834 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from flask import Flask, request
from openai import OpenAI
from waitress import serve
app = Flask(__name__)
client = OpenAI(base_url="https://open.bigmodel.cn/api/paas/v4", api_key="d1e97306540d12bb2f834be961fcacb1.SNBShlCxWYJCx0qZ")
@app.route('/ai_text', methods=['POST'])
def ai_text():
_input = request.get_data(as_text=True)
# 如果input值为空则返回空字符串
if not _input:
return ''
print(f'input: {_input}')
# app.logger.info(f'input: {input}')
completion = client.chat.completions.create(
model="glm-4-flash",
messages=[
{"role": "user", "content": _input},
],
stream=False
)
_output = completion.choices[0].message.content
# app.logger.info(f'output: {output}')
return _output
serve(app, host='0.0.0.0', port=6721)