|
|
|
|
|
|
|
|
|
|
|
import uvicorn |
|
|
import json |
|
|
import requests |
|
|
from flask import Flask, request, jsonify |
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
rq = requests.sessions.Session() |
|
|
|
|
|
model_names = [ |
|
|
"meta-llama/Meta-Llama-3-70B-Instruct", |
|
|
"meta-llama/Meta-Llama-3-8B-Instruct", |
|
|
"mistralai/Mixtral-8x22B-Instruct-v0.1", |
|
|
"mistralai/Mixtral-8x22B-v0.1", |
|
|
"microsoft/WizardLM-2-8x22B", |
|
|
"microsoft/WizardLM-2-7B", |
|
|
"HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1", |
|
|
"google/gemma-1.1-7b-it", |
|
|
"databricks/dbrx-instruct", |
|
|
"mistralai/Mixtral-8x7B-Instruct-v0.1", |
|
|
"mistralai/Mistral-7B-Instruct-v0.2", |
|
|
"meta-llama/Llama-2-70b-chat-hf", |
|
|
"cognitivecomputations/dolphin-2.6-mixtral-8x7b", |
|
|
"codellama/CodeLlama-70b-Instruct-hf" |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def DeepinFra(Api:str, messages:list ,model:str, max_tokens: int = 512, temperature: float = 0.7): |
|
|
|
|
|
url = "https://api.deepinfra.com/v1/openai/chat/completions" |
|
|
headers ={ |
|
|
"Authorization" : f"Bearer {Api}" |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = json.dumps( |
|
|
{ |
|
|
'model': model, |
|
|
'messages': messages, |
|
|
'temperature': temperature, |
|
|
'max_tokens': max_tokens, |
|
|
'stop': [], |
|
|
'stream': False |
|
|
}, separators=(',', ':') |
|
|
) |
|
|
|
|
|
try: |
|
|
result = rq.post(url=url, headers=headers, data=data) |
|
|
|
|
|
return result.json()['choices'][0]['message']['content'] |
|
|
except: |
|
|
|
|
|
|
|
|
return "Response content: " + result.text |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/generate-text-deep", methods=["POST"]) |
|
|
def generate_text(): |
|
|
data = request.json |
|
|
message = data.get("message") |
|
|
Api = data.get("api_key") |
|
|
model_name = data.get("model_name", "mistralai/Mixtral-8x22B-Instruct-v0.1") |
|
|
max_tokens = data.get("max_tokens", 512) |
|
|
temperature = data.get("temperature", 0.7) |
|
|
|
|
|
if not message or not Api: |
|
|
return jsonify({"error": "Missing required fields"}), 400 |
|
|
|
|
|
response = DeepinFra(Api=Api , messages=message, model=model_name, max_tokens=max_tokens, temperature=temperature) |
|
|
|
|
|
return jsonify({"response": response}), 200 |
|
|
|