Files
dify-plugin-sdks/python/tests/__mock_server/openai.py
Yeuoly cc4a611b0c feat: enhance PluginRunner to build plugins from source directories (#150)
* feat: enhance PluginRunner to build plugins from source directories

- Added functionality to the PluginRunner to detect if the plugin package path is a directory and build the plugin accordingly.
- Introduced a new method `_build_plugin` to handle the building process and log the output.
- Implemented resource cleanup for temporary directories used during the build process.
- Updated integration tests to reflect changes in the mock server configuration by using a constant for the server port.

* fix: linter
2025-05-27 14:04:26 +08:00

44 lines
1.4 KiB
Python

import json
import flask.cli
from flask import Flask, Response, jsonify, request
from tests.consts.mockserver import OPENAI_MOCK_SERVER_PORT
flask.cli.show_server_banner = lambda *args: None
def openai_server_mock():
app = Flask(__name__)
@app.route("/v1/chat/completions", methods=["POST"])
def chat_completions():
request_body = request.get_json(force=True)
if request_body.get("stream"):
def stream_response():
yield "data: "
yield json.dumps({"choices": [{"message": {"content": "Hello, world!"}}]})
yield "\n\n"
return Response(stream_response(), mimetype="text/event-stream")
else:
return jsonify(
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1715806438,
"model": request_body["model"],
"choices": [
{
"message": {"role": "assistant", "content": "Hello, world!"},
"index": 0,
"finish_reason": "stop",
}
],
"usage": {"prompt_tokens": 10, "completion_tokens": 10, "total_tokens": 20},
}
)
app.run(port=OPENAI_MOCK_SERVER_PORT)