add codestral 2508
Browse files- app.py +47 -14
- requirements.txt +2 -1
app.py
CHANGED
@@ -27,6 +27,7 @@ from tavily import TavilyClient
|
|
27 |
from huggingface_hub import HfApi
|
28 |
import tempfile
|
29 |
from openai import OpenAI
|
|
|
30 |
|
31 |
# Gradio supported languages for syntax highlighting
|
32 |
GRADIO_SUPPORTED_LANGUAGES = [
|
@@ -464,6 +465,11 @@ AVAILABLE_MODELS = [
|
|
464 |
"name": "StepFun Step-3",
|
465 |
"id": "step-3",
|
466 |
"description": "StepFun Step-3 model - AI chat assistant by 阶跃星辰 with multilingual capabilities"
|
|
|
|
|
|
|
|
|
|
|
467 |
}
|
468 |
]
|
469 |
|
@@ -571,6 +577,9 @@ def get_inference_client(model_id, provider="auto"):
|
|
571 |
api_key=os.getenv("STEP_API_KEY"),
|
572 |
base_url="https://api.stepfun.com/v1"
|
573 |
)
|
|
|
|
|
|
|
574 |
elif model_id == "moonshotai/Kimi-K2-Instruct":
|
575 |
provider = "groq"
|
576 |
elif model_id == "Qwen/Qwen3-235B-A22B":
|
@@ -1930,22 +1939,46 @@ This will help me create a better design for you."""
|
|
1930 |
else:
|
1931 |
messages.append({'role': 'user', 'content': enhanced_query})
|
1932 |
try:
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1939 |
content = ""
|
1940 |
for chunk in completion:
|
1941 |
-
#
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1949 |
search_status = " (with web search)" if enable_search and tavily_client else ""
|
1950 |
|
1951 |
# Handle transformers.js output differently
|
|
|
27 |
from huggingface_hub import HfApi
|
28 |
import tempfile
|
29 |
from openai import OpenAI
|
30 |
+
from mistralai import Mistral
|
31 |
|
32 |
# Gradio supported languages for syntax highlighting
|
33 |
GRADIO_SUPPORTED_LANGUAGES = [
|
|
|
465 |
"name": "StepFun Step-3",
|
466 |
"id": "step-3",
|
467 |
"description": "StepFun Step-3 model - AI chat assistant by 阶跃星辰 with multilingual capabilities"
|
468 |
+
},
|
469 |
+
{
|
470 |
+
"name": "Codestral 2508",
|
471 |
+
"id": "codestral-2508",
|
472 |
+
"description": "Mistral Codestral model - specialized for code generation and programming tasks"
|
473 |
}
|
474 |
]
|
475 |
|
|
|
577 |
api_key=os.getenv("STEP_API_KEY"),
|
578 |
base_url="https://api.stepfun.com/v1"
|
579 |
)
|
580 |
+
elif model_id == "codestral-2508":
|
581 |
+
# Use Mistral client for Codestral model
|
582 |
+
return Mistral(api_key=os.getenv("MISTRAL_API_KEY"))
|
583 |
elif model_id == "moonshotai/Kimi-K2-Instruct":
|
584 |
provider = "groq"
|
585 |
elif model_id == "Qwen/Qwen3-235B-A22B":
|
|
|
1939 |
else:
|
1940 |
messages.append({'role': 'user', 'content': enhanced_query})
|
1941 |
try:
|
1942 |
+
# Handle Mistral API method difference
|
1943 |
+
if _current_model["id"] == "codestral-2508":
|
1944 |
+
completion = client.chat.stream(
|
1945 |
+
model=_current_model["id"],
|
1946 |
+
messages=messages,
|
1947 |
+
max_tokens=16384
|
1948 |
+
)
|
1949 |
+
else:
|
1950 |
+
completion = client.chat.completions.create(
|
1951 |
+
model=_current_model["id"],
|
1952 |
+
messages=messages,
|
1953 |
+
stream=True,
|
1954 |
+
max_tokens=16384
|
1955 |
+
)
|
1956 |
content = ""
|
1957 |
for chunk in completion:
|
1958 |
+
# Handle different response formats for Mistral vs others
|
1959 |
+
chunk_content = None
|
1960 |
+
if _current_model["id"] == "codestral-2508":
|
1961 |
+
# Mistral format: chunk.data.choices[0].delta.content
|
1962 |
+
if (
|
1963 |
+
hasattr(chunk, "data") and chunk.data and
|
1964 |
+
hasattr(chunk.data, "choices") and chunk.data.choices and
|
1965 |
+
hasattr(chunk.data.choices[0], "delta") and
|
1966 |
+
hasattr(chunk.data.choices[0].delta, "content") and
|
1967 |
+
chunk.data.choices[0].delta.content is not None
|
1968 |
+
):
|
1969 |
+
chunk_content = chunk.data.choices[0].delta.content
|
1970 |
+
else:
|
1971 |
+
# OpenAI format: chunk.choices[0].delta.content
|
1972 |
+
if (
|
1973 |
+
hasattr(chunk, "choices") and chunk.choices and
|
1974 |
+
hasattr(chunk.choices[0], "delta") and
|
1975 |
+
hasattr(chunk.choices[0].delta, "content") and
|
1976 |
+
chunk.choices[0].delta.content is not None
|
1977 |
+
):
|
1978 |
+
chunk_content = chunk.choices[0].delta.content
|
1979 |
+
|
1980 |
+
if chunk_content:
|
1981 |
+
content += chunk_content
|
1982 |
search_status = " (with web search)" if enable_search and tavily_client else ""
|
1983 |
|
1984 |
# Handle transformers.js output differently
|
requirements.txt
CHANGED
@@ -9,4 +9,5 @@ opencv-python
|
|
9 |
requests
|
10 |
beautifulsoup4
|
11 |
html2text
|
12 |
-
openai
|
|
|
|
9 |
requests
|
10 |
beautifulsoup4
|
11 |
html2text
|
12 |
+
openai
|
13 |
+
mistralai
|