add codestral 2508
Browse filesFiles changed (2)
- app.py+47-14
- requirements.txt+2-1
26 unmodified lines272829303132431 unmodified lines464465466467468469101 unmodified lines5715725735745755761353 unmodified lines193019311932193319341935193619371938193919401941194219431944194519461947194819491950195126 unmodified linesfrom huggingface_hub import HfApiimport tempfilefrom openai import OpenAI# Gradio supported languages for syntax highlightingGRADIO_SUPPORTED_LANGUAGES = [431 unmodified lines"name": "StepFun Step-3","id": "step-3","description": "StepFun Step-3 model - AI chat assistant by 阶跃星辰 with multilingual capabilities"}]101 unmodified linesapi_key=os.getenv("STEP_API_KEY"),base_url="https://api.stepfun.com/v1")elif model_id == "moonshotai/Kimi-K2-Instruct":provider = "groq"elif model_id == "Qwen/Qwen3-235B-A22B":1353 unmodified lineselse:messages.append({'role': 'user', 'content': enhanced_query})try:completion = client.chat.completions.create(model=_current_model["id"],messages=messages,stream=True,max_tokens=16384)content = ""for chunk in completion:# Only process if chunk.choices is non-emptyif (hasattr(chunk, "choices") and chunk.choices andhasattr(chunk.choices[0], "delta") andhasattr(chunk.choices[0].delta, "content") andchunk.choices[0].delta.content is not None):content += chunk.choices[0].delta.contentsearch_status = " (with web search)" if enable_search and tavily_client else ""# Handle transformers.js output differently26 unmodified lines27282930313233431 unmodified lines465466467468469470471472473474475101 unmodified lines5775785795805815825835845851353 unmodified lines193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198426 unmodified linesfrom huggingface_hub import HfApiimport tempfilefrom openai import OpenAIfrom mistralai import Mistral# Gradio supported languages for syntax highlightingGRADIO_SUPPORTED_LANGUAGES = [431 unmodified lines"name": "StepFun Step-3","id": "step-3","description": "StepFun Step-3 model - AI chat assistant by 阶跃星辰 with multilingual capabilities"},{"name": "Codestral 2508","id": "codestral-2508","description": "Mistral Codestral model - specialized for code generation and programming tasks"}]101 unmodified linesapi_key=os.getenv("STEP_API_KEY"),base_url="https://api.stepfun.com/v1")elif model_id == "codestral-2508":# Use Mistral client for Codestral modelreturn Mistral(api_key=os.getenv("MISTRAL_API_KEY"))elif model_id == "moonshotai/Kimi-K2-Instruct":provider = "groq"elif model_id == "Qwen/Qwen3-235B-A22B":1353 unmodified lineselse:messages.append({'role': 'user', 'content': enhanced_query})try:# Handle Mistral API method differenceif _current_model["id"] == "codestral-2508":completion = client.chat.stream(model=_current_model["id"],messages=messages,max_tokens=16384)else:completion = client.chat.completions.create(model=_current_model["id"],messages=messages,stream=True,max_tokens=16384)content = ""for chunk in completion:# Handle different response formats for Mistral vs otherschunk_content = Noneif _current_model["id"] == "codestral-2508":# Mistral format: chunk.data.choices[0].delta.contentif (hasattr(chunk, "data") and chunk.data andhasattr(chunk.data, "choices") and chunk.data.choices andhasattr(chunk.data.choices[0], "delta") andhasattr(chunk.data.choices[0].delta, "content") andchunk.data.choices[0].delta.content is not None):chunk_content = chunk.data.choices[0].delta.contentelse:# OpenAI format: chunk.choices[0].delta.contentif (hasattr(chunk, "choices") and chunk.choices andhasattr(chunk.choices[0], "delta") andhasattr(chunk.choices[0].delta, "content") andchunk.choices[0].delta.content is not None):chunk_content = chunk.choices[0].delta.contentif chunk_content:content += chunk_contentsearch_status = " (with web search)" if enable_search and tavily_client else ""# Handle transformers.js output differently
8 unmodified lines91011128 unmodified linesrequestsbeautifulsoup4html2textopenai8 unmodified lines9101112138 unmodified linesrequestsbeautifulsoup4html2textopenaimistralai
app.py+47-14
requirements.txt+2-1