Commit Graph
271 Commits
Author SHA1 Message Date
chenhuawang-04andClaude Opus 4.6 53ab1fd086 fix: improve final image selection in stream processor
When n=1, the stream processor locks onto the first image received
as target. If a different image gets its final version first,
completed >= n breaks the WebSocket loop, but the processor saves
the target's medium-quality data as "final".

Now checks if the target actually has is_final=True before selecting
it. If not, falls back to the highest quality image available.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 16:13:55 +08:00
Chenyme 1d29bc44c8 Merge pull request #234 from chenyme/enhance_tool
feat: enhance StreamProcessor with tool stream handling
2026-02-26 14:04:00 +08:00
Chenyme 5aa29aad02 feat: enhance StreamProcessor with tool stream handling 2026-02-26 14:00:19 +08:00
Chenyme 059e9d7147 Merge pull request #232 from chenyme/fix_image
refactor: update image handling in chat completions and services
2026-02-26 11:41:04 +08:00
Chenyme c2989e8579 refactor: update image handling in chat completions and services 2026-02-26 11:38:25 +08:00
Chenyme 3d755f1bb4 Merge pull request #230 from chenyme/fix_message_none
feat: enhance chat service with fallback prompt for attachments
2026-02-26 11:22:35 +08:00
Chenyme 02d4f91c4a feat: enhance chat service with fallback prompt for attachments and semaphore management 2026-02-26 11:20:46 +08:00
Chenyme f7f8f973a0 Merge pull request #226 from reloadggg/pr/function-calling
feat: add OpenAI-compatible function calling (tools / tool_calls)
2026-02-26 11:01:26 +08:00
Chenyme cf4942d68b Merge branch 'main' into pr/function-calling 2026-02-26 09:49:16 +08:00
Chenyme 4b4620cc6e Merge pull request #222 from Yuyang-0/codex/openclaw-chat-fix
fix: 兼容 OpenAI 风格消息 content 对象与 assistant 空 content,避免 400 校验错误
2026-02-26 09:43:15 +08:00
Chenyme 2493ea2e4c docs: delete CLAUDE.md 2026-02-26 09:42:18 +08:00
zxc123developer 1d49377bee feat: add OpenAI-compatible function calling (tools / tool_calls)
Implements prompt-based tool call emulation to support the OpenAI
function calling API (tools / tool_calls / tool_choice), fixing #219.

Changes:
- New module app/services/grok/utils/tool_call.py
  - build_tool_prompt(): inject tool definitions into system prompt
    using <tool_call> XML tag format
  - parse_tool_calls(): regex-extract <tool_call> blocks and convert
    to OpenAI-format tool_calls list
  - format_tool_history(): convert multi-turn tool messages to text
    for Grok's single-message API
  - build_tool_overrides(): experimental passthrough mode helper
- app/api/v1/chat.py
  - Add tool_calls, tool_call_id, name fields to MessageItem
  - Add tools, tool_choice, parallel_tool_calls to ChatCompletionRequest
  - Add "tool" to VALID_ROLES
  - Validate tool role messages (require tool_call_id)
  - Validate tools format and tool_choice values
- app/services/grok/services/chat.py
  - MessageExtractor: preprocess tool history and inject tool prompt
  - StreamProcessor: buffer tokens when tools active, emit tool_calls
    chunk with finish_reason="tool_calls" after stream ends
  - CollectProcessor: parse tool_calls from final content
  - GrokChatService/ChatService: forward tools params through the stack
- config.defaults.toml: add tool_call_mode = "prompt" config key
  (supports "prompt" default and experimental "passthrough" mode)

Backward compatible: requests without tools are completely unaffected.
2026-02-24 21:49:25 +08:00
guanyuyang 0356bb4ad8 Clarify PR flow and tool handling 2026-02-24 08:16:30 +08:00
guanyuyang 67fc2cc475 fix: 兼容 OpenAI-like content 对象与 assistant null content 2026-02-24 07:53:14 +08:00
Chenyme 186e6bb20b Merge pull request #209 from BytePioneer-AI/fix/issue-206-base64-path
fix: support relative asset paths in base64 download flow
2026-02-21 21:25:41 +08:00
Chenyme d5bd81ece0 Merge pull request #204 from FakerL/fix/sql-ssl-connect-args
fix: handle SSL query params for asyncpg and aiomysql
2026-02-21 21:11:05 +08:00
Chenyme fdf1f8494f Merge pull request #200 from fno2010/grok-image-response-format
fix: standardize image generation response to OpenAI ChatCompletion format
2026-02-21 21:06:32 +08:00
BytePioneer-AI 68895f0f31 fix: support relative asset paths in base64 download flow 2026-02-21 14:12:42 +08:00
Jensen Zhang e5e9225898 refactor: extract response formatting utilities and apply to image services
- Add app/services/grok/utils/response.py with reusable utilities:
  - make_response_id(): generate unique response IDs
  - make_chat_chunk(): build OpenAI-compatible chat completion chunks
  - make_chat_response(): build non-streaming chat completion responses
  - wrap_image_content(): wrap image content in markdown format
- Refactor image.py and image_edit.py to use these utilities
- Simplify chat.py non-streaming responses with make_chat_response()
2026-02-21 09:51:48 +08:00
Zhi YangandClaude Opus 4.6 c818bdfa2d fix: handle SSL query params for asyncpg and aiomysql drivers
Both asyncpg and aiomysql reject SSL-related query parameters (sslmode,
ssl-mode, ssl) when passed through SQLAlchemy URLs. This extracts SSL
mode from the URL, normalizes it per backend, and passes proper
connect_args instead.

- Postgres: passes libpq-style mode string via connect_args={"ssl": mode}
- MySQL: builds an SSLContext matching the requested verification level
- Supports cross-dialect aliases (e.g. verify-full works for both backends)
- Adds mariadb+aiomysql:// prefix handling
- Raises ValueError on unrecognized SSL modes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 22:23:31 +00:00
Jensen Zhang 679b94622f fix: standardize image generation response to OpenAI ChatCompletion format
- Standardize non-streaming response from 'data' to 'choices' format
- Add chat_format parameter to image services
- Support SSE streaming with OpenAI chat.completion.chunk format
- Fix partial_image events to use chat format
- Pass chat_format to _stream_ws in _stream_retry
- Wrap image content in markdown format for chat completions
2026-02-20 13:59:14 +08:00
Chenyme 1638baa07e docs: update image dimensions in README files 2026-02-20 01:22:30 +08:00
Chenyme 0e73fab4e4 style: enhance chat UI with new image retry functionality and improved layout; update login redirection to chat page 2026-02-20 00:55:54 +08:00
Chenyme 46824f3243 Merge pull request #197 from chenyme/chat-web
chore: update version to 1.5.0 and add public chat endpoint
2026-02-20 00:31:56 +08:00
Chenyme 7454722068 chore: update version to 1.5.0 and add public chat endpoint v1.5.0 2026-02-20 00:29:11 +08:00
Chenyme 23aed15784 Merge pull request #196 from chenyme/browser
refactor: enhance session management by incorporating browser impersonation
2026-02-19 21:03:59 +08:00
Chenyme 439c7cea61 refactor: enhance session management by incorporating browser impersonation 2026-02-19 21:00:34 +08:00
Chenyme aa92d41913 Merge pull request #195 from chenyme/token
feat: add usage flush interval configuration and enhance token management
2026-02-19 20:40:18 +08:00
Chenyme f7976e12a5 feat: add usage flush interval configuration and enhance token management 2026-02-19 17:37:20 +08:00
Chenyme 53f96cf8db Merge pull request #192 from chenyme/docker
refactor: update Dockerfile for multi-stage build
2026-02-19 16:12:21 +08:00
Chenyme 62474e7a0b refactor: optimize Dockerfile for improved build efficiency 2026-02-19 16:09:35 +08:00
Chenyme 1062006abb refactor: update Dockerfile for multi-stage build 2026-02-19 10:20:59 +08:00
Chenyme d3fcefce2b Merge pull request #183 from adamhj/proxy_fix
fix(websocket): 修复代理配置加载竞态条件导致的连接超时问题
2026-02-19 09:48:31 +08:00
Adam.H 0fe5fd8dd7 fix(websocket): resolve proxy configuration race condition
- Fix an issue where WebSocket connections (e.g., for image generation) failed with "semaphore timeout" because proxy settings were not applied.
- Root cause: WebSocketClient was fetching proxy config during module-level instantiation, which occurred before config.load() finished.
- Modified WebSocketClient to dynamically resolve proxy settings at connection time.
- Added debug logging for proxy resolution and connector types.
2026-02-18 00:43:24 +08:00
Chenyme 7b02255f04 Merge pull request #182 from chenyme/fix_retry
feat: add ResettableSession for managing async HTTP sessions with automatic reset on specified status codes
2026-02-18 00:00:19 +08:00
Chenyme 716eb08bce Update .gitignore 2026-02-17 23:58:53 +08:00
Chenyme 0d73504f1a feat: add ResettableSession for managing async HTTP sessions with automatic reset on specified status codes 2026-02-17 23:58:42 +08:00
Chenyme 7de30abc53 Merge pull request #180 from chenyme/fix_stream
feat: enable streaming for file uploads in UploadService
2026-02-17 23:16:43 +08:00
Chenyme 6001a2ca5d feat: enable streaming for file uploads in UploadService 2026-02-17 23:14:49 +08:00
Chenyme cb0209d024 Update download.py 2026-02-17 22:28:19 +08:00
Chenyme 5936099ce7 Merge branch 'main' of https://github.com/chenyme/grok2api 2026-02-17 21:21:33 +08:00
Chenyme 9875b4756a docs: add grok-4.20-beta to the feature list in README files 2026-02-17 21:21:25 +08:00
Chenyme 0978215056 Merge pull request #178 from chenyme/grok-4-20-beta
feat: support new model Grok 4.20 Beta
2026-02-17 21:10:11 +08:00
Chenyme e3c2f76e96 feat: enhance extract_tool_text to include rollout_id for improved context in tool usage 2026-02-17 21:09:33 +08:00
Chenyme fcc957c956 feat: support new model Grok 4.20 Beta 2026-02-17 20:57:14 +08:00
Chenyme ee6ac473d8 chore: remove unused files 2026-02-16 01:18:50 +08:00
Chenyme ad92974ccc rrefactor: change admin and public API routers to compatible vercel 2026-02-16 01:06:03 +08:00
Chenyme f4e0ae4a1f refactor: reorganize router imports and streamline static file service in main.py 2026-02-16 00:34:34 +08:00
Chenyme bc70fa6ab1 Merge branch 'main' of https://github.com/chenyme/grok2api 2026-02-16 00:21:27 +08:00
Chenyme ea86c91bbc fix: vercel deploy error 2026-02-16 00:21:09 +08:00