add GPT 5
Browse files465 unmodified lines46646746846947047147213 unmodified lines48648748848949049185 unmodified lines5775785795805815825835841465 unmodified lines205020512052205320542055465 unmodified lines"id": "qwen3-coder-30b-a3b-instruct","description": "Qwen3-Coder-30B-A3B-Instruct model for advanced code generation via Alibaba Cloud DashScope API"},{"name": "StepFun Step-3","id": "step-3",13 unmodified lines"name": "GPT-OSS-20B","id": "openai/gpt-oss-20b","description": "OpenAI GPT-OSS-20B model for code generation and general tasks"}]85 unmodified linesapi_key=os.getenv("DASHSCOPE_API_KEY"),base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",)elif model_id == "step-3":# Use StepFun API client for Step-3 modelreturn OpenAI(1465 unmodified linesmessages=messages,max_tokens=16384)else:completion = client.chat.completions.create(model=_current_model["id"],465 unmodified lines46646746846947047113 unmodified lines48548648748848949049149249349449585 unmodified lines5815825835845855865875885895905911465 unmodified lines20572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163465 unmodified lines"id": "qwen3-coder-30b-a3b-instruct","description": "Qwen3-Coder-30B-A3B-Instruct model for advanced code generation via Alibaba Cloud DashScope API"},{"name": "StepFun Step-3","id": "step-3",13 unmodified lines"name": "GPT-OSS-20B","id": "openai/gpt-oss-20b","description": "OpenAI GPT-OSS-20B model for code generation and general tasks"},{"name": "GPT-5","id": "gpt-5","description": "OpenAI GPT-5 model for advanced code generation and general tasks"}]85 unmodified linesapi_key=os.getenv("DASHSCOPE_API_KEY"),base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",)elif model_id == "gpt-5":# Use OpenAI client for GPT-5 modelreturn OpenAI(api_key=os.getenv("OPENAI_API_KEY"),)elif model_id == "step-3":# Use StepFun API client for Step-3 modelreturn OpenAI(1465 unmodified linesmessages=messages,max_tokens=16384)elif _current_model["id"] == "gpt-5":# Special handling for GPT-5 model - no streaming due to organization verification requirementcompletion = client.chat.completions.create(model="gpt-5",messages=messages,max_completion_tokens=16384)# Handle non-streaming responsecontent = completion.choices[0].message.contentclean_code = remove_code_block(content)# Apply image generation if enabled and this is HTML contentfinal_content = contentif enable_image_generation and language == "html" and (clean_code.strip().startswith('<!DOCTYPE html>') or clean_code.strip().startswith('<html')):# Create search/replace blocks for image replacement based on images found in codeimage_replacement_blocks = create_image_replacement_blocks(content, query)if image_replacement_blocks:# Apply the image replacements using existing search/replace logicfinal_content = apply_search_replace_changes(content, image_replacement_blocks)_history.append([query, final_content])if language == "transformers.js":files = parse_transformers_js_output(clean_code)if files['index.html'] and files['index.js'] and files['style.css']:# Apply image generation if enabledif enable_image_generation:# Create search/replace blocks for image replacement based on images found in codeimage_replacement_blocks = create_image_replacement_blocks(files['index.html'], query)if image_replacement_blocks:# Apply the image replacements using existing search/replace logicfiles['index.html'] = apply_search_replace_changes(files['index.html'], image_replacement_blocks)formatted_output = format_transformers_js_output(files)yield {code_output: formatted_output,history: _history,sandbox: send_to_sandbox(files['index.html']),history_output: history_to_chatbot_messages(_history),}else:yield {code_output: clean_code,history: _history,sandbox: "<div style='padding:1em;color:#888;text-align:center;'>Error parsing transformers.js output. Please try again.</div>",history_output: history_to_chatbot_messages(_history),}elif language == "svelte":files = parse_svelte_output(clean_code)if files['src/App.svelte'] and files['src/app.css']:formatted_output = format_svelte_output(files)yield {code_output: formatted_output,history: _history,sandbox: "<div style='padding:1em;color:#888;text-align:center;'>Preview is only available for HTML. Please download your Svelte code using the download button above.</div>",history_output: history_to_chatbot_messages(_history),}else:yield {code_output: clean_code,history: _history,sandbox: "<div style='padding:1em;color:#888;text-align:center;'>Preview is only available for HTML. Please download your Svelte code using the download button above.</div>",history_output: history_to_chatbot_messages(_history),}else:if has_existing_content and not (clean_code.strip().startswith("<!DOCTYPE html>") or clean_code.strip().startswith("<html")):last_content = _history[-1][1] if _history and len(_history[-1]) > 1 else ""modified_content = apply_search_replace_changes(last_content, clean_code)clean_content = remove_code_block(modified_content)# Apply image generation if enabled and this is HTML contentif enable_image_generation and language == "html" and (clean_content.strip().startswith('<!DOCTYPE html>') or clean_content.strip().startswith('<html')):# Create search/replace blocks for image replacement based on images found in codeimage_replacement_blocks = create_image_replacement_blocks(clean_content, query)if image_replacement_blocks:# Apply the image replacements using existing search/replace logicclean_content = apply_search_replace_changes(clean_content, image_replacement_blocks)yield {code_output: clean_content,history: _history,sandbox: send_to_sandbox(clean_content) if language == "html" else "<div style='padding:1em;color:#888;text-align:center;'>Preview is only available for HTML. Please download your code using the download button above.</div>",history_output: history_to_chatbot_messages(_history),}else:# Apply image generation if enabled and this is HTML contentfinal_content = clean_codeif enable_image_generation and language == "html" and (final_content.strip().startswith('<!DOCTYPE html>') or final_content.strip().startswith('<html')):# Create search/replace blocks for image replacement based on images found in codeimage_replacement_blocks = create_image_replacement_blocks(final_content, query)if image_replacement_blocks:# Apply the image replacements using existing search/replace logicfinal_content = apply_search_replace_changes(final_content, image_replacement_blocks)yield {code_output: final_content,history: _history,sandbox: send_to_sandbox(final_content) if language == "html" else "<div style='padding:1em;color:#888;text-align:center;'>Preview is only available for HTML. Please download your code using the download button above.</div>",history_output: history_to_chatbot_messages(_history),}returnelse:completion = client.chat.completions.create(model=_current_model["id"],
app.py+111-3