Skip to content

feat: 添加对Xinference模型的支持 #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ UNBOUND_API_KEY=
SiliconFLOW_ENDPOINT=https://api.siliconflow.cn/v1/
SiliconFLOW_API_KEY=

XINFERENCE_OPENAI_ENDPOINT=https://api.xinference.com/v1
XINFERENCE_API_KEY=
XINFERENCE_MODEL=
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for expected values for XINFERENCE_MODEL environment variable


# Set to false to disable anonymized telemetry
ANONYMIZED_TELEMETRY=false

Expand Down
28 changes: 27 additions & 1 deletion src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"google": "Google",
"alibaba": "Alibaba",
"moonshot": "MoonShot",
"unbound": "Unbound AI"
"unbound": "Unbound AI",
"xinference": "XInference",
}


Expand Down Expand Up @@ -183,6 +184,27 @@ def get_llm_model(provider: str, **kwargs):
model_name=kwargs.get("model_name", "Qwen/QwQ-32B"),
temperature=kwargs.get("temperature", 0.0),
)
elif provider == "xinference":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing entry for "xinference" in PROVIDER_DISPLAY_NAMES dictionary

if not kwargs.get("base_url", ""):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API key retrieval uses a different environment variable pattern than what's defined in .env.example

base_url = os.getenv("XINFERENCE_OPENAI_ENDPOINT", "https://api.xinference.com/v1")
else:
base_url = kwargs.get("base_url")

if not kwargs.get("api_key", ""):
api_key = os.getenv("XINFERENCE_API_KEY", "")
else:
api_key = kwargs.get("api_key")

if not kwargs.get("model_name", ""):
model_name = os.getenv("XINFERENCE_MODEL", "qwen2.5-instruct")
else:
model_name = kwargs.get("model_name")
return ChatOpenAI(
model=model_name,
temperature=kwargs.get("temperature", 0.0),
base_url=base_url,
api_key=api_key,
)
else:
raise ValueError(f"Unsupported provider: {provider}")

Expand Down Expand Up @@ -234,6 +256,10 @@ def get_llm_model(provider: str, **kwargs):
"Pro/THUDM/chatglm3-6b",
"Pro/THUDM/glm-4-9b-chat",
],
"xinference": ["qwen2.5-instruct", "qwen2.5", "qwen2.5-coder", "qwen2.5-coder-instruct", "qwen2.5-instruct-1m",
"qwen2.5-vl-instruct", "deepseek", "deepseek-chat", "deepseek-coder", "deepseek-coder-instruct",
"deepseek-r1", "deepseek-v2", "deepseek-v2-chat", "deepseek-v2-chat-0628", "deepseek-v2.5",
"deepseek-v3", "deepseek-vl-chat", "deepseek-vl2"]
}


Expand Down