Repository: All-Hands-AI/OpenHands
File: openhands/server/routes/manage_conversations.py (Python)

Code before:
    await conversation_store.delete_metadata(conversation_id)
    return True


@app.get('/conversations/{conversation_id}/remember-prompt')
async def get_prompt(
    event_id: int,
    conversation_id: str = Depends(validate_conversation_id),
    user_settings: SettingsStore = Depends(get_user_settings_store),
    metadata: ConversationMetadata = Depends(get_conversation_metadata),
):
    # get event store for the conversation
    event_store = EventStore(
        sid=conversation_id, file_store=file_store, user_id=metadata.user_id
    )

    # retrieve the relevant events
    stringified_events = _get_contextual_events(event_store, event_id)

    # generate a prompt
    settings = await user_settings.load()
    if settings is None:
        # placeholder for error handling
        raise ValueError('Settings not found')

    env_base_url = os.environ.get('LLM_BASE_URL')
    settings_base_url = settings.llm_base_url
    if env_base_url not in (None, ''):
        effective_base_url = env_base_url
    elif settings_base_url not in (None, ''):
        effective_base_url = settings_base_url
    else:
        effective_base_url = get_effective_llm_base_url(
            settings.llm_model,
            settings_base_url,
        )
    llm_config = LLMConfig(
        model=settings.llm_model or '',
        api_key=settings.llm_api_key,
        base_url=effective_base_url,
    )

    prompt_template = generate_prompt_template(stringified_events)
    prompt = await generate_prompt(llm_config, prompt_template, conversation_id)

    return JSONResponse(
        {
            'status': 'success',
            'prompt': prompt,
        }
    )

Review comment (suggestion):
```suggestion
```

We don't use global envs for settings (except for the resolver); `settings.llm_base_url` should be enough!

Code after:
    await conversation_store.delete_metadata(conversation_id)
    return True


@app.get('/conversations/{conversation_id}/remember-prompt')
async def get_prompt(
    event_id: int,
    conversation_id: str = Depends(validate_conversation_id),
    user_settings: SettingsStore = Depends(get_user_settings_store),
    metadata: ConversationMetadata = Depends(get_conversation_metadata),
):
    # get event store for the conversation
    event_store = EventStore(
        sid=conversation_id, file_store=file_store, user_id=metadata.user_id
    )

    # retrieve the relevant events
    stringified_events = _get_contextual_events(event_store, event_id)

    # generate a prompt
    settings = await user_settings.load()
    if settings is None:
        # placeholder for error handling
        raise ValueError('Settings not found')

    settings_base_url = settings.llm_base_url
    effective_base_url = get_effective_llm_base_url(
        settings.llm_model,
        settings_base_url,
    )
    llm_config = LLMConfig(
        model=settings.llm_model or '',
        api_key=settings.llm_api_key,
        base_url=effective_base_url,
    )

    prompt_template = generate_prompt_template(stringified_events)
    prompt = await generate_prompt(llm_config, prompt_template, conversation_id)

    return JSONResponse(
        {
            'status': 'success',
            'prompt': prompt,
        }
    )


def generate_prompt_template(events: str) -> str:
    env = Environment(loader=FileSystemLoader('openhands/microagent/prompts'))
    template = env.get_template('generate_remember_prompt.j2')
    return template.render(events=events)