mirror of
https://github.com/harry0703/MoneyPrinterTurbo.git
synced 2026-02-21 08:27:22 +08:00
add qwen api
This commit is contained in:
parent
27d081ae54
commit
985378838b
@ -9,6 +9,7 @@ from openai import AzureOpenAI
|
||||
from app.config import config
|
||||
|
||||
|
||||
|
||||
def _generate_response(prompt: str) -> str:
|
||||
content = ""
|
||||
llm_provider = config.app.get("llm_provider", "openai")
|
||||
@ -43,6 +44,10 @@ def _generate_response(prompt: str) -> str:
|
||||
model_name = config.app.get("azure_model_name")
|
||||
base_url = config.app.get("azure_base_url", "")
|
||||
api_version = config.app.get("azure_api_version", "2024-02-15-preview")
|
||||
elif llm_provider == "qwen":
|
||||
api_key = config.app.get("qwen_api_key")
|
||||
model_name = config.app.get("qwen_model_name")
|
||||
base_url = "***"
|
||||
else:
|
||||
raise ValueError("llm_provider is not set, please set it in the config.toml file.")
|
||||
|
||||
@ -52,6 +57,20 @@ def _generate_response(prompt: str) -> str:
|
||||
raise ValueError(f"{llm_provider}: model_name is not set, please set it in the config.toml file.")
|
||||
if not base_url:
|
||||
raise ValueError(f"{llm_provider}: base_url is not set, please set it in the config.toml file.")
|
||||
|
||||
|
||||
import dashscope
|
||||
|
||||
if llm_provider == "qwen":
|
||||
dashscope.api_key = api_key
|
||||
response = dashscope.Generation.call(
|
||||
model=model_name,
|
||||
messages=[{"role": "user", "content": prompt}]
|
||||
)
|
||||
content=response["output"]["text"]
|
||||
print(content)
|
||||
return content.replace("\n", "")
|
||||
|
||||
|
||||
if llm_provider == "azure":
|
||||
client = AzureOpenAI(
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
pexels_api_keys = []
|
||||
|
||||
# 如果你没有 OPENAI API Key,可以使用 g4f 代替,或者使用国内的 Moonshot API
|
||||
llm_provider="openai" # "openai" or "moonshot" or "oneapi" or "g4f" or "azure"
|
||||
llm_provider="openai" # "openai" or "moonshot" or "oneapi" or "g4f" or "azure" or "qwen"
|
||||
|
||||
########## OpenAI API Key
|
||||
# Visit https://openai.com/api/ for details on obtaining an API key.
|
||||
@ -40,6 +40,11 @@
|
||||
azure_model_name="gpt-35-turbo" # replace with your model deployment name
|
||||
azure_api_version = "2024-02-15-preview"
|
||||
|
||||
########## qwen API Key, you need to pip install dashscope firstly
|
||||
# Visit https://tongyi.aliyun.com/qianwen/ to get more details
|
||||
qwen_api_key = ""
|
||||
qwen_model_name = "qwen-max"
|
||||
|
||||
|
||||
# Subtitle Provider, "edge" or "whisper"
|
||||
# If empty, the subtitle will not be generated
|
||||
|
||||
Loading…
Reference in New Issue
Block a user