Skip to content

Support AI Recommender#13

Merged
q231950 merged 24 commits into
mainfrom
recommender
Jul 22, 2025
Merged

Support AI Recommender#13
q231950 merged 24 commits into
mainfrom
recommender

Conversation

@q231950

@q231950 q231950 commented Jun 30, 2025

Copy link
Copy Markdown
Owner

No description provided.

q231950 and others added 20 commits June 30, 2025 10:29
…nd bullet-formatted titles

Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
…, author, and ISBN

Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
Comment thread paper/src/api/recommender.rs Outdated
Comment thread paper/src/api/recommender.rs Outdated
Comment thread paper/src/api/recommender.rs Outdated
println!("Request content: {}", content);

let request = CreateChatCompletionRequestArgs::default()
.model("openai/gpt-4.1")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think hard-coding the model makes sense here? IMHO we should have this as an argument / config.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved all model variables into a model configuration 👍

Comment thread paper/src/api/recommender.rs Outdated
Comment on lines +67 to +69
Always respond with valid JSON in the format: `{}`.
The response itself should be valid json.
Please do not include any additional text like markdown or explanations."#, titles_bullets, json_format);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this it not the most up to date version to force an AI to return data in a specific format. Most APIs allow specifying "structured output" or so.
I found this example in the async_openai crate showcasing how to do it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good point, thank you! I checked the docs while adapting the response format and it says:

/// Setting to `json_object` enables JSON mode. This guarantees that the message the model generates is valid JSON.
    ///
    /// Note that your system prompt must still instruct the model to produce JSON, and to help ensure you don't forget,
    /// the API will throw an error if the string `JSON` does not appear in your system message. Also note that the message
    /// content may be partial (i.e. cut off) if `finish_reason="length"`, which indicates the generation
    /// exceeded `max_tokens` or the conversation exceeded the max context length.
    ///
    /// Must be one of `text` or `json_object`.
    pub r#type: ChatCompletionResponseFormatType,

So I'll keep the prompt as is and additionally set the format.

@q231950
q231950 marked this pull request as ready for review July 18, 2025 14:09
.model(config.model.identifier())
.max_tokens(500_u16)
.response_format(ChatCompletionResponseFormat {
r#type: ChatCompletionResponseFormatType::JsonObject,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could be even more detailed here and use this ResponseFormat::JsonSchema specifying the exact format that we want, no?

@molikuner molikuner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start with this for now and once there is feedback from users we can iterate on it. 👍

@q231950

q231950 commented Jul 22, 2025

Copy link
Copy Markdown
Owner Author

@molikuner Thanks for your remarks. I'll leave the json schema/response unresolved and created an issue to check later.

@q231950
q231950 merged commit 9e9dfd6 into main Jul 22, 2025
1 check passed
@q231950
q231950 deleted the recommender branch July 22, 2025 16:30
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.

2 participants