Skip to content

fix(memos-local): include json hint in user messages#1756

Open
de1tydev wants to merge 1 commit into
MemTensor:mainfrom
de1tydev:fix/memos-json-user-hint
Open

fix(memos-local): include json hint in user messages#1756
de1tydev wants to merge 1 commit into
MemTensor:mainfrom
de1tydev:fix/memos-json-user-hint

Conversation

@de1tydev
Copy link
Copy Markdown

Summary

Fix OpenAI-compatible JSON mode requests by ensuring at least one user message contains the word json when jsonMode / completeJson is used.

Some OpenAI-compatible gateways and newer OpenAI-style APIs reject response_format: { type: "json_object" } unless the request input messages contain the word json. Previously, the memos LLM client injected the JSON instruction only into the system message. That can still fail on gateways that validate user/input content and return errors like:

status_code=400, Response input messages must contain the word 'json' in some form to use '***.format' of type 'json_object'.

This change appends a short user-level hint (Return valid json only.) when JSON mode is active and the existing user message does not already contain json.

Changes

  • Add ensureJsonWordInUserMessage() in core/llm/client.ts.
  • Apply it to both:
    • complete(..., { jsonMode: true })
    • completeJson(...)
  • Update unit tests to assert the user message receives the JSON hint.

Testing

From apps/memos-local-plugin:

npm run lint
npx vitest run tests/unit/llm/client.test.ts

Both pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant